KUKA_KRC2_DAT.py
Go to the documentation of this file.
1 # Copyright 2017 - RoboDK Software S.L. - http://www.robodk.com/
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
6 # Unless required by applicable law or agreed to in writing, software
7 # distributed under the License is distributed on an "AS IS" BASIS,
8 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9 # See the License for the specific language governing permissions and
10 # limitations under the License.
11 
12 # ----------------------------------------------------
13 # This file is a POST PROCESSOR for Robot Offline Programming to generate programs
14 # for a Kuka robot with RoboDK
15 #
16 # To edit/test this POST PROCESSOR script file:
17 # Select "Program"->"Add/Edit Post Processor", then select your post or create a new one.
18 # You can edit this file using any text editor or Python editor. Using a Python editor allows to quickly evaluate a sample program at the end of this file.
19 # Python should be automatically installed with RoboDK
20 #
21 # You can also edit the POST PROCESSOR manually:
22 # 1- Open the *.py file with Python IDLE (right click -> Edit with IDLE)
23 # 2- Make the necessary changes
24 # 3- Run the file to open Python Shell: Run -> Run module (F5 by default)
25 # 4- The "test_post()" function is called automatically
26 # Alternatively, you can edit this file using a text editor and run it with Python
27 #
28 # To use a POST PROCESSOR file you must place the *.py file in "C:/RoboDK/Posts/"
29 # To select one POST PROCESSOR for your robot in RoboDK you must follow these steps:
30 # 1- Open the robot panel (double click a robot)
31 # 2- Select "Parameters"
32 # 3- Select "Unlock advanced options"
33 # 4- Select your post as the file name in the "Robot brand" box
34 #
35 # To delete an existing POST PROCESSOR script, simply delete this file (.py file)
36 #
37 # ----------------------------------------------------
38 # More information about RoboDK Post Processors and Offline Programming here:
39 # http://www.robodk.com/help#PostProcessor
40 # http://www.robodk.com/doc/en/PythonAPI/postprocessor.html
41 # ----------------------------------------------------
42 
43 
44 # ----------------------------------------------------
45 # Import RoboDK tools
46 from robodk import *
47 
48 
49 HEADER = '''
50 ;FOLD INI
51 BAS (#INITMOV,0 )
52 ;ENDFOLD (INI)
53 
54 ;FOLD STARTPOS
55 $BWDSTART = FALSE
56 PDAT_ACT = PDEFAULT
57 BAS(#PTP_DAT)
58 FDAT_ACT = {TOOL_NO 0,BASE_NO 0,IPO_FRAME #BASE}
59 BAS(#FRAMES)
60 ;ENDFOLD
61 
62 ;FOLD SET DEFAULT SPEED
63 $VEL.CP=0.2
64 BAS(#VEL_PTP,100)
65 BAS(#TOOL,0)
66 BAS(#BASE,0)
67 ;ENDFOLD
68 
69 $ADVANCE = 5
70 
71 PTP $AXIS_ACT ; skip BCO quickly
72 '''
73 
74 # ----------------------------------------------------
75 def pose_2_str(pose):
76  """Converts a pose target to a string"""
77  #[x,y,z,w,p,r] = Pose_2_KUKA(pose)
78  #return ('X %.3f, Y %.3f, Z %.3f, A %.3f, B %.3f, C %.3f' % (x,y,z,r,p,w)) # old version had to be switched
79  [x,y,z,r,p,w] = pose_2_xyzrpw(pose)
80  return ('X %.3f,Y %.3f,Z %.3f,A %.3f,B %.3f,C %.3f' % (x,y,z,w,p,r))
81 
82 def pose_2_str_ext(pose,joints):
83  njoints = len(joints)
84  if njoints <= 6:
85  return pose_2_str(pose)
86  else:
87  extaxes = ''
88  for i in range(njoints-6):
89  extaxes = extaxes + (',E%i %.5f' % (i+1, joints[i+6]))
90  return pose_2_str(pose) + extaxes
91 
92 def angles_2_str(angles):
93  """Prints a joint target"""
94  str = ''
95  data = ['A1','A2','A3','A4','A5','A6','E1','E2','E3','E4','E5','E6']
96  for i in range(len(angles)):
97  str = str + ('%s %.5f,' % (data[i], angles[i]))
98  str = str[:-1]
99  return str
100 
101 def conf_2_str(confRLF):
102  if confRLF is None:
103  return "'B010'"
104  strconf = ""
105  if confRLF[2] > 0:
106  strconf = strconf + '1'
107  else:
108  strconf = strconf + '0'
109 
110  if confRLF[1] == 0:
111  strconf = strconf + '1'
112  else:
113  strconf = strconf + '0'
114 
115  if confRLF[0] > 0:
116  strconf = strconf + '1'
117  else:
118  strconf = strconf + '0'
119 
120  return "'B%s'" % strconf
121 
122 def joints_2_turn_str(joints):
123  if joints is None:
124  return "'B000000'"
125 
126  strturn = ""
127  for i in range(len(joints)):
128  if joints[i] < 0:
129  strturn = '1' + strturn
130  else:
131  strturn = '0' + strturn
132  return "'B%s'" % strturn
133 
134 
135 # ----------------------------------------------------
136 # Object class that handles the robot instructions/syntax
137 class RobotPost(object):
138  """Robot post object"""
139  PROG_EXT = 'src' # set the program extension
140 
141  # other variables
142  ROBOT_POST = ''
143  ROBOT_NAME = ''
144  PROG_FILES = []
145  PROG_NAME = 'unknown'
146  PROG_COUNT = 0
147 
148  BASE_ID = 1
149  TOOL_ID = 1
150  speed_ms = 1
151  speed_degs = 180
152  accel_mss = 1
153  accel_degss = 200
154  VEL_PTP = 100 # speed in percentage
155 
156  PROG = ''
157  PROG_DAT = ''
158  nPosDat = 0
159  LOG = ''
160  nAxes = 6
161  APO_VALUE = -1 # set to one for smooth path
162  C_DIS = ' C_DIS'
163  C_PTP = ' C_PTP'
164  ARC_ON = False
165  ARC_REQUIRED = False
166  nArcId = 0
167  ARC_Pgno = 108
168 
169  PROG_CALLS = []
170 
171  def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
172  self.ROBOT_POST = robotpost
173  self.ROBOT_NAME = robotname
174  self.PROG = ''
175  self.LOG = ''
176  self.nAxes = robot_axes
177 
178  def ProgStart(self, progname):
179  self.PROG_COUNT = self.PROG_COUNT + 1
180  self.addline('DEF %s ( )' % progname)
181  if self.PROG_COUNT == 1:
182  self.PROG = self.PROG + HEADER
183  self.PROG_NAME = progname
184  #if self.nAxes > 6:
185  #self.addline('$ACT_EX_AX = %i' % (self.nAxes-6))
186 
187  def ProgFinish(self, progname):
188  self.addline('END')
189 
190  def ProgSave(self, folder, progname, ask_user = False, show_result = False):
191  progname = progname + '.' + self.PROG_EXT
192  if ask_user or not DirExists(folder):
193  filesave = getSaveFile(folder, progname, 'Save program as...')
194  if filesave is not None:
195  filesave = filesave.name
196  else:
197  return
198  else:
199  filesave = folder + '/' + progname
200  fid = open(filesave, "w")
201  #fid.write("&ACCESS RVP\n")
202  #fid.write("&REL 1\n")
203  #fid.write("&COMMENT Generated by RoboDK\n")
204  fid.write("&ACCESS RVP\n")
205  fid.write("&REL 1\n") #fid.write("&REL 29\n")
206  fid.write("&PARAM TEMPLATE = C:\\KRC\\Roboter\\Template\\vorgabe\n")
207  fid.write("&PARAM EDITMASK = *\n")
208  fid.write(self.PROG)
209  fid.close()
210  print('SAVED: %s\n' % filesave) # tell RoboDK the path of the saved file
211  filesave_dat = filesave[:-3] + 'dat'
212  fid2 = open(filesave_dat, "w")
213  fid2.write('&ACCESS RVP\n')
214  fid2.write('&REL 1\n')
215  fid2.write("&COMMENT Generated by RoboDK\n")
216  fid2.write('&PARAM TEMPLATE = C:\\KRC\\Roboter\\Template\\vorgabe\n')
217  fid2.write('&PARAM EDITMASK = *\n')
218  fid2.write('DEFDAT %s\n\n' % self.PROG_NAME)
219  fid2.write('EXT BAS (BAS_COMMAND :IN,REAL :IN )\n')
220 
221  for prog_nm in self.PROG_CALLS:
222  fid2.write("EXT %s()\n" % prog_nm)
223  fid2.write('\n')
224  fid2.write(self.PROG_DAT)
225  fid2.write('\nENDDAT\n\n')
226  fid2.close()
227  print('SAVED: %s\n' % filesave_dat) # tell RoboDK the path of the saved file
228  self.PROG_FILES = [filesave, filesave_dat]
229  # open file with default application
230  if show_result:
231  if type(show_result) is str:
232  # Open file with provided application
233  import subprocess
234  p = subprocess.Popen([show_result, filesave_dat, filesave])
235  elif type(show_result) is list:
236  import subprocess
237  p = subprocess.Popen(show_result + [filesave])
238  else:
239  # open file with default application
240  import os
241  os.startfile(filesave)
242  os.startfile(filesave_dat)
243  if len(self.LOG) > 0:
244  mbox('Program generation LOG:\n\n' + self.LOG)
245 
246  def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass):
247  """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".
248  The connection parameters must be provided in the robot connection menu of RoboDK"""
249  UploadFTP(self.PROG_FILES, robot_ip, remote_path, ftp_user, ftp_pass)
250 
251  def MoveJ(self, pose, joints, conf_RLF=None):
252  """Add a joint movement"""
253  self.nPosDat = self.nPosDat + 1
254  vname = '%i' % self.nPosDat
255 
256  # Write SRC information ---------------------------
257  #;FOLD PTP P1 Vel=70 % PDAT1 Tool[1]:graco_negra Base[0];%{PE}%R 8.3.42,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:P1, 3:, 5:70, 7:PDAT1
258  #;FOLD PTP P1 Vel=70 % PDAT1 Tool[1]:graco_negra Base[0];%{PE}%R 8.3.32,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:P1, 3:, 5:70, 7:PDAT1
259  #$BWDSTART=FALSE
260  #PDAT_ACT=PPDAT1
261  #FDAT_ACT=FP1
262  #BAS(#PTP_PARAMS,70)
263  #PTP XP1
264  str_cont = ''
265  str_cdis = ''
266  if self.APO_VALUE >= 0:
267  str_cdis = 'C_PTP'
268  str_cont = 'CONT '
269  self.addline(';FOLD PTP P%s %sVel=%.0f %% PDAT%s Tool[%i] Base[%i];%%{PE}%%R 5.5.31,%%MKUKATPBASIS,%%CMOVE,%%VPTP,%%P 1:PTP, 2:P%s, 3:%s, 5:%.0f, 7:PDAT%s' % (vname, str_cont, self.VEL_PTP, vname, self.TOOL_ID, self.BASE_ID, vname, str_cdis, self.VEL_PTP, vname))
270  self.addline('$BWDSTART=FALSE')
271  self.addline('PDAT_ACT=PPDAT%s' % vname)
272  self.addline('FDAT_ACT=FP%s' % vname)
273  self.addline('BAS(#PTP_PARAMS,%.0f)' % self.VEL_PTP)
274  self.addline('PTP XP%s%s' % (vname,self.C_PTP))
275  self.addline(';ENDFOLD')
276 
277  # Write DAT information ---------------------------
278  #DECL E6POS XP1={X 27.0236969,Y 1220.23962,Z 669.846619,A -90.0563354,B 53.4202652,C -178.565933,S 2,T 35,E1 0.0,E2 0.0,E3 0.0,E4 0.0,E5 0.0,E6 0.0}
279  #DECL FDAT FP1={TOOL_NO 1,BASE_NO 0,IPO_FRAME #BASE,POINT2[] " ",TQ_STATE FALSE}
280  #DECL PDAT PPDAT1={VEL 100.000,ACC 100.000,APO_DIST 100.000,GEAR_JERK 50.0000,EXAX_IGN 0}
281  self.addDAT('DECL E6AXIS XP%s={%s}' % (vname, angles_2_str(joints)))
282  self.addDAT('DECL FDAT FP%s={TOOL_NO %i,BASE_NO %i,IPO_FRAME #BASE,POINT2[] " ",TQ_STATE FALSE}' % (vname, self.TOOL_ID, self.BASE_ID))
283  self.addDAT('DECL PDAT PPDAT%s={VEL %.3f,ACC 100.000,APO_DIST %.3f,APO_MODE #CPTP}' % (vname, self.VEL_PTP, max(self.APO_VALUE,1)))
284 
285  def MoveL(self, pose, joints, conf_RLF=None):
286  """Add a linear movement"""
287  self.nPosDat = self.nPosDat + 1
288  vname = '%i' % self.nPosDat
289 
290  # Write SRC information ---------------------------
291  #;FOLD LIN P56 Vel=2 m/s CPDAT37 Tool[1]:graco_negra Base[1]:vol1;%{PE}%R 8.3.42,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:P56, 3:, 5:2, 7:CPDAT37
292  #$BWDSTART=FALSE
293  #LDAT_ACT=LCPDAT37
294  #FDAT_ACT=FP56
295  #BAS(#CP_PARAMS,2)
296  #LIN XP56
297 
298  # If ARC information is provided:
299  #;FOLD LIN P5 CPDAT4 ARC Pgno= 108 W3 Tool[1]:ArcGun Base[0];%{PE}%R 5.5.0,%MKUKATPA20,%CARC_SWI,%VLIN,%P 1:LIN, 2:P5, 3:, 5:0.2, 7:CPDAT4, 10:108, 11:W3
300  #$BWDSTART=FALSE
301  #LDAT_ACT=LCPDAT4
302  #FDAT_ACT=FP5
303  #BAS(#CP_PARAMS,LDEFAULT.VEL)
304  #A20(ARC_SWIP,ADEFAULT,MW3,108)
305  #LIN XP5
306  #;ENDFOLD
307  str_cont = ''
308  str_cdis = ''
309  if self.APO_VALUE >= 0:
310  str_cdis = 'C_DIS'
311  str_cont = 'CONT '
312 
313  wid = ''
314  if not self.ARC_ON:
315  self.addline(';FOLD LIN P%s %sVel=%.3f m/s CPDAT%s Tool[%i] Base[%i];%%{PE}%%R 5.5.0,%%MKUKATPA20,%%CARC_SWI,%%VLIN,%%P 1:LIN, 2:P%s, 3:%s, 5:%.0f, 7:CPDAT%s' % (vname, str_cont, self.speed_ms, vname, self.TOOL_ID, self.BASE_ID, vname, str_cdis, self.speed_ms, vname))
316  else:
317  self.nArcId = self.nArcId + 1
318  wid = 'W%i' % self.nArcId
319  self.addline(';FOLD LIN P%s CPDAT%s ARC Pgno= %i %s Tool[%i] Base[%i];%%{PE}%%R 5.5.0,%%MKUKATPBASIS,%%CMOVE,%%VLIN,%%P 1:LIN, 2:P%s, 3:%s, 5:%.0f, 7:CPDAT%s, 10:%i, 11:%s' % (vname, str_cont, self.ARC_Pgno, wid, self.TOOL_ID, self.BASE_ID, vname, str_cdis, self.speed_ms, vname, self.ARC_Pgno, wid))
320  self.addline('$BWDSTART=FALSE')
321  self.addline('LDAT_ACT=LCPDAT%s' % vname)
322  self.addline('FDAT_ACT=FP%s' % vname)
323  if not self.ARC_ON:
324  self.addline('BAS(#CP_PARAMS,%.0f)' % self.speed_ms)
325  else:
326  self.addline('BAS(#CP_PARAMS,LDEFAULT.VEL)')
327  self.addline('A20(ARC_SWIP,ADEFAULT,M%s,%i)' % (wid, self.ARC_Pgno))
328 
329  self.addline('LIN XP%s%s' % (vname,self.C_DIS))
330  self.addline(';ENDFOLD')
331 
332  # Write DAT information ---------------------------
333  #DECL E6POS XP56={X -293.060028,Y 165.117493,Z 18.0715256,A -64.8358612,B 39.9032936,C -161.694565,S 2,T 3,E1 0.0,E2 0.0,E3 0.0,E4 0.0,E5 0.0,E6 0.0}
334  #DECL FDAT FP56={TOOL_NO 1,BASE_NO 1,IPO_FRAME #BASE,POINT2[] " ",TQ_STATE FALSE}
335  #DECL LDAT LCPDAT37={VEL 2.00000,ACC 100.000,APO_DIST 100.000,APO_FAC 50.0000,AXIS_VEL 100.000,AXIS_ACC 100.000,ORI_TYP #VAR,CIRC_TYP #BASE,JERK_FAC 50.0000,GEAR_JERK 50.0000,EXAX_IGN 0}
336 
337  # with arc information:
338  #DECL E6POS XP3={X 663.532104,Y -614.288025,Z 2346.43799,A 171.796906,B -55.8371086,C 6.86900616,S 0,T 14,E1 -2848.03809,E2 0.0,E3 0.0,E4 0.0,E5 0.0,E6 0.0}
339  #DECL FDAT FP3={TOOL_NO 1,BASE_NO 0,IPO_FRAME #BASE,POINT2[] " ",TQ_STATE FALSE}
340  #DECL LDAT LCPDAT2={VEL 2.0,ACC 100.0,APO_DIST 100.0,APO_FAC 50.0,ORI_TYP #VAR,CIRC_TYP #BASE,JERK_FAC 50.0}
341  #DECL WELD_FI MW1={PRG_NO 1,VELOCITY 0.109999999,WEAVFIG_MECH 1,WEAVLEN_MECH 6.0,WEAVAMP_MECH 7.0,WEAVANG_MECH 180.0,END_TIME 0.0149999997}
342  self.addDAT('DECL E6POS XP%s={%s}' % (vname, pose_2_str_ext(pose,joints)))
343  self.addDAT('DECL FDAT FP%s={TOOL_NO %i,BASE_NO %i,IPO_FRAME #BASE,POINT2[] " ",TQ_STATE FALSE}' % (vname, self.TOOL_ID, self.BASE_ID))
344  self.addDAT('DECL LDAT LCPDAT%s={VEL %.5f,ACC 100.000,APO_DIST %.3f,APO_FAC 50.0000,ORI_TYP #VAR,CIRC_TYP #BASE,JERK_FAC 50.0000}' % (vname, self.speed_ms, max(self.APO_VALUE,1)))
345  if not self.ARC_ON:
346  pass
347  else:
348  self.addDAT('DECL WELD_FI M%s={PRG_NO 1,VELOCITY %.3f,WEAVFIG_MECH 1,WEAVLEN_MECH 6.0,WEAVAMP_MECH 7.0,WEAVANG_MECH 180.0,END_TIME 0.015}' % (wid, self.speed_ms))
349 
350  def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
351  """Add a circular movement"""
352  self.addline('CIRC {' + pose_2_str_ext(pose1,joints1) + '},{' + pose_2_str_ext(pose2,joints2) + '}' + self.C_DIS)
353 
354  def setFrame(self, pose, frame_id=None, frame_name=None):
355  """Change the robot reference frame"""
356  if frame_name is not None and frame_name.endswith("Base"): # robot base frame
357  frame_id = 0
358  self.BASE_ID = frame_id
359  self.addline('BASE_DATA[%i] = {FRAME: %s}' % (self.BASE_ID, pose_2_str(pose)))
360  elif frame_id is not None and frame_id >= 0: # specified ID reference frame
361  self.BASE_ID = frame_id
362  self.addline('BASE_DATA[%i] = {FRAME: %s}' % (self.BASE_ID, pose_2_str(pose)))
363  else: # unspecified ID reference frame
364  self.BASE_ID = 1
365  self.addline('BASE_DATA[%i] = {FRAME: %s}' % (self.BASE_ID, pose_2_str(pose)))
366 
367  def setTool(self, pose, tool_id=None, tool_name=None):
368  """Change the robot TCP"""
369  if tool_id is not None and tool_id >= 0:
370  self.TOOL_ID = tool_id
371  self.addline('TOOL_DATA[%i] = {FRAME: %s}' % (self.TOOL_ID, pose_2_str(pose)))
372  else:
373  self.TOOL_ID = 1
374  self.addline('TOOL_DATA[%i] = {FRAME: %s}' % (self.TOOL_ID, pose_2_str(pose)))
375  #self.addline('$TOOL = {FRAME: ' + pose_2_str(pose) + '}')
376 
377  def Pause(self, time_ms):
378  """Pause the robot program"""
379  if time_ms <= 0:
380  self.addline('HALT')
381  else:
382  self.addline('WAIT SEC %.3f' % (time_ms*0.001))
383 
384  def setSpeed(self, speed_mms):
385  """Changes the robot speed (in mm/s)"""
386  self.speed_ms = speed_mms/1000.0
387  self.addline('$VEL.CP = %.5f' % (self.speed_ms))
388 
389  def setAcceleration(self, accel_mmss):
390  """Changes the current robot acceleration"""
391  self.accel_mss = accel_mmss/1000.0
392  self.addline('$ACC.CP = %.5f' % (self.accel_mss))
393 
394  def setSpeedJoints(self, speed_degs):
395  """Changes the robot joint speed (in deg/s)"""
396  self.speed_degs = speed_degs
397  self.addline('$VEL.ORI1 = %.5f' % speed_degs)
398  self.addline('$VEL.ORI2 = %.5f' % speed_degs)
399 
400  def setAccelerationJoints(self, accel_degss):
401  """Changes the robot joint acceleration (in deg/s2)"""
402  self.accel_degss = accel_degss
403  self.addline('$ACC.ORI1 = %.5f' % accel_degss)
404  self.addline('$ACC.ORI2 = %.5f' % accel_degss)
405 
406  def setZoneData(self, zone_mm):
407  """Changes the zone data approach (makes the movement more smooth)"""
408  self.APO_VALUE = zone_mm
409  if zone_mm >= 0:
410  self.addline('$APO.CPTP = %.3f' % zone_mm)
411  self.addline('$APO.CDIS = %.3f' % zone_mm)
412  C_DIS = ' C_DIS'
413  C_PTP = ' C_PTP'
414  else:
415  C_DIS = ''
416  C_PTP = ''
417 
418  def setDO(self, io_var, io_value):
419  """Sets a variable (output) to a given value"""
420  if type(io_var) != str: # set default variable name if io_var is a number
421  io_var = '$OUT[%s]' % str(io_var)
422  if type(io_value) != str: # set default variable value if io_value is a number
423  if io_value > 0:
424  io_value = 'TRUE'
425  else:
426  io_value = 'FALSE'
427 
428  # at this point, io_var and io_value must be string values
429  self.addline('%s=%s' % (io_var, io_value))
430 
431  def waitDI(self, io_var, io_value, timeout_ms=-1):
432  """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided."""
433  if type(io_var) != str: # set default variable name if io_var is a number
434  io_var = '$IN[%s]' % str(io_var)
435  if type(io_value) != str: # set default variable value if io_value is a number
436  if io_value > 0:
437  io_value = 'TRUE'
438  else:
439  io_value = 'FALSE'
440 
441  # at this point, io_var and io_value must be string values
442  if timeout_ms < 0:
443  self.addline('WAIT FOR (%s==%s)' % (io_var, io_value))
444  else:
445  self.addline('START_TIMER:')
446  self.addline('$TIMER_STOP[1]=TRUE')
447  self.addline('$TIMER_FLAG[1]=FALSE')
448  self.addline('$TIMER[1]=%.3f' % (float(timeout_ms)*0.001))
449  self.addline('$TIMER_STOP[1]=FALSE')
450  self.addline('WAIT FOR (%s==%s OR $TIMER_FLAG[1])' % (io_var, io_value))
451  self.addline('$TIMER_STOP[1]=TRUE')
452  self.addline('IF $TIMER_FLAG[1]== TRUE THEN')
453  self.addline(' HALT ; Timed out!')
454  self.addline(' GOTO START_TIMER')
455  self.addline('ENDIF')
456 
457  def RunCode(self, code, is_function_call = False):
458  """Adds code or a function call"""
459  if is_function_call:
460  code.replace(' ','_')
461  if not code.endswith(')'):
462  code = code + '()'
463  if code.startswith('ARC_ON'):
464  self.ARC_ON = True
465  self.ARC_REQUIRED = True
466  elif code.startswith('ARC_OFF'):
467  self.ARC_ON = False
468  else:
469 
470  fcn_def = code
471  if '(' in fcn_def:
472  fcn_def = fcn_def.split('(')[0]
473  if not (fcn_def in self.PROG_CALLS):
474  self.PROG_CALLS.append(fcn_def)
475 
476  self.addline(code)
477  else:
478  self.addline(code)
479 
480  def RunMessage(self, message, iscomment = False):
481  """Add a joint movement"""
482  if iscomment:
483  self.addline('; ' + message)
484  else:
485  self.addline('Wait for StrClear($LOOP_MSG[])')
486  self.addline('$LOOP_CONT = TRUE')
487  self.addline('$LOOP_MSG[] = "%s"' % message)
488 
489 # ------------------ private ----------------------
490  def addline(self, newline):
491  """Add a program line"""
492  self.PROG = self.PROG + newline + '\n'
493 
494  def addDAT(self, newline):
495  self.PROG_DAT = self.PROG_DAT + newline + '\n'
496 
497  def addlog(self, newline):
498  """Add a log message"""
499  self.LOG = self.LOG + newline + '\n'
500 
501 # -------------------------------------------------
502 # ------------ For testing purposes ---------------
503 def Pose(xyzrpw):
504  [x,y,z,r,p,w] = xyzrpw
505  a = r*math.pi/180
506  b = p*math.pi/180
507  c = w*math.pi/180
508  ca = math.cos(a)
509  sa = math.sin(a)
510  cb = math.cos(b)
511  sb = math.sin(b)
512  cc = math.cos(c)
513  sc = math.sin(c)
514  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]])
515 
516 def test_post():
517  """Test the post with a basic program"""
518 
519  robot = RobotPost('Kuka_custom', 'Generic Kuka')
520 
521  robot.ProgStart("Program")
522  robot.RunMessage("Program generated by RoboDK", True)
523  robot.setFrame(Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
524  robot.setTool(Pose([62.5, -108.253175, 100, -60, 90, 0]))
525  robot.MoveJ(Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
526  robot.MoveL(Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
527  robot.MoveL(Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
528  robot.RunMessage("Setting air valve 1 on")
529  robot.RunCode("TCP_On", True)
530  robot.Pause(1000)
531  robot.MoveL(Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
532  robot.MoveL(Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
533  robot.MoveL(Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
534  robot.RunMessage("Setting air valve off")
535  robot.RunCode("TCP_Off", True)
536  robot.Pause(1000)
537  robot.MoveL(Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
538  robot.MoveL(Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
539  robot.MoveL(Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
540  robot.ProgFinish("Program")
541  # robot.ProgSave(".","Program",True)
542  print(robot.PROG)
543  if len(robot.LOG) > 0:
544  mbox('Program generation LOG:\n\n' + robot.LOG)
545 
546  input("Press Enter to close...")
547 
548 if __name__ == "__main__":
549  """Function to call when the module is executed by itself: test"""
550  test_post()
def setTool(self, pose, tool_id=None, tool_name=None)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
Definition: robodk.py:1312
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def MoveJ(self, pose, joints, conf_RLF=None)
def setFrame(self, pose, frame_id=None, frame_name=None)
def RunCode(self, code, is_function_call=False)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
Definition: robodk.py:1458
def MoveL(self, pose, joints, conf_RLF=None)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
Definition: robodk.py:1354
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def RunMessage(self, message, iscomment=False)


ros_robodk_post_processors
Author(s): Victor Lamoine - Institut Maupertuis
autogenerated on Sun Jun 7 2020 03:50:22