Read txt file coordinate
Hello everyone
I am just starting to work on a project using ABB Yumi robot to do soldering. Since this is an automated system, it is not possible to jog each point, I have created a .txt file on Home and used RAPID to read that file. However, I am having difficulty in reading that file and assigning values from the file to the variables x, y, z. Here is my code:
PROC WeldingMotion(num x, num y, num z)
MoveL offs(Temp, x, y, z+10), v100, fine, Servo\WObj:=wobj0;
WaitTime 0.5;
MoveL offs(Temp, x, y, z), v100, fine, Servo\WObj:=wobj0;
WaitTime 0.5;
PulseDO signal1;
WaitTime 1.5;
PulseDO signal1;
WaitTime 1.5;
MoveL offs(Temp, x, y, z+10), v100, fine, Servo\WObj:=wobj0;
ENDPROC
PROC ReadAndWeld()
Open "HOME:" \File:= "han.txt", infile\Read;
WHILE i<4 DO
text := ReadStr(infile\Delim:=","\RemoveCR);
IF text = "EOF" THEN
EXIT;
ENDIF
x := ReadNum(infile);
text := ReadStr(infile\Delim:=","\RemoveCR);
IF text = "EOF" THEN
EXIT;
ENDIF
y := ReadNum(infile);
text := ReadStr(infile\Delim:="\0d"\RemoveCR);
IF text = "EOF" THEN
EXIT;
ENDIF
z := ReadNum(infile);
WeldingMotion x, y, z;
text := ReadStr(infile);
i := i + 1;
ENDWHILE
ENDPROC
ENDPROC
Please let me know if you have a solution
Best Regards
0
Answers
-
On first glance I see that your handling of EOF is problematic. Using the EXIT instruction will cause the program pointer to be discarded. Please see my blog here:
https://www.robot-forum.com/blog/entry/4-another-program-that-writes-a-program/
for an example of file handing and examples of extracting data from them. I hope that you find it useful.Lee Justice0 -
Thanks for your help!But actually I read your Blog about this issue but really don't understand much. Maybe because RAPID code is too new to me. If possible, please help me assign the x, y, z values of the file. Thank you very much.Type your comment0
-
I have no idea what your file looks like. Also, have you considered using a .csv file?Lee Justice0
-
I tried with .txt file its content is simply:-47.45241327,-49.76916306,-106.452481-47.45216231,49.29770462,-106.452833250.27137845,49.29752072,-106.452946950.27139316,-48.08475086,-106.4531297Also, after consulting some commands, I changed my code as follows:MODULE WeldingModuleVAR iodev infile;VAR string strRead;CONST string EOF := "EOF";VAR num x;VAR num y;VAR num z;VAR bool bEmptyFile := FALSE;CONST robtarget Temp := [[398.325199305, 0.258359649, 229.351914078],[0.008778554, -0.708013571, 0.70614426, 0.000073994],[1, -2, 0, 4],[-125.311648719, 9E+09, 9E+09, 9E+09, 9E+09, 9E+09]];PROC main()MoveL Temp, v100, fine, Servo\WObj:=wobj0;ReadAndWeld;ENDPROCPROC WeldingMotion(num x, num y, num z)MoveL Offs(Temp, x, y, z+10), v100, fine, Servo\WObj:=wobj0;WaitTime 0.5;MoveL Offs(Temp, x, y, z), v100, fine, Servo\WObj:=wobj0;WaitTime 0.5;MoveL Offs(Temp, x, y, z+10), v100, fine, Servo\WObj:=wobj0;ENDPROCPROC ReadAndWeld()! Open the file to readOpen "HOME:" \File:= "han.txt", infile \Read;WHILE bEmptyFile = FALSE DOstrRead := ReadStr(infile \RemoveCR);IF strRead <> EOF THENx := StrToVal(StrPart(strRead, 1, StrFind(strRead, ",") - 1));strRead := StrPart(strRead, StrFind(strRead, ",") + 1);y := StrToVal(StrPart(strRead, 1, StrFind(strRead, ",") - 1));strRead := StrPart(strRead, StrFind(strRead, ",") + 1);z := StrToVal(strRead);WeldingMotion x, y, z;ELSEbEmptyFile := TRUE;ENDIFENDWHILEClose infile;ENDPROCENDMODULEBut it still doesn't work, there's only a little time left until my exam. I really hope you can help me solve it.Best regards0
-
It looked like in your first trial you were tying to use a delimiter "," for a comma. It should be ASCII Hex for the , character. Stick with the ReadNum. I suspect that you are running the program instead of stepping line by line. Step line by line, pausing to examine the values that are being evaluated and written. It is the best way to debug.Lee Justice0
Categories
- All Categories
- 5.6K RobotStudio
- 398 UpFeed
- 20 Tutorials
- 13 RobotApps
- 299 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 327 IRC5
- 65 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 821 RAPID Programming
- 8 AppStudio
- 3 RobotStudio AR Viewer
- 19 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings