ABB 机器人G代码画图实例

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
MODULE gCodeHandle
    
    ! [filePath]      存放G代码的文件路径
    ! [signalDoName]  轨迹记录控制信号的名称,用于开启\关闭仿真中的轨迹记录(模拟画笔)
    ! [robTool]       机器人使用使用的工具
    ! [centerPoint]   画板平面中心点坐标
    PROC runGCode(String filePath, String signalDoName, inout tooldata robTool, robtarget centerPoint)
        VAR iodev sourceFile;
        !VAR signaldo ioOutput;
        VAR string text;
        VAR string commandLable;
        VAR string result;
        
        !GetDataVal signalDoName, ioOutput;
        
        ! Open the file in read-only mode.
        Open filePath, sourceFile\Read;
        
        ! Run to aims point
        !Reset ioOutput;
        MoveL centerPoint,v100,z0,robTool;
        
        WHILE TRUE DO
            text := ReadStr(sourceFile);
            
            ! Check file if end
            IF text = EOF OR text = "" THEN
                ! Exit proc
                GOTO EXITRUN;
            ENDIF
            
            commandLable := StrPart(text, 1, 1);
            IF commandLable = "#" OR commandLable = ";" THEN
                ExitCycle;
            ENDIF
            
            ! Call handler
            result := gCodeHandler(text, signalDoName, robTool, centerPoint);
            IF result = "error" THEN
                TPWrite("GCode write error!");
            ENDIF
        ENDWHILE
      
        EXITRUN:
            ! Close file.
            ! Data placement.
            Close sourceFile;
            ! Robot return safe point
            MoveL centerPoint,v100,z0,robTool;
    ENDPROC
    
    ! [text]          需要处理的G代码,如 G0 X12 Y77 Z9
    ! [isWrite]       是否写入,如果设置为真函数会将转换后的G代码作为字符串返回(不会移动机器人)
    ! [signalDoName]  轨迹记录控制信号的名称,用于开启\关闭仿真中的轨迹记录(模拟画笔)
    ! [robTool]       机器人使用使用的工具
    ! [centerPoint]   画板平面中心点坐标
    FUNC string gCodeHandler(string text\switch isWrite, String signalDoName, inout tooldata robTool, robtarget centerPoint)
        VAR num x:=0;
        VAR num y:=0;
        VAR num tmpX:=0;
        VAR num tmpY:=0;
        VAR num xLable := 0;
        VAR num yLable := 0;
        VAR num tmpLable := 0;
        VAR num tmpLableTwo := 0;
        VAR num tmpLen := 0;
        VAR string commandLable := "";
        VAR string tmpStr := "";
        VAR signaldo ioOutput;
        
        GetDataVal signalDoName, ioOutput;

        ! Check command lable is then "G0" or "G1"
        ! If not, then exit func
        commandLable := StrPart(text, 1, 2);
        IF commandLable <> "G0" AND commandLable <> "G1" THEN
            RETURN "error";
        ENDIF

        ! Get x value.
        xLable := strfind(text,1,"X");
        IF xLable <= strLen(text) THEN
            tmpLable := strfind(text,xLable," ");
            !IF tmpLable > strLen(text) THEN
            !    tmpStr := StrPart(text, xLable+1, StrLen(text)-(xLable+1));
            !ELSE
            !   tmpLable := strfind(text,xLable," ");
            !   tmpLable := strfind(text,xLable," ")-(xLable+1);
            !   tmpStr := StrPart(text, xLable+1, tmpLable)
            !ENDIF
            tmpLableTwo := tmpLable - (xLable + 1);
            tmpStr := StrPart(text, xLable + 1, tmpLableTwo);
            IF NOT StrToVal(tmpStr, tmpX) THEN
                RETURN "error";
            ENDIF
            !IF (tmpX - 50) > x THEN
            !    x := tmpX;
            !ENDIF
            x := tmpX;
        ENDIF

        ! Get y value.
        yLable := strfind(text,1,"Y");
        IF yLable <= strLen(text) THEN
            tmpLable := strfind(text,yLable," ");
            !IF tmpLable > strLen(text) THEN
            !    tmpLen := StrLen(text);
            !    tmpLableTwo := tmpLen  - yLable;
            !    tmpStr := StrPart(text, yLable+1, tmpLableTwo);
            !ELSE
            !    tmpStr := StrPart(text, yLable+1, tmpLable - 1);
            !ENDIF
            tmpLableTwo :=  tmpLable - (yLable + 1);
            tmpStr := StrPart(text, yLable + 1, tmpLableTwo);
            IF NOT StrToVal(tmpStr, tmpY) THEN
                RETURN "error";
            ENDIF
            !IF (tmpY - 50) > y THEN
            !    y := tmpY;
            !ENDIF
            y := tmpY;
        ENDIF

        ! Check is write data to file.
        ! If not written, it will be executed immediately
        IF Present(isWrite) THEN
            ! Return result
            RETURN strpart(text,1,2) + " X"+ValToStr(x)+" Y"+ValToStr(y);
        ELSEIF strpart(text,1,2)="G0" THEN
            MOveJ Offs(centerPoint,x,y,0),v500,fine,robTool;
        ELSEIF strpart(text,1,2)="G1" THEN
            ! Open welding torch
            !%"Set "+signalDoName%;
            !%"SetDO "+signalDoName+",1"%;
            Set ioOutput;
            MoveJ Offs(centerPoint,x,y,0),v500,fine,robTool;
        ENDIF

        ! Close welding torch
        !%"Reset "+signalDoName%;
        !%"SetDO "+signalDoName+",0"%;
        Reset ioOutput;
        ! Return default reslult
        RETURN "success";
        
    ENDFUNC
    
ENDMODULE