How to input the XYZ coordinate and Quaternion data from externl file or matrix?
I am using MoveL to program the robot:
MoveL Target_20,v1000,fine,tRM62_22\WObj:=Workobject_1;
and the target_20 is :
CONST robtarget Target_20:=[[-12.830311995,192.144032798,119.012999948],[0.618084702345011,0.492475524331876,0.299763882874037,0.534397579696431],[-1,1,-3,0],[9E9,9E9,9E9,9E9,9E9,9E9]];
The first array is the XYZ coordinate and the second array is the quaternion. I am calculating both array in Matlab.
The problem is I will have huge number of points. It is time consuming to copy and paste them one by one to the Rapid program.
Is there a better way to input these points to the MoveL? For example, I can store the data in an excel file or txt file. How can Rapid read the excel or txt file? Otherwise, can I use a matrix to store all the points and read them one by one in the Rapid?
Thanks!
Best Answer
-
You can use a iodev to read from a for example a text file. Here is just an ex. where I read a values seperated with ; The text file is stored in the home folder on the robot controller PROC ReadTest() VAR iodev testsFile; VAR string strRead; VAR num nArrayPosition; VAR bool bEmptyFile; ! nArrayPosition:=1; bEmptyFile:=FALSE; ! Open file Open "tests.txt",testsFile\Read; WHILE bEmptyFile=FALSE DO ! Write into array strRead:=ReadStr(testsFile\Delim:=";"\RemoveCR); IF strRead<>EOF THEN arrDefinedTests{nArrayPosition}.TestNo:=strRead; strRead:=ReadStr(testsFile\Delim:=";"\RemoveCR); arrDefinedTests{nArrayPosition}.Chapter:=strRead; strRead:=ReadStr(testsFile\Delim:=";"\RemoveCR); arrDefinedTests{nArrayPosition}.Description:=strRead; Incr nArrayPosition; ELSE bEmptyFile:=TRUE; ENDIF ENDWHILE ! Close file Close testsFile; ERROR Close testsFile; RAISE ; ENDPROCPer Svensson
Robotics and Vision Specialist
Consat Engineering5
Answers
-
PerSvensson said:You can use a iodev to read from a for example a text file. Here is just an ex. where I read a values seperated with ; The text file is stored in the home folder on the robot controller PROC ReadTest() VAR iodev testsFile; VAR string strRead; VAR num nArrayPosition; VAR bool bEmptyFile; ! nArrayPosition:=1; bEmptyFile:=FALSE; ! Open file Open "tests.txt",testsFile\Read; WHILE bEmptyFile=FALSE DO ! Write into array strRead:=ReadStr(testsFile\Delim:=";"\RemoveCR); IF strRead<>EOF THEN arrDefinedTests{nArrayPosition}.TestNo:=strRead; strRead:=ReadStr(testsFile\Delim:=";"\RemoveCR); arrDefinedTests{nArrayPosition}.Chapter:=strRead; strRead:=ReadStr(testsFile\Delim:=";"\RemoveCR); arrDefinedTests{nArrayPosition}.Description:=strRead; Incr nArrayPosition; ELSE bEmptyFile:=TRUE; ENDIF ENDWHILE ! Close file Close testsFile; ERROR Close testsFile; RAISE ; ENDPROC
Hi, PerSvensson,
Thanks for your reply!
I wrote the following program:
PROC ReadTest()
VAR iodev file;
VAR num input;
Open "HOME:/Q4_coordinate.txt", file\Read;
input :=ReadNum(file);
ENDPROC
and the Q4_coordinate.txt is an array like follow:
-17 191 165; -12.8303 192.144 180.987; -4.87965 192.5664 195.3; 5.608169 192.6152 208.2366; 18.10037 191.9184 219.4036; 32.02475 190.1629 228.4619; 46.8055 187.1379 235.1362; 61.88993 182.7559 239.2236; 76.76652 177.0579 240.6; 90.97897 170.2096 239.2236; Those values should be put into 'input'. However, my input is always 0.
Could you please suggest the data type, which I should declare for 'input'? Or how should I arrange the values in the .txt file?
Thanks!
0 -
I have figured out the problem. I need to write a loop to read the data in the file, like PerSvensson's answer. Thanks!0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings