52   ! -------------------------------    53   ! Define your variables here    58 CUSTOM_FUNCTIONS = 
'''    59   ! -------------------------------    60   ! Define your functions here    66     """Prints a pose target"""    68     return (
'[%.3f,%.3f,%.3f],[%.6f,%.6f,%.6f,%.6f]' % (x,y,z,q1,q2,q3,q4))
    71     """Prints a joint target"""    75         angles.extend([0]*(6-njoints))
    79     return '[%s]' % (
','.join(format(ji, 
".6f") 
for ji 
in angles[0:6]))
    82     """Prints the external axes, if any"""    88         return '[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]'    89     extaxes_str = (
','.join(format(ji, 
".6f") 
for ji 
in angles[6:njoints]))
    91         extaxes_str = extaxes_str + 
',' + 
','.join([
'9E9']*(12-njoints))
    95     return '[%s]' % extaxes_str
   100     """Robot post object"""   105     ROBOT_NAME = 
'generic'   113     TOOL_REF_FIRST = 
None   116     SPEEDDATA = 
'[500,500,5000,1000]'   117     FRAME_NAME = 
'rdkWObj'   118     TOOL_NAME = 
'rdkTool'   120     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
   132             self.
addline(
'PROC %s()' % progname)
   135             self.
addline(
'PROC %s()' % progname)
   136         self.
TAB = ONETAB + ONETAB 
   142     def ProgSave(self, folder, progname, ask_user = False, show_result = False):
   146         progname = progname + 
'.' + self.
PROG_EXT   148             filesave = 
getSaveFile(folder, progname, 
'Save program as...')
   149             if filesave 
is not None:
   150                 filesave = filesave.name
   154             filesave = folder + 
'/' + progname
   155         fid = open(filesave, 
"w")
   157         fid.write(
'  VERSION:1\n')
   158         fid.write(
'  LANGUAGE:ENGLISH\n')
   161         fid.write(
'MODULE MOD_%s\n' % self.
MOD_NAME)
   165         fid.write(
'  PERS tooldata rdkTool := [TRUE,[%s],[2,[0,0,15],[1,0,0,0],0,0,0.005]];\n' % 
pose_2_str(self.
TOOL_REF_FIRST))
   166         fid.write(
'  PERS wobjdata rdkWObj := [FALSE, TRUE, "", [[0,0,0],[1,0,0,0]],[[0,0,0],[1,0,0,0]]];\n')
   172         print(
'SAVED: %s\n' % filesave) 
   177             if type(show_result) 
is str:
   180                 p = subprocess.Popen([show_result, filesave])
   181             elif type(show_result) 
is list:
   183                 p = subprocess.Popen(show_result + [filesave])   
   187                 os.startfile(filesave)
   188             if len(self.
LOG) > 0:
   189                 mbox(
'Program generation LOG:\n\n' + self.
LOG)
   192         """Send a program to the robot using the provided parameters. This method is executed right after ProgSave if we selected the option "Send Program to Robot".   193         The connection parameters must be provided in the robot connection menu of RoboDK"""   196     def MoveJ(self, pose, joints, conf_RLF=None):
   197         """Add a joint movement"""   201     def MoveL(self, pose, joints, conf_RLF=None):
   202         """Add a linear movement"""   207         [REAR, LOWERARM, FLIP] = conf_RLF
   208         cf1 = math.floor(joints[0]/90.0)
   209         cf4 = math.floor(joints[3]/90.0)
   210         cf6 = math.floor(joints[5]/90.0)
   211         cfx = 4*REAR + 2*LOWERARM + FLIP
   214         self.
addline(
'MoveL [%s,[%i,%i,%i,%i],%s],%s,%s,%s,\WObj:=rdkWObj;' % (
pose_2_str(self.
FRAME_REF*pose), cf1, cf4, cf6,cfx, 
extaxes_2_str(joints), self.
SPEEDDATA, self.
ZONEDATA, self.
TOOL_NAME))
   217     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   218         """Add a circular movement"""   219         if conf_RLF_1 
is None:
   221         if conf_RLF_2 
is None:
   227         if joints1 
is not None:
   228             cf1_1 = math.floor(joints1[0]/90.0)
   229             cf4_1 = math.floor(joints1[3]/90.0)
   230             cf6_1 = math.floor(joints1[5]/90.0)
   231         [REAR, LOWERARM, FLIP] = conf_RLF_1
   232         cfx_1 = 4*REAR + 2*LOWERARM + FLIP
   237         if joints2 
is not None:
   238             cf1_2 = math.floor(joints2[0]/90.0)
   239             cf4_2 = math.floor(joints2[3]/90.0)
   240             cf6_2 = math.floor(joints2[5]/90.0)
   241         [REAR, LOWERARM, FLIP] = conf_RLF_2
   242         cfx_2 = 4*REAR + 2*LOWERARM + FLIP
   243         self.
addline(
'MoveC [%s,[%i,%i,%i,%i],%s],[%s,[%i,%i,%i,%i],%s],%s,%s,rdkTool,\WObj:=rdkWObj;' % (
pose_2_str(pose1), cf1_1, cf4_1, cf6_1,cfx_1, 
extaxes_2_str(joints1), 
pose_2_str(pose2), cf1_2, cf4_2, cf6_2,cfx_2, 
extaxes_2_str(joints2), self.
SPEEDDATA, self.
ZONEDATA))
   246     def setFrame(self, pose, frame_id=None, frame_name=None):
   247         """Change the robot reference frame"""   256     def setTool(self, pose, tool_id=None, tool_name=None):
   257         """Change the robot TCP"""   265             self.
addline(
'%s := [TRUE,[%s],[2,[0,0,50],[1,0,0,0],0,0,0.005]];' % (self.
TOOL_NAME, 
pose_2_str(pose)))
   268         """Pause the robot program"""   272             self.
addline(
'WaitTime %.3f' % (time_ms*0.001))
   275         """Changes the robot speed (in mm/s)"""   279         """Changes the robot acceleration (in mm/s2)"""   280         self.
addlog(
'setAcceleration is not defined')
   283         """Changes the robot joint speed (in deg/s)"""   284         self.
addlog(
'setSpeedJoints not defined')
   287         """Changes the robot joint acceleration (in deg/s2)"""   288         self.
addlog(
'setAccelerationJoints not defined')
   291         """Changes the zone data approach (makes the movement more smooth)"""   298         """Sets a variable (output) to a given value"""   299         if type(io_var) != str:  
   300             io_var = 
'D_OUT_%s' % str(io_var)        
   301         if type(io_value) != str: 
   308         self.
addline(
'SetDO %s, %s;' % (io_var, io_value))
   310     def waitDI(self, io_var, io_value, timeout_ms=-1):
   311         """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided."""   312         if type(io_var) != str:  
   313             io_var = 
'D_IN_%s' % str(io_var)        
   314         if type(io_value) != str: 
   322             self.
addline(
'WaitDI %s, %s;' % (io_var, io_value))
   324             self.
addline(
'WaitDI %s, %s, \MaxTime:=%.1f;' % (io_var, io_value, timeout_ms*0.001))   
   326     def RunCode(self, code, is_function_call = False):
   327         """Adds code or a function call"""   329             code = code.replace(
' ',
'_')
   332             if code.startswith(
'END') 
or code.startswith(
'ELSEIF'):
   334                 self.
TAB = self.
TAB[:-len(ONETAB)]
   336             self.
addline(code.replace(
'\t',
'  '))
   338             if code.startswith(
'IF ') 
or code.startswith(
'ELSEIF ') 
or code.startswith(
'WHILE '):
   340                 self.
TAB = self.
TAB + ONETAB
   344         """Add a joint movement"""   348             self.
addline(
'TPWrite "%s";' % message)
   352         """Add a program line"""   356         """Add a log message"""   357         self.
LOG = self.
LOG + newline + 
'\n'   360         """Adds custom code, such as a custom header"""   366     [x,y,z,r,p,w] = xyzrpw
   376     return Mat([[cb*ca, ca*sc*sb - cc*sa, sc*sa + cc*ca*sb, x],[cb*sa, cc*ca + sc*sb*sa, cc*sb*sa - ca*sc, y],[-sb, cb*sc, cc*cb, z],[0,0,0,1]])
   379     """Test the post with a basic program"""   381     robot = 
RobotPost(
'ABB RAPID custom', 
'Generic ABB robot')
   383     robot.ProgStart(
"Program")
   384     robot.RunMessage(
"Program generated by RoboDK", 
True)
   385     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
   386     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
   387     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   388     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   389     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   390     robot.RunMessage(
"Setting air valve 1 on")
   391     robot.RunCode(
"TCP_On", 
True)
   393     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   394     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   395     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   396     robot.RunMessage(
"Setting air valve off")
   397     robot.RunCode(
"TCP_Off", 
True)
   399     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   400     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   401     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   402     robot.ProgFinish(
"Program")
   405     if len(robot.LOG) > 0:
   406         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   408     input(
"Press Enter to close...")
   410 if __name__ == 
"__main__":
   411     """Function to call when the module is executed by itself: test""" def setSpeed(self, speed_mms)
def setTool(self, pose, tool_id=None, tool_name=None)
def addline(self, newline)
def extaxes_2_str(angles)
def setSpeedJoints(self, speed_degs)
def setAcceleration(self, accel_mmss)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def setZoneData(self, zone_mm)
def addlog(self, newline)
def setFrame(self, pose, frame_id=None, frame_name=None)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def setDO(self, io_var, io_value)
def RunMessage(self, message, iscomment=False)
def MoveJ(self, pose, joints, conf_RLF=None)
def ProgStart(self, progname)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def setAccelerationJoints(self, accel_degss)
def RunCode(self, code, is_function_call=False)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def ProgFinish(self, progname)
def MoveL(self, pose, joints, conf_RLF=None)