Kawasaki.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 Kawasaki robots.
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 def pose_2_str(pose,joints=None,reference=None):
50  """Converts a pose target to a string"""
51  if reference is not None:
52  pose = reference*pose
53  [x,y,z,w,p,r] = Pose_2_Adept(pose)
54  #return ('[%.3f,%.3f,%.3f,%.4f,%.4f,%.4f]' % (x,y,z,w,p,r))
55  return ('TRANS(%.3f,%.3f,%.3f,%.4f,%.4f,%.4f)' % (x,y,z,w,p,r))
56 
57 def joints_2_str(joints):
58  """Contverts a joint target to a string"""
59  return '[%s]' % (', '.join(format(ji, ".5f") for ji in joints))
60 
61 # ----------------------------------------------------
62 # Object class that handles the robot instructions/syntax
63 class RobotPost(object):
64  """Robot post object"""
65  PROG_EXT = 'pg' # set the program extension
66 
67  # other variables
68  ROBOT_POST = ''
69  ROBOT_NAME = ''
70  PROG_FILES = []
71 
72  PROG = ''
73  LOG = ''
74  nAxes = 6
75  TAB = ''
76  REF_FRAME = None
77 
78  def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
79  self.ROBOT_POST = robotpost
80  self.ROBOT_NAME = robotname
81  self.PROG = ''
82  self.LOG = ''
83  self.nAxes = robot_axes
84 
85  def ProgStart(self, progname):
86  self.addline('.PROGRAM %s()' % progname)
87  self.TAB = ' '
88 
89  def ProgFinish(self, progname):
90  self.TAB = ''
91  self.addline('.END')
92 
93  def ProgSave(self, folder, progname, ask_user = False, show_result = False):
94  progname = progname + '.' + self.PROG_EXT
95  if ask_user or not DirExists(folder):
96  filesave = getSaveFile(folder, progname, 'Save program as...')
97  if filesave is not None:
98  filesave = filesave.name
99  else:
100  return
101  else:
102  filesave = folder + '/' + progname
103  fid = open(filesave, "w")
104  fid.write(self.PROG)
105  fid.close()
106  print('SAVED: %s\n' % filesave) # tell RoboDK the path of the saved file
107  self.PROG_FILES = filesave
108 
109  # open file with default application
110  if show_result:
111  if type(show_result) is str:
112  # Open file with provided application
113  import subprocess
114  p = subprocess.Popen([show_result, filesave])
115  elif type(show_result) is list:
116  import subprocess
117  p = subprocess.Popen(show_result + [filesave])
118  else:
119  # open file with default application
120  import os
121  os.startfile(filesave)
122  if len(self.LOG) > 0:
123  mbox('Program generation LOG:\n\n' + self.LOG)
124 
125  def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass):
126  """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".
127  The connection parameters must be provided in the robot connection menu of RoboDK"""
128  UploadFTP(self.PROG_FILES, robot_ip, remote_path, ftp_user, ftp_pass)
129 
130  def MoveJ(self, pose, joints, conf_RLF=None):
131  """Add a joint movement"""
132  self.addline('JMOVE #' + joints_2_str(joints))
133 
134  def MoveL(self, pose, joints, conf_RLF=None):
135  """Add a linear movement"""
136  self.addline('LMOVE ' + pose_2_str(pose,joints))
137 
138  def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
139  """Add a circular movement"""
140  self.addline('C1MOVE ' + pose_2_str(pose1,joints1))
141  self.addline('C2MOVE ' + pose_2_str(pose2,joints2))
142 
143  def setFrame(self, pose, frame_id=None, frame_name=None):
144  """Change the robot reference frame"""
145  self.addline('BASE ' + pose_2_str(pose))
146 
147  def setTool(self, pose, tool_id=None, tool_name=None):
148  """Change the robot TCP"""
149  self.addline('TOOL ' + pose_2_str(pose))
150 
151  def Pause(self, time_ms):
152  """Pause the robot program"""
153  if time_ms <= 0:
154  self.addline('PAUSE')
155  else:
156  self.addline('TWAIT %.3f' % (time_ms*0.001))
157 
158  def setSpeed(self, speed_mms):
159  """Changes the robot speed (in mm/s)"""
160  speed_mms = min(5000, speed_mms)
161  self.addline('SPEED %.1f MM/S ALWAYS' % (speed_mms))
162 
163  def setAcceleration(self, accel_mmss):
164  """Changes the robot acceleration (in mm/s2)"""
165  # Warning! Here, acceleration in mmss is considered as a percentage!
166  accel_percentage = min(100,max(0,accel_mmss))
167  self.addline('ACCEL %.1f %.1f' % (accel_percentage, accel_percentage))
168 
169  def setSpeedJoints(self, speed_degs):
170  """Changes the robot joint speed (in deg/s)"""
171  # consider 500 deg/s the max speed (100%)
172  self.addline('SPEED %.1f ALWAYS' % (min(100,100*speed_degs/500)))
173 
174  def setAccelerationJoints(self, accel_degss):
175  """Changes the robot joint acceleration (in deg/s2)"""
176  self.addlog('setAccelerationJoints not defined')
177 
178  def setZoneData(self, zone_mm):
179  """Changes the zone data approach (makes the movement more smooth)"""
180  self.addline('ACCURACY %.3f ALWAYS' % zone_mm)
181 
182  def setDO(self, io_var, io_value):
183  """Sets a variable (output) to a given value"""
184  if type(io_var) != str: # set default variable name if io_var is a number
185  io_var = '%s' % str(io_var)
186  if type(io_value) != str: # set default variable value if io_value is a number
187  if io_value > 0:
188  io_value = ''
189  else:
190  io_value = '-'
191 
192  # at this point, io_var and io_value must be string values
193  self.addline('SIGNAL %s%s' % (io_value, io_var))
194 
195  def waitDI(self, io_var, io_value, timeout_ms=-1):
196  """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided."""
197  if type(io_var) != str: # set default variable name if io_var is a number
198  io_var = '%s' % str(io_var)
199  if type(io_value) != str: # set default variable value if io_value is a number
200  if io_value > 0:
201  io_value = ''
202  else:
203  io_value = '-'
204 
205  # at this point, io_var and io_value must be string values
206  if timeout_ms > 0:
207  self.RunMessage('Timeout not implemented', True)
208 
209  self.addline('WAIT SIG(%s%s)' % (io_value, io_var))
210 
211  def RunCode(self, code, is_function_call = False):
212  """Adds code or a function call"""
213  if is_function_call:
214  code.replace(' ','_')
215  if code.find('(') < 0:
216  code = code + '()'
217  self.addline("CALL " + code)
218  else:
219  self.addline(code)
220 
221  def RunMessage(self, message, iscomment = False):
222  """Add a joint movement"""
223  if iscomment:
224  self.addline('; ' + message)
225  else:
226  self.addline('TYPE "' + message + '"')
227 
228 # ------------------ private ----------------------
229  def addline(self, newline):
230  """Add a program line"""
231  self.PROG = self.PROG + self.TAB + newline + '\n'
232 
233  def addlog(self, newline):
234  """Add a log message"""
235  self.LOG = self.LOG + newline + '\n'
236 
237 # -------------------------------------------------
238 # ------------ For testing purposes ---------------
239 def Pose(xyzrpw):
240  [x,y,z,r,p,w] = xyzrpw
241  a = r*math.pi/180
242  b = p*math.pi/180
243  c = w*math.pi/180
244  ca = math.cos(a)
245  sa = math.sin(a)
246  cb = math.cos(b)
247  sb = math.sin(b)
248  cc = math.cos(c)
249  sc = math.sin(c)
250  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]])
251 
252 def test_post():
253  """Test the post with a basic program"""
254 
255  robot = RobotPost('Vplus_custom', 'Generic Adept Robot')
256 
257  robot.ProgStart("Program")
258  robot.RunMessage("Program generated by RoboDK", True)
259  robot.setFrame(Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
260  robot.setTool(Pose([62.5, -108.253175, 100, -60, 90, 0]))
261  robot.MoveJ(Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
262  robot.MoveL(Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
263  robot.MoveL(Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
264  robot.RunMessage("Setting air valve 1 on")
265  robot.RunCode("TCP_On", True)
266  robot.Pause(1000)
267  robot.MoveL(Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
268  robot.MoveL(Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
269  robot.MoveL(Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
270  robot.RunMessage("Setting air valve off")
271  robot.RunCode("TCP_Off(55)", True)
272  robot.Pause(1000)
273  robot.MoveL(Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
274  robot.MoveL(Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
275  robot.MoveL(Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
276  robot.ProgFinish("Program")
277  # robot.ProgSave(".","Program",True)
278  print(robot.PROG)
279  if len(robot.LOG) > 0:
280  mbox('Program generation LOG:\n\n' + robot.LOG)
281 
282  input("Press Enter to close...")
283 
284 if __name__ == "__main__":
285  """Function to call when the module is executed by itself: test"""
286  test_post()
def MoveJ(self, pose, joints, conf_RLF=None)
Definition: Kawasaki.py:130
def RunCode(self, code, is_function_call=False)
Definition: Kawasaki.py:211
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
Definition: Kawasaki.py:78
def setTool(self, pose, tool_id=None, tool_name=None)
Definition: Kawasaki.py:147
def pose_2_str(pose, joints=None, reference=None)
Definition: Kawasaki.py:49
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
Definition: robodk.py:1312
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
Definition: Kawasaki.py:125
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)
Definition: Kawasaki.py:134
def RunMessage(self, message, iscomment=False)
Definition: Kawasaki.py:221
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
Definition: robodk.py:1354
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
Definition: Kawasaki.py:138
def setFrame(self, pose, frame_id=None, frame_name=None)
Definition: Kawasaki.py:143
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
Definition: Kawasaki.py:93
def waitDI(self, io_var, io_value, timeout_ms=-1)
Definition: Kawasaki.py:195


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