51     """Calculate the p[x,y,z,rx,ry,rz] position for a pose target"""    52     def saturate_1(value):
    53         return min(max(value,-1.0),1.0)
    55     angle = 
acos(  saturate_1((pose[0,0]+pose[1,1]+pose[2,2]-1)/2)   )    
    56     rxyz = [pose[2,1]-pose[1,2], pose[0,2]-pose[2,0], pose[1,0]-pose[0,1]]
    62         rxyz = 
mult3(rxyz, angle)
    63     return [pose[0,3], pose[1,3], pose[2,3], rxyz[0], rxyz[1], rxyz[2]]
    66     """Prints a pose target"""    69     return (
'p[%.6f, %.6f, %.6f, %.6f, %.6f, %.6f]' % (x*M_2_MM,y*M_2_MM,z*M_2_MM,w,p,r))
    72     """Prints a joint target"""    76         return (
'[%.6f, %.6f, %.6f, %.6f, %.6f, %.6f]' % (angles[0]*d2r, angles[1]*d2r, angles[2]*d2r, angles[3]*d2r, angles[4]*d2r, angles[5]*d2r))
    78         return 'this post only supports 6 joints'    83     """Robot post object"""    89     BLEND_RADIUS_M = 0.001  
    95     ROBOT_NAME = 
'generic'    97     MAIN_PROGNAME = 
'unknown'   103     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
   112         self.
addline(
'def %s():' % progname)        
   116             self.
addline(
'# default parameters:')
   128     def ProgSave(self, folder, progname, ask_user = False, show_result = False):
   130         progname = progname + 
'.' + self.
PROG_EXT   132             filesave = 
getSaveFile(folder, progname, 
'Save program as...')
   133             if filesave 
is not None:
   134                 filesave = filesave.name
   138             filesave = folder + 
'/' + progname
   139         fid = open(filesave, 
"w")
   142         print(
'SAVED: %s\n' % filesave) 
   147             if type(show_result) 
is str:
   150                 p = subprocess.Popen([show_result, filesave])
   154                 os.startfile(filesave)
   155             if len(self.
LOG) > 0:
   156                 mbox(
'Program generation LOG:\n\n' + self.
LOG)
   159         """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".   160         The connection parameters must be provided in the robot connection menu of RoboDK"""   165         blend_radius = 
'blend_radius_m';
   166         current_pos = pose.Pos()
   172                 blend_radius = 
'%.3f' % (max(0.4*distance*0.001, 0.001))
   176     def MoveJ(self, pose, joints, conf_RLF=None):
   177         """Add a joint movement"""   183         self.
addline(
'movej(%s,accel_radss,speed_rads,0,%s)' % (
angles_2_str(joints), blend_radius))
   185     def MoveL(self, pose, joints, conf_RLF=None):
   186         """Add a linear movement"""   201     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   202         """Add a circular movement"""   207             radius = a*b*c/
sqrt(pow(a*a+b*b+c*c,2)-2*(pow(a,4)+pow(b,4)+pow(c,4)))            
   210         def distance_p1_p02(p0,p1,p2):
   213             return dot(v02,v01)/
dot(v02,v02)
   219             self.
MoveL(pose2, joints2, conf_RLF_2)
   223         if radius < 1 
or radius > 100000:
   224             self.
MoveL(pose2, joints2, conf_RLF_2)
   227         d_p1_p02 = distance_p1_p02(p0, p1, p2)
   229             self.
MoveL(pose2, joints2, conf_RLF_2)
   237     def setFrame(self, pose, frame_id=None, frame_name=None):
   238         """Change the robot reference frame"""   245     def setTool(self, pose, tool_id=None, tool_name=None):
   246         """Change the robot TCP"""   250         """Pause the robot program"""   252             self.
addline(
'halt() # reimplement this function to force stop')
   254             self.
addline(
'sleep(%.3f)' % (time_ms*0.001))
   257         """Changes the robot speed (in mm/s)"""   262         """Changes the robot acceleration (in mm/s2)"""       267         """Changes the robot joint speed (in deg/s)"""   272         """Changes the robot joint acceleration (in deg/s2)"""   277         """Changes the zone data approach (makes the movement more smooth)"""   284         """Sets a variable (output) to a given value"""   285         if type(io_value) != str: 
   291         if type(io_var) != str:  
   292             newline = 
'set_standard_digital_out(%s, %s)' % (str(io_var), io_value)
   294             newline = 
'%s = %s' % (io_var, io_value)
   298     def waitDI(self, io_var, io_value, timeout_ms=-1):
   299         """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided."""   300         if type(io_var) != str:  
   301             io_var = 
'get_standard_digital_in(%s)' % str(io_var)        
   302         if type(io_value) != str: 
   310         self.
addline(
'while (%s != %s):' % (io_var, io_value))
   314     def RunCode(self, code, is_function_call = False):
   315         """Adds code or a function call"""   317             code.replace(
' ',
'_')
   318             if not code.endswith(
')'):
   326         """Show a message on the controller screen"""   330             self.
addline(
'popup("%s","Message",False,False,blocking=True)' % message)
   334         """Add a program line"""   338         """Add a log message"""   339         self.
LOG = self.
LOG + newline + 
'\n'   344     [x,y,z,r,p,w] = xyzrpw
   354     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]])
   357     """Test the post with a basic program"""   359     robot = 
RobotPost(
'Universal Robotics', 
'Generic UR robot')
   361     robot.ProgStart(
"Program")
   362     robot.RunMessage(
"Program generated by RoboDK", 
True)
   363     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
   364     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
   366     robot.setAcceleration(3000) 
   367     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   368     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   369     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   370     robot.RunMessage(
"Setting air valve 1 on")
   371     robot.RunCode(
"TCP_On", 
True)
   373     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   374     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   375     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   376     robot.RunMessage(
"Setting air valve off")
   377     robot.RunCode(
"TCP_Off", 
True)
   379     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   380     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   381     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   382     robot.ProgFinish(
"Program")
   385     if len(robot.LOG) > 0:
   386         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   388     input(
"Press Enter to close...")
   390 if __name__ == 
"__main__":
   391     """Function to call when the module is executed by itself: test""" 
def ProgStart(self, progname)
def setAcceleration(self, accel_mmss)
def setDO(self, io_var, io_value)
def ProgFinish(self, progname)
def setZoneData(self, zone_mm)
def setSpeedJoints(self, speed_degs)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def blend_radius_check(self, pose)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveJ(self, pose, joints, conf_RLF=None)
def addlog(self, newline)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def MoveL(self, pose, joints, conf_RLF=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def addline(self, newline)
def setAccelerationJoints(self, accel_degss)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def setSpeed(self, speed_mms)
def RunCode(self, code, is_function_call=False)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def RunMessage(self, message, iscomment=False)
def setFrame(self, pose, frame_id=None, frame_name=None)
def setTool(self, pose, tool_id=None, tool_name=None)
def circle_radius(p0, p1, p2)