45     """Get a safe program name"""    47     for c 
in r'-[]/\;,><&*:%=+@!#^()|?^':
    48         progname = progname.replace(c,
'')
    50     if len(progname) <= 0:
    53     if progname[0].isdigit():
    54         progname = 
'P' + progname
    56     if len(progname) > max_chars:
    57         progname = progname[:max_chars]
    69     """Robot post object defined for Motoman robots"""    71     PATH_MAKE_SP = 
'C:/Program Files (x86)/CLOOS/'    75     MAX_LINES_X_PROG = 5000      
    78     INCLUDE_SUB_PROGRAMS = 
True     83     PULSES_X_DEG = [1,1,1,1,1,1] 
    98     PROG_TARGETS_LIST = [] 
   100     PROG_NAME = 
'unknown'     101     PROG_NAME_CURRENT = 
'unknown'    111     AXES_TYPE = [
'R','R','R','R','R','R']  # Important: This is usually set up by RoboDK automatically. Otherwise, override the __init__ procedure.   117     HAS_TURNTABLE = 
False   125     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
   132         for k,v 
in kwargs.items():
   133             if k == 
'lines_x_prog':
   137             if k == 
'pulses_x_deg':
   151         progname_i = progname
   156                     print(
"Can't split %s: Two or more programs are split into smaller programs" % progname)
   158                     raise Exception(
"Only one program at a time can be split into smaller programs")
   184         header += 
'RESTART' + 
'\n'   185         header += 
'LIST 1=(4211,3,0,49,91,20,530,0,0,40,50,0,0,0,0,0,0,3,0,0,3,0)' + 
'\n'   188         header += 
'MAIN' + 
'\n'   189         header += 
'STCP (10,0,4998)' + 
'\n'   190         header += 
'STOV (-1,0,-1)' + 
'\n'   191         header += 
'$ (1)' + 
'\n'           194         header_pkt += 
'( Robot     : %s )' % self.
ROBOT_MODEL + 
'\n'   195         header_pkt += 
'( Serial Nr : %s )' % self.
SERIAL_NR + 
'\n'   196         header_pkt += 
'( Achszahl  : %i )' % self.
nAxes + 
'\n'   197         header_pkt += 
'( Resolution: 2:2:2:2:2:2: Konfigend)'   199         self.
PROG.insert(0, header)
   200         self.
PROG.append(
'\nEND')
   220     def progsave(self, folder, progname, ask_user = False, show_result = False):
   222         if not folder.endswith(
'/'):
   223             folder = folder + 
'/'   224         progname = progname + 
'.' + self.
PROG_EXT        226             filesave = 
getSaveFile(folder, progname, 
'Save program as...')
   227             if filesave 
is not None:
   228                 filesave = filesave.name
   232             filesave = folder + progname
   235         fid = open(filesave, 
"w")
   236         for line 
in self.
PROG:
   242         filesave_pkt = filesave[:-3]+
'pkt'   243         fid2 = open(filesave_pkt, 
"w")
   249         print(
'SAVED: %s\n' % filesave) 
   255             if type(show_result) 
is str:
   258                 p = subprocess.Popen([show_result, filesave, filesave_pkt])
   259             elif type(show_result) 
is list:
   261                 p = subprocess.Popen(show_result + [filesave])   
   265                 os.startfile(filesave)
   272             filesave_S = filesave[:-4] + 
'S'   273             filesave_P = filesave[:-4] + 
'P'               274             print(
"POPUP: Compiling S file with CONVSP.exe: %s..." % progname)
   278             command_list.append([self.
PATH_MAKE_SP + 
'CONVSP', filesave.replace(
'/',
'\\'), filesave_S.replace(
'/',
'\\')])
   279             command_list.append([self.
PATH_MAKE_SP + 
'CONVSP', filesave_pkt.replace(
'/',
'\\'), filesave_P.replace(
'/',
'\\')])            
   283             self.
LOG += 
'Program generation for: ' + progname + 
'\n'   284             for command 
in command_list:
   285                 with subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1, universal_newlines=
True) 
as p:
   286                     for line 
in p.stdout:
   287                         line_ok = line.strip()
   288                         self.
LOG += line_ok + 
'\n'   289                         print(
"POPUP: " + line_ok)
   294     def ProgSave(self, folder, progname, ask_user = False, show_result = False):
   300                 print(
"Warning: ProgFinish was not called properly")
   324             self.
progsave(folder, progname_last, ask_user, show_result)
   344             self.
progsave(folder, progname, ask_user, show_result)
   347             print(
"Warning! Program has not been properly finished")
   348             self.
progsave(folder, progname, ask_user, show_result)
   350         if show_result 
and len(self.
LOG) > 0:
   351             mbox(
'Program generation LOG:\n\n' + self.
LOG)
   354         """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".   355         The connection parameters must be provided in the robot connection menu of RoboDK"""   358     def MoveJ(self, pose, joints, conf_RLF=None):
   359         """Add a joint movement"""   362         self.
addline(
"GP (%i)" % (target_id))
   365     def MoveL(self, pose, joints, conf_RLF=None):
   366         """Add a linear movement"""           374         self.
addline(
"GC (%i)" % (target_id))
   377     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   378         """Add a circular movement"""   382         self.
addline(
"ARC (%i,%i,%i)" % (target_id1-1,target_id1,target_id2))        
   385         """Change the robot reference frame"""   388         self.
RunMessage(
'Using %s (targets wrt base):' % (str(frame_name)), 
True)
   389         self.
RunMessage(
'%.1f,%.1f,%.1f,%.1f,%.1f,%.1f' % (xyzwpr[0], xyzwpr[1], xyzwpr[2], xyzwpr[3], xyzwpr[4], xyzwpr[5]), 
True)
   392         """Change the robot TCP"""   394         self.
RunMessage(
'Tool %s should be close to:' % (str(tool_name)), 
True)
   395         self.
RunMessage(
'%.1f,%.1f,%.1f,%.1f,%.1f,%.1f' % (xyzwpr[0], xyzwpr[1], xyzwpr[2], xyzwpr[3], xyzwpr[4], xyzwpr[5]), 
True)
   398         """Pause the robot program"""   402             self.
addline(
'WAITM %.0f' % (time_ms))
   405         """Changes the robot speed (in mm/s)"""   409         """Changes the robot acceleration (in mm/s2)"""   410         self.
addlog(
'Set acceleration not defined')
   413         """Changes the robot joint speed (in deg/s)"""   414         speedj = max(0.01,min(speed,100.0)) 
   418             self.
STR_VJ = 
"VJ=%.1f" % speedj
   421         """Changes the robot joint acceleration (in deg/s2)"""   422         self.
addlog(
'Set acceleration not defined')
   425         """Changes the zone data approach (makes the movement more smooth)"""   429             self.
STR_PL = 
' PL=%i' % round(min(zone_mm/25, 4))        
   432         """Sets a variable (output) to a given value"""   433         if type(io_var) != str:  
   434             io_var = 
'OT#(%s)' % str(io_var)        
   435         if type(io_value) != str: 
   443         self.
addline(
'DOUT %s %s' % (io_var, io_value))
   445     def waitDI(self, io_var, io_value, timeout_ms=-1):
   446         """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided."""   447         if type(io_var) != str:  
   448             io_var = 
'IN#(%s)' % str(io_var)        
   449         if type(io_value) != str: 
   458             self.
addline(
'WAIT %s=%s' % (io_var, io_value))
   461             self.
addline(
'WAIT %s=%s T=%.2f' % (io_var, io_value, timeout_ms*0.001))
   464     def RunCode(self, code, is_function_call = False):
   465         """Adds code or a function call"""   472             if code.startswith(
"Extrude"):
   475             code.replace(
' ',
'_')
   476             self.
addline(
'CALL %s' % (code))
   483         """Add a joint movement"""   488             self.
addline(
'! MSG %s' % message)
   498         """Add a program line"""   504         self.
PROG.append(newline)
   507         """Add a line at the end of the program (used for targets)"""   511         """Add a log message"""   515         self.
LOG = self.
LOG + newline + 
'\n'   527         for i 
in range(len(joints)):
   532         self.
addline_targets(
'%05i,%05i,%05i,%05i,' % (cid, speed, interpolation, outputs) + 
','.join(str_pulses))                
   554             turnJ4 = (joints[3]+180)//360
   555             turnJ6 = (joints[5]+180)//360
   556             turnJ1 = (joints[0]+180)//360
   557             turns = [turnJ4, turnJ6, turnJ1]
   559         confdata = 
'%i,%i,%i,%i,%i,%i,0,0' % tuple(conf_RLF[:3] + turns[:3])      
   562         self.
addline_targets(
'%i,' % cid + 
'%.3f,%.3f,%.3f,%.2f,%.2f,%.2f' % tuple(xyzwpr))
   571     [x,y,z,r,p,w] = xyzrpw
   581     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]])
   584     """Test the post with a basic program"""   586     robot = 
RobotPost(
'CLOOS test', 
'CLOOS robot robot', 6)
   588     robot.ProgStart(
"Program")
   589     robot.RunMessage(
"Program generated by RoboDK", 
True)
   590     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]), 
None, 0)
   591     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]), 
None, 0)
   592     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   593     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   594     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   595     robot.RunMessage(
"Setting air valve 1 on")
   596     robot.RunCode(
"TCP_On", 
True)
   598     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   599     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   600     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   601     robot.RunMessage(
"Setting air valve off")
   602     robot.RunCode(
"TCP_Off", 
True)
   604     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   605     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   606     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   607     robot.ProgFinish(
"Program")
   610     robot.PROG = robot.PROG_LIST.pop()
   611     print(
"\n\n--------------- TXT file ----------------\n")
   612     for line 
in robot.PROG:
   615     print(
"\n\n--------------- PKT file ----------------\n")
   616     robot.PROG_TARGETS = robot.PROG_TARGETS_LIST.pop()
   617     for line 
in robot.PROG_TARGETS:
   620     if len(robot.LOG) > 0:
   621         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   623     input(
"Press Enter to close...")
   625 if __name__ == 
"__main__":
   626     """Function to call when the module is executed by itself: test""" def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def setSpeed(self, speed_mms)
def RunCode(self, code, is_function_call=False)
def add_target_cartesian(self, pose, joints, conf_RLF)
def setDO(self, io_var, io_value)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def get_safe_name(progname, max_chars=7)
def setSpeedJoints(self, speed_degs)
def setZoneData(self, zone_mm)
def MoveJ(self, pose, joints, conf_RLF=None)
def MoveL(self, pose, joints, conf_RLF=None)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def setTool(self, pose, tool_id, tool_name)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def page_size_control(self)
def ProgFinish(self, progname, new_page=False)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def addlog(self, newline)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
bool INCLUDE_SUB_PROGRAMS
def setAccelerationJoints(self, accel_degss)
def setFrame(self, pose, frame_id, frame_name)
def ProgStart(self, progname, new_page=False)
def RunMessage(self, message, iscomment=False)
def add_target_joints(self, joints, interpolation=0)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def progsave(self, folder, progname, ask_user=False, show_result=False)
def addline_targets(self, newline)
def setAcceleration(self, accel_mmss)
def addline(self, newline, movetype=' ')