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;
        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
Please let me know if you have a solution
Best Regards

Answers

  • lemster68
    lemster68 ✭✭✭
    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 Justice
  • 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 comment
  • lemster68
    lemster68 ✭✭✭
    I have no idea what your file looks like.  Also, have you considered using a .csv file?
    Lee Justice
  • I tried with .txt file its content is simply:
    -47.45241327,-49.76916306,-106.452481
    -47.45216231,49.29770462,-106.4528332
    50.27137845,49.29752072,-106.4529469
    50.27139316,-48.08475086,-106.4531297
    Also, after consulting some commands, I changed my code as follows:
    MODULE WeldingModule
    VAR 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;
     ENDPROC

     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;
     MoveL Offs(Temp, x, y, z+10), v100, fine, Servo\WObj:=wobj0;
     ENDPROC

     PROC ReadAndWeld()
     ! Open the file to read
     Open "HOME:" \File:= "han.txt", infile \Read;

     WHILE bEmptyFile = FALSE DO
     strRead := ReadStr(infile \RemoveCR);
     IF strRead <> EOF THEN
    x := 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;
    ELSE
    bEmptyFile := TRUE;
    ENDIF
    ENDWHILE
    Close infile;
    ENDPROC
    ENDMODULE

    But 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 regards
  • lemster68
    lemster68 ✭✭✭
    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 Justice