Epson_RC.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 an Epson robot with RC controller and 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 
50 # ----------------------------------------------------
51 def pose_2_str(pose):
52  """Prints a pose target"""
53  [x,y,z,a,b,c] = Pose_2_Staubli(pose)
54  return ('XY(%.3f, %.3f, %.3f, %.3f, %.3f, %.3f)' % (x,y,z,c,b,a))
55 
56 def angles_2_str(angles):
57  """Prints a joint target"""
58  str = ''
59  for i in range(len(angles)):
60  #data[3] = data[3] + -0.00
61  str = str + ('%.3f,' % (angles[i]))
62  str = str[:-1]
63  return "AglToPls(" + str + ")"
64 
65 # ----------------------------------------------------
66 # Object class that handles the robot instructions/syntax
67 class RobotPost(object):
68  """Robot post object"""
69  PROG_EXT = 'gpl' # set the program extension
70 
71  # other variables
72  # ROBOT_POST = 'unset'
73  ROBOT_NAME = ''
74  PROG_FILES = []
75 
76  nPROGS = 0
77  PROG = ''
78  TAB = ''
79  LOG = ''
80  nAxes = 6
81  FRAME = eye(4)
82  TOOL = eye(4)
83 
84 
85  def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
86  #self.ROBOT_POST = robotpost
87  self.ROBOT_NAME = robotname
88  self.PROG = ''
89  self.LOG = ''
90  self.nAxes = robot_axes
91 
92  def ProgStart(self, progname):
93  self.nPROGS = self.nPROGS + 1
94  if self.nPROGS == 1:
95  self.addline('Function %s' % progname)
96  self.TAB = ' '
97  self.addline('Motor On')
98  self.addline('Power High')
99 
100  def ProgFinish(self, progname):
101  self.TAB = ''
102  self.addline('Fend')
103 
104  def ProgSave(self, folder, progname, ask_user=True, show_result=True):
105  progname = progname + '.' + self.PROG_EXT
106  if ask_user or not DirExists(folder):
107  filesave = getSaveFile(folder, progname, 'Save program as...')
108  if filesave is not None:
109  filesave = filesave.name
110  else:
111  return
112  else:
113  filesave = folder + '/' + progname
114  fid = open(filesave, "w")
115  fid.write(self.PROG)
116  fid.close()
117  print('SAVED: %s\n' % filesave)
118  self.PROG_FILES = filesave
119 
120  #---------------------- show result
121  if show_result:
122  if type(show_result) is str:
123  # Open file with provided application
124  import subprocess
125  p = subprocess.Popen([show_result, filesave])
126  elif type(show_result) is list:
127  import subprocess
128  p = subprocess.Popen(show_result + [filesave])
129  else:
130  # open file with default application
131  import os
132  os.startfile(filesave)
133 
134  if len(self.LOG) > 0:
135  mbox('Program generation LOG:\n\n' + self.LOG)
136 
137  def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass):
138  """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".
139  The connection parameters must be provided in the robot connection menu of RoboDK"""
140  UploadFTP(self.PROG_FILES, robot_ip, remote_path, ftp_user, ftp_pass)
141 
142  def MoveJ(self, pose, joints, conf_RLF=None):
143  """Add a joint movement"""
144  #poseabs = self.FRAME * pose * invH(self.TOOL)
145  # Use of Move AglToPls(,,,) is also possible
146  self.addline('Go %s' % angles_2_str(joints))
147 
148  def MoveL(self, pose, joints, conf_RLF=None):
149  """Add a linear movement"""
150  poseabs = self.FRAME * pose
151  self.addline('TGo %s' % pose_2_str(poseabs))
152 
153  def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
154  """Add a circular movement"""
155  poseabs1 = self.FRAME * pose1
156  poseabs2 = self.FRAME * pose2
157  self.addline('Arc %s, %s ' % (pose_2_str(poseabs1), pose_2_str(poseabs2)))
158 
159  def setFrame(self, pose, frame_id = None, frame_name = None):
160  """Change the robot reference frame"""
161  self.FRAME = pose
162  self.addline("' Using reference frame %s: %s" % (frame_name, pose_2_str(pose)))
163 
164  def setTool(self, pose, tool_id = None, tool_name = None):
165  """Change the robot TCP"""
166  self.TOOL = pose
167  #self.addline('Tool ' + pose_2_str(pose))
168  pose_str = pose_2_str(pose)
169  self.addline("' Using Tool frame %s: %s" % (tool_name, pose_str))
170  if tool_id <= 0:
171  tool_id = 1
172 
173  self.addline('TLSet ' + str(tool_id) + ", " + pose_str)
174  self.addline('Tool ' + str(tool_id))
175 
176  def Pause(self, time_ms):
177  """Pause the robot program"""
178  self.addline('Wait %.3f' % (time_ms*0.001))
179 
180  def setSpeed(self, speed_mms):
181  """Changes the robot speed (in mm/s)"""
182  self.addline('Speed %.2f' % speed_mms)
183 
184  def Acceleration(self, accel_ptg):
185  """Changes the robot acceleration (in %)"""
186  accel_ptg = min(accel_ptg, 100)
187  self.addline('Accel %.2f, %.2f' % (accel_ptg, accel_ptg))
188 
189  def setSpeedJoints(self, speed_degs):
190  """Changes the robot joint speed (in deg/s)"""
191  pass
192  #self.addlog('setSpeedJoints not defined')
193 
194  def setAccelerationJoints(self, accel_degss):
195  """Changes the robot joint acceleration (in deg/s2)"""
196  pass
197  # self.addlog('setAccelerationJoints not defined')
198 
199  def setZoneData(self, zone_mm):
200  """Changes the zone data approach (makes the movement more smooth)"""
201  pass
202  #self.addlog('setZoneData not defined (%.1f mm)' % zone_mm)
203 
204  def setDO(self, io_var, io_value):
205  """Sets a variable (output) to a given value"""
206  if type(io_var) != str: # set default variable name if io_var is a number
207  io_var = '%s' % str(io_var)
208  if type(io_value) != str: # set default variable value if io_value is a number
209  if io_value > 0:
210  io_value = 'On'
211  else:
212  io_value = 'Off'
213 
214  # at this point, io_var and io_value must be string values
215  self.addline('%s %s' % (io_value, io_var))
216 
217  def waitDI(self, io_var, io_value, timeout_ms=-1):
218  """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided."""
219  if type(io_var) != str: # set default variable name if io_var is a number
220  io_var = 'In(%s)' % str(io_var)
221  if type(io_value) != str: # set default variable value if io_value is a number
222  if io_value > 0:
223  io_value = 'On'
224  else:
225  io_value = 'Off'
226 
227  # at this point, io_var and io_value must be string values
228  if timeout_ms < 0:
229  self.addline('Wait %s = %s' % (io_var, io_value))
230  else:
231  self.addline('Wait %s = %s Timeout = %.1f' % (io_var, io_value, timeout_ms))
232 
233  def RunCode(self, code, is_function_call = False):
234  """Adds code or a function call"""
235  if is_function_call:
236  code.replace(' ','_')
237  self.addline("Call " + code)
238  else:
239  self.addline("Xqt 2, " + code)
240 
241  def RunMessage(self, message, iscomment = False):
242  """Display a message in the robot controller screen (teach pendant)"""
243  if iscomment:
244  self.addline("' " + message)
245  else:
246  self.addline('Print "%s"' % message)
247 
248 # ------------------ private ----------------------
249  def addline(self, newline):
250  """Add a program line"""
251  self.PROG = self.PROG + self.TAB + newline + '\n'
252 
253  def addlog(self, newline):
254  """Add a log message"""
255  self.LOG = self.LOG + newline + '\n'
256 
257 # -------------------------------------------------
258 # ------------ For testing purposes ---------------
259 def Pose(xyzrpw):
260  [x,y,z,r,p,w] = xyzrpw
261  a = r*math.pi/180
262  b = p*math.pi/180
263  c = w*math.pi/180
264  ca = math.cos(a)
265  sa = math.sin(a)
266  cb = math.cos(b)
267  sb = math.sin(b)
268  cc = math.cos(c)
269  sc = math.sin(c)
270  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]])
271 
272 def test_post():
273  """Test the post with a basic program"""
274 
275  robot = RobotPost()
276 
277  robot.ProgStart("Program")
278 
279  robot.MoveJ(Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
280  robot.MoveL(Pose([200, 250, 15, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
281  robot.MoveC(Pose([200, 200, 34, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122],Pose([200, 200, 15, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122])
282  #robot.setFrame(Pose([192.305408, 222.255946, 0.000000, 0.000000, 0.000000, 0.000000]),5,'Frame 5')
283  robot.setSpeed(30)
284  #robot.Delay(1000)
285 
286  #robot.ProgFinish("Program")
287  #robot.ProgSave(".","Program",True)
288  print(robot.PROG)
289  if len(robot.LOG) > 0:
290  mbox('Program generation LOG:\n\n' + robot.LOG)
291 
292  input("Press Enter to close...")
293 
294 if __name__ == "__main__":
295  """Function to call when the module is executed by itself: test"""
296  test_post()
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
Definition: Epson_RC.py:137
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
Definition: Epson_RC.py:85
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
Definition: robodk.py:1312
def MoveJ(self, pose, joints, conf_RLF=None)
Definition: Epson_RC.py:142
def setFrame(self, pose, frame_id=None, frame_name=None)
Definition: Epson_RC.py:159
def MoveL(self, pose, joints, conf_RLF=None)
Definition: Epson_RC.py:148
def RunMessage(self, message, iscomment=False)
Definition: Epson_RC.py:241
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
Definition: robodk.py:1458
def setTool(self, pose, tool_id=None, tool_name=None)
Definition: Epson_RC.py:164
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
Definition: Epson_RC.py:153
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
Definition: robodk.py:1354
def RunCode(self, code, is_function_call=False)
Definition: Epson_RC.py:233
def waitDI(self, io_var, io_value, timeout_ms=-1)
Definition: Epson_RC.py:217
def ProgSave(self, folder, progname, ask_user=True, show_result=True)
Definition: Epson_RC.py:104


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