43 HEADER_PROG =
'''#--------------- ROBOTIQ GRIPPER UTILITY 45 global Position_close=255 46 global Speed_close=255 47 global Force_close=255 48 #Allocation of modbus output registers with the desired settings 49 out_reg2_close = Speed_close * 256 + Force_close 50 modbus_set_output_register("Speed_Force_Req", out_reg2_close, False) 51 modbus_set_output_register("Position_Req", Position_close, False) 54 modbus_set_output_signal("Go_to_Requested", True, False) 55 while(modbus_get_signal_status("Action_Status", False) == False): 59 #Wait until the end of the movement 61 while (not((modbus_get_signal_status("Obj_Det_Status1", False) == True) or (modbus_get_signal_status("Obj_Det_Status2", False) == True ))): 67 #Status check object detection 68 global obj_detect1 = modbus_get_signal_status("Obj_Det_Status1",False) 69 global obj_detect2 = modbus_get_signal_status("Obj_Det_Status2",False) 70 if ((obj_detect1 == False) and (obj_detect2 == True)): 71 global Contact_opening = False 72 global Contact_closing = True 74 if ((obj_detect1 == True) and (obj_detect2 == False)): 75 global Contact_opening = True 76 global Contact_closing = False 78 global Contact_opening = False 79 global Contact_closing = False 83 #Prohibit the movement 84 modbus_set_output_signal("Go_to_Requested", False, False) 85 while(modbus_get_signal_status("Action_Status", False) == True): 90 global Position_open=0 93 #Allocation of modbus output registers with the desired settings 94 out_reg2_open = Speed_open * 256 + Force_open 95 modbus_set_output_register("Speed_Force_Req", out_reg2_open, False) 96 modbus_set_output_register("Position_Req", Position_open, False) 99 modbus_set_output_signal("Go_to_Requested", True, False) 100 while(modbus_get_signal_status("Action_Status", False) == False): 104 #Wait until the end of the movement 106 while (not((modbus_get_signal_status("Obj_Det_Status1", False) == True) or (modbus_get_signal_status("Obj_Det_Status2", False) == True ))): 112 #Status check object detection 113 global obj_detect1 = modbus_get_signal_status("Obj_Det_Status1",False) 114 global obj_detect2 = modbus_get_signal_status("Obj_Det_Status2",False) 115 if ((obj_detect1 == False) and (obj_detect2 == True)): 116 global Contact_opening = False 117 global Contact_closing = True 119 if ((obj_detect1 == True) and (obj_detect2 == False)): 120 global Contact_opening = True 121 global Contact_closing = False 123 global Contact_opening = False 124 global Contact_closing = False 128 #Prohibit the movement 129 modbus_set_output_signal("Go_to_Requested", False, False) 130 while(modbus_get_signal_status("Action_Status", False) == True): 135 #Activation if not activated 136 if ((modbus_get_signal_status("Gripper_Status1", False) == False) and (modbus_get_signal_status("Gripper_Status2", False) == False)): 137 modbus_set_output_signal("Activate", True, False) 140 #Prohibit the movement 141 modbus_set_output_signal("Go_to_Requested", False, False) 142 while (modbus_get_signal_status("Action_Status", False) == True): 146 #Awaiting the activation of the gripper 147 while (not(modbus_get_signal_status("Gripper_Status1", False) == True )): 150 while (not(modbus_get_signal_status("Gripper_Status2", False) == True )): 164 """Calculate the p[x,y,z,rx,ry,rz] position for a pose target""" 165 def saturate_1(value):
166 return min(max(value,-1.0),1.0)
168 angle =
acos( saturate_1((pose[0,0]+pose[1,1]+pose[2,2]-1)/2) )
169 rxyz = [pose[2,1]-pose[1,2], pose[0,2]-pose[2,0], pose[1,0]-pose[0,1]]
175 rxyz =
mult3(rxyz, angle)
176 return [pose[0,3], pose[1,3], pose[2,3], rxyz[0], rxyz[1], rxyz[2]]
179 """Prints a pose target""" 182 return (
'p[%.6f, %.6f, %.6f, %.6f, %.6f, %.6f]' % (x*MM_2_M,y*MM_2_M,z*MM_2_M,w,p,r))
185 """Prints a joint target""" 186 njoints = len(angles)
189 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))
191 return 'this post only supports 6 joints' 196 """Robot post object""" 202 BLEND_RADIUS_M = 0.001
208 ROBOT_NAME =
'generic' 210 MAIN_PROGNAME =
'unknown' 216 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
225 self.
addline(
'def %s():' % progname)
230 self.
addline(
'# default parameters:')
242 def ProgSave(self, folder, progname, ask_user = False, show_result = False):
244 progname = progname +
'.' + self.
PROG_EXT 246 filesave =
getSaveFile(folder, progname,
'Save program as...')
247 if filesave
is not None:
248 filesave = filesave.name
252 filesave = folder +
'/' + progname
253 fid = open(filesave,
"w")
256 print(
'SAVED: %s\n' % filesave)
261 if type(show_result)
is str:
264 p = subprocess.Popen([show_result, filesave])
265 elif type(show_result)
is list:
267 p = subprocess.Popen(show_result + [filesave])
271 os.startfile(filesave)
272 if len(self.
LOG) > 0:
273 mbox(
'Program generation LOG:\n\n' + self.
LOG)
276 """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". 277 The connection parameters must be provided in the robot connection menu of RoboDK""" 282 blend_radius =
'blend_radius_m';
283 current_pos = pose.Pos()
289 blend_radius =
'%.3f' % (0.4*distance*0.001)
293 def MoveJ(self, pose, joints, conf_RLF=None):
294 """Add a joint movement""" 300 self.
addline(
'movej(%s,accel_radss,speed_rads,0,%s)' % (
angles_2_str(joints), blend_radius))
302 def MoveL(self, pose, joints, conf_RLF=None):
303 """Add a linear movement""" 314 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
315 """Add a circular movement""" 319 def setFrame(self, pose, frame_id=None, frame_name=None):
320 """Change the robot reference frame""" 327 def setTool(self, pose, tool_id=None, tool_name=None):
328 """Change the robot TCP""" 332 """Pause the robot program""" 334 self.
addline(
'halt() # reimplement this function to force stop')
336 self.
addline(
'sleep(%.3f)' % (time_ms*0.001))
339 """Changes the robot speed (in mm/s)""" 344 """Changes the robot acceleration (in mm/s2)""" 349 """Changes the robot joint speed (in deg/s)""" 354 """Changes the robot joint acceleration (in deg/s2)""" 359 """Changes the zone data approach (makes the movement more smooth)""" 366 """Sets a variable (output) to a given value""" 367 if type(io_value) != str:
373 if type(io_var) != str:
374 newline =
'set_standard_digital_out(%s, %s)' % (str(io_var), io_value)
376 newline =
'%s = %s' % (io_var, io_value)
380 def waitDI(self, io_var, io_value, timeout_ms=-1):
381 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 382 if type(io_var) != str:
383 io_var =
'get_standard_digital_in(%s)' % str(io_var)
384 if type(io_value) != str:
392 self.
addline(
'while (%s != %s):' % (io_var, io_value))
396 def RunCode(self, code, is_function_call = False):
397 """Adds code or a function call""" 399 code.replace(
' ',
'_')
400 if not code.endswith(
')'):
408 """Show a message on the controller screen""" 412 self.
addline(
'popup("%s","Message",False,False,blocking=True)' % message)
416 """Add a program line""" 420 """Add a log message""" 421 self.
LOG = self.
LOG + newline +
'\n' 426 [x,y,z,r,p,w] = xyzrpw
436 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]])
439 """Test the post with a basic program""" 441 robot =
RobotPost(
'Universal Robotics',
'Generic UR robot')
443 robot.ProgStart(
"Program")
444 robot.RunMessage(
"Program generated by RoboDK",
True)
445 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
446 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
448 robot.setAcceleration(3000)
449 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
450 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
451 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
452 robot.RunMessage(
"Setting air valve 1 on")
453 robot.RunCode(
"TCP_On",
True)
455 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
456 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
457 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
458 robot.RunMessage(
"Setting air valve off")
459 robot.RunCode(
"TCP_Off",
True)
461 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
462 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
463 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
464 robot.ProgFinish(
"Program")
467 if len(robot.LOG) > 0:
468 mbox(
'Program generation LOG:\n\n' + robot.LOG)
470 input(
"Press Enter to close...")
472 if __name__ ==
"__main__":
473 """Function to call when the module is executed by itself: test""" def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def MoveJ(self, pose, joints, conf_RLF=None)
def ProgFinish(self, progname)
def addline(self, newline)
def RunCode(self, code, is_function_call=False)
def setAcceleration(self, accel_mmss)
def MoveL(self, pose, joints, conf_RLF=None)
def setFrame(self, pose, frame_id=None, frame_name=None)
def setAccelerationJoints(self, accel_degss)
def ProgStart(self, progname)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def RunMessage(self, message, iscomment=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def setSpeedJoints(self, speed_degs)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setDO(self, io_var, io_value)
def setSpeed(self, speed_mms)
def setZoneData(self, zone_mm)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def addlog(self, newline)
def blend_radius_check(self, pose)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def setTool(self, pose, tool_id=None, tool_name=None)