# 离线编程

## 用 RoboDK 实现离线编程

Python让您更快、更有效地整合您的系统。相较于其他编程语言来说，Python更简单有效，并且容易学习。版本Python 3.7.3 将随 RoboDK 自动安装.

RoboDK 用于Python 的应用程序编程接口（API）参考资料以及范例在 这里。RoboDK的应用程序编程接口（API）与 C#（包括范例）以及 Matlab 也兼容。

### 离线编程范例：

```from robolink import *    # RoboDK's API
from robodk import *      # Math toolbox for robots

# Any interaction with RoboDK must be done through

# get the robot item:
robot = RDK.Item('ABB IRB 1600ID-4/1.5')

# get the home target and the welding targets:
home = RDK.Item('Home')
target = RDK.Item('Target 1')
# get the pose of the target (4x4 matrix):
ref = target.Pose()

# move the robot to home, then to the center:
robot.MoveJ(home)
robot.MoveJ(target)

# call a robot program to start the weld gun
RDK.RunProgram('WeldStart')

# make an hexagon around the center:
for i in range(7):
ang = i*2*pi/6 #ang = 0, 60, 120, ..., 360
pi = ref*rotz(ang)*transl(200,0,0)*rotz(-ang)
robot.MoveL(pi)

# call a robot program to stop the weld gun
RDK.RunProgram('WeldStop')

# move back to the center, then home:
robot.MoveL(target)
robot.MoveJ(home)
```

### 机器人程序文件范例

```MODULE MOD_Weld_Hexagon

PERS wobjdata rdkWObj := [FALSE, TRUE, "", [[0,0,0],[1,0,0,0]],[[0,0,0],[1,0,0,0]];
PERS tooldata rdkTool := [TRUE,[[0,0,0],[1,0,0,0]],[3,[0,0,200],[1,0,0,0],0,0,0.005]];
VAR speeddata rdkSpeed := [500,500,500,500];
VAR extjoint rdkExtax := [9E9,9E9,9E9,9E9,9E9,9E9];

PROC Weld_Hexagon()
!Program generated by RoboDK for ABB IRB 1600ID-4/1.5 on 29/11/2014 17:42:31
ConfJ \On;
ConfL \On;
rdkWObj.oframe:=[0,0,0],[1,0,0,0];
rdkWObj.uframe:=[0,0,0],[1,0,0,0];
rdkTool.tframe:=[-4,0,371.3],[0.92387953,0,0.38268343,0];
MoveAbsJ [[-0,-19.143793,-7.978668,0,49.189506,-0]],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
MoveJ [[1010.634,-114.491,662.29],[0,0,1,0],[-1,0,-1,0],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
WeldStart;
MoveL [[810.634,-114.491,662.29],[0,0,1,0],[-1,0,-1,0],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
MoveL [[910.634,58.715,662.29],[0,0,1,0.00000001],[0,-1,0,0],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
MoveL [[1110.634,58.715,662.29],[0,0,1,0],[0,-1,0,0],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
MoveL [[1210.634,-114.491,662.29],[0,0,1,0],[-1,0,-1,0],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
MoveL [[1110.634,-287.696,662.29],[0,0,1,0],[-1,0,-1,0],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
MoveL [[910.634,-287.696,662.29],[0,0,1,0],[-1,0,-1,0],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
MoveL [[810.634,-114.491,662.29],[0,0,1,0],[-1,0,-1,0],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
WeldStop;
MoveL [[1010.634,-114.491,662.29],[0,0,1,0],[-1,0,-1,0],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
MoveAbsJ [[-0,-19.143793,-7.978668,0,49.189506,-0]],rdkExtax], rdkSpeed, rdkZone, rdkTool, \WObj:=rdkWObj;
ConfJ \On;
ConfL \On;
ENDPROC
ENDMODULE
```

# 机器人后处理器（Post Processor）

RoboDK 为多数机器人品牌建立了后处理器。我们也可以根据需要生成适合您的后处理器。