generate_robot_srdf.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2008, Willow Garage, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of Willow Garage nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 
34 import sys
35 import os
36 from xml.dom.minidom import parse
37 import rospkg
38 import xml
39 import yaml
40 from copy import deepcopy
41 from shutil import copy2
42 
43 import xacro
44 import rospy
45 
46 from sr_moveit_hand_config.generate_hand_srdf import SRDFHandGenerator
47 from urdf_parser_py.urdf import URDF
48 
49 
50 class SRDFRobotGeneratorException(Exception):
51  def __init__(self, msg):
52  self.msg = msg
53 
54  def __str__(self):
55  return self.msg
56 
57 
58 class Subrobot(object):
59  def __init__(self, type):
60  self.type = type
61  self.name = ""
62  self.internal_name = ""
63  self.main_group = ""
64  self.other_groups = []
65  self.group_states = []
66  self.is_lite = False
67  self.prefix = ""
68  self.moveit_path = ""
69 
70 
71 class Manipulator(object):
72  def __init__(self, name, side, has_arm, has_hand):
73  self.name = name
74  self.side = side
75  self.has_arm = has_arm
76  self.has_hand = has_hand
77 
78  if has_arm:
79  self.arm = Subrobot("arm")
80  if self.side == "right":
81  self.arm.prefix = "ra_"
82  self.arm.internal_name = "right_arm"
83  else:
84  self.arm.prefix = "la_"
85  self.arm.internal_name = "left_arm"
86  if has_hand:
87  self.hand = Subrobot("hand")
88  if self.side == "right":
89  self.hand.prefix = "rh_"
90  self.hand.internal_name = "right_hand"
91  else:
92  self.hand.prefix = "lh_"
93  self.hand.internal_name = "left_hand"
94 
95 
96 def next_element(elt):
97  child = xacro.first_child_element(elt)
98  if child:
99  return child
100  while elt and elt.nodeType == xml.dom.Node.ELEMENT_NODE:
101  next = xacro.next_sibling_element(elt)
102  if next:
103  return next
104  elt = elt.parentNode
105  return None
106 
107 
108 class Robot(object):
109  def __init__(self):
110  self.name = ""
111  self.manipulators = []
112 
113  def set_parameters(self, yamldoc):
114  # Read robot description yaml
115  if "robot" in yamldoc:
116  robot_yaml = yamldoc["robot"]
117  self.name = robot_yaml["name"]
118  if "manipulators" in robot_yaml:
119  manipulators_yaml = robot_yaml["manipulators"]
120  for manipulator_name in manipulators_yaml.keys():
121  manipulator_yaml = manipulators_yaml[manipulator_name]
122  side = manipulator_yaml["side"]
123  if side not in ["left", "right"]:
124  raise SRDFRobotGeneratorException("robot description did not specify " +
125  "a correct side for a manipulator")
126  has_arm = True if "arm" in manipulator_yaml else False
127  has_hand = True if "hand" in manipulator_yaml else False
128  if not has_hand and not has_arm:
129  raise SRDFRobotGeneratorException("robot description did not specify " +
130  "either an arm or hand for a manipulator")
131  # TODO: check that each manipulator do not have more than one arm and hand
132  manipulator = Manipulator(manipulator_name, side, has_arm, has_hand)
133  if has_arm:
134  arm_yaml = manipulator_yaml["arm"]
135  if "name" in arm_yaml:
136  manipulator.arm.name = arm_yaml["name"]
137  else:
138  raise SRDFRobotGeneratorException("arm name should be specified")
139  if "moveit_path" in arm_yaml:
140  package_name = arm_yaml["moveit_path"]["package"]
141  relative_path = arm_yaml["moveit_path"]["relative_path"]
142  manipulator.arm.moveit_path = rospkg.RosPack().get_path(package_name) + relative_path
143  if "extra_groups_config_path" in arm_yaml:
144  relative_path = arm_yaml["extra_groups_config_path"]
145  manipulator.arm.extra_groups_config_path = \
146  rospkg.RosPack().get_path("sr_multi_moveit_config") + relative_path
147  if "main_group" in arm_yaml:
148  manipulator.arm.main_group = arm_yaml["main_group"]
149  else:
150  raise SRDFRobotGeneratorException("arm main_group should be specified")
151  if "other_groups" in arm_yaml:
152  for group in arm_yaml["other_groups"]:
153  manipulator.arm.other_groups.append(group)
154  if "group_states" in arm_yaml:
155  for group_state in arm_yaml["group_states"]:
156  manipulator.arm.group_states.append(group_state)
157 
158  if has_hand:
159  hand_yaml = manipulator_yaml["hand"]
160  if "name" in hand_yaml:
161  manipulator.hand.name = hand_yaml["name"]
162  if "main_group" in hand_yaml:
163  manipulator.hand.main_group = hand_yaml["main_group"]
164  if "other_groups" in hand_yaml:
165  for group in hand_yaml["other_groups"]:
166  manipulator.hand.other_groups.append(group)
167  if "group_states" in hand_yaml:
168  for group_state in hand_yaml["group_states"]:
169  manipulator.hand.group_states.append(group_state)
170  if "is_lite" in hand_yaml:
171  manipulator.hand.is_lite = bool(hand_yaml["is_lite"])
172 
173  self.manipulators.append(manipulator)
174  else:
175  raise SRDFRobotGeneratorException("robot description did not specify a robot")
176 
177 
178 class SRDFRobotGenerator(object):
179  def __init__(self, description_file=None, load=True):
180  if description_file is None and len(sys.argv) > 1:
181  description_file = sys.argv[1]
182 
183  self._save_files = rospy.get_param('~save_files', False)
184  self._path_to_save_files = rospy.get_param('~path_to_save_files', "/tmp/")
185  self._file_name = rospy.get_param('~file_name', "generated_robot")
186 
187  # ARM
188  self.rospack = rospkg.RosPack()
189  self.package_path = self.rospack.get_path('sr_multi_moveit_config')
190 
191  self.robot = Robot()
192 
193  with open(description_file, "r") as stream:
194  yamldoc = yaml.load(stream)
195 
196  self.robot.set_parameters(yamldoc)
197  self.arm_srdf_xmls = []
198  self.hand_srdf_xmls = []
199 
200  new_srdf_file_name = "generated_robot.srdf"
201  self.start_new_srdf(new_srdf_file_name)
202  for manipulator_id, manipulator in enumerate(self.robot.manipulators):
203  if manipulator.has_arm:
204  # Read arm srdf
205  arm_srdf_path = manipulator.arm.moveit_path + "/" + manipulator.arm.name + ".srdf"
206  with open(arm_srdf_path, 'r') as stream:
207  self.arm_srdf_xmls.append(parse(stream))
208  xacro.process_includes(self.arm_srdf_xmls[manipulator_id], os.path.dirname(sys.argv[0]))
209  xacro.process_doc(self.arm_srdf_xmls[manipulator_id])
210 
211  if manipulator.has_hand:
212  # Generate and read hand srdf
213  hand_urdf_path = self.rospack.get_path('sr_description') + "/robots/" + manipulator.hand.name
214  with open(hand_urdf_path, 'r') as hand_urdf_xacro_file:
215  hand_urdf_xml = parse(hand_urdf_xacro_file)
216  xacro.process_includes(hand_urdf_xml, os.path.dirname(sys.argv[0]))
217  xacro.process_doc(hand_urdf_xml)
218 
219  hand_urdf = hand_urdf_xml.toprettyxml(indent=' ')
220  srdfHandGenerator = SRDFHandGenerator(hand_urdf, load=False, save=False)
221  self.hand_srdf_xmls.append(srdfHandGenerator.get_hand_srdf())
222 
223  comment = ["Manipulator:" + manipulator.name]
224  self.add_comments(comment)
225 
226  # Add groups and group states
227  if manipulator.has_arm:
228  self.parse_arm_groups(manipulator_id, manipulator)
229  if manipulator.has_hand:
230  self.parse_hand_groups(manipulator_id, manipulator)
231 
232  # Add groups for bimanual arm system
233  if len(self.robot.manipulators) == 2:
234  if self.robot.manipulators[0].has_arm and self.robot.manipulators[1].has_arm:
235  comment = ["Bimanual groups"]
236  self.add_comments(comment)
237  self.add_bimanual_arm_groups(self.robot.manipulators[0].arm.internal_name,
238  self.robot.manipulators[1].arm.internal_name)
239 
240  for manipulator_id, manipulator in enumerate(self.robot.manipulators):
241 
242  # Add end effectors
243  comment = ["END EFFECTOR: Purpose: Represent information about an end effector."]
244  self.add_comments(comment)
245  if manipulator.has_hand:
246  self.parse_hand_end_effectors(manipulator_id, manipulator)
247  if manipulator.has_arm:
248  self.parse_arm_end_effectors(manipulator_id, manipulator)
249 
250  # Add virtual joints
251  if manipulator.has_arm:
252  pass
253  # self.parse_arm_virtual_joint(manipulator)
254  else:
255  self.parse_hand_virtual_joint(manipulator_id, manipulator)
256 
257  # Add disable collisions
258  comment = ["DISABLE COLLISIONS: By default it is assumed that any link of the robot could potentially " +
259  "come into collision with any other link in the robot. This tag disables collision checking " +
260  "between a specified pair of links."]
261  self.add_comments(comment)
262  if manipulator.has_arm:
263  self.parse_arm_collisions(manipulator_id, manipulator)
264  if manipulator.has_hand:
265  self.parse_hand_collisions(manipulator_id, manipulator)
266 
267  # Finish and close file
268  self.new_robot_srdf.write('</robot>\n')
269  self.new_robot_srdf.close()
270  if load:
271  with open(self.package_path + "/config/" + new_srdf_file_name, 'r') as stream:
272  srdf = parse(stream)
273 
274  rospy.loginfo("Loading SRDF on parameter server")
275  robot_description_param = rospy.resolve_name('robot_description') + "_semantic"
276  rospy.set_param(robot_description_param,
277  srdf.toprettyxml(indent=' '))
278 
279  if self._save_files:
280  rospy.loginfo("Robot urdf and srdf have been saved to %s" % self._path_to_save_files)
281 
282  # srdf: File is already generated so just need to be copied to specified location
283  copy2(self.package_path + "/config/" + new_srdf_file_name, self._path_to_save_files +
284  "/" + self._file_name + ".srdf")
285 
286  # urdf: File can be copied from rosparam
287  if rospy.has_param('/robot_description'):
288  urdf_str = rospy.get_param('/robot_description')
289  urdf_file = open(self._path_to_save_files + "/" + self._file_name + ".urdf", "wb")
290  urdf_file.write(urdf_str)
291  urdf_file.close()
292 
293  rospy.loginfo("generated_robot.srdf has been generated and saved.")
294 
295  def start_new_srdf(self, file_name):
296  # Generate new robot srdf with arm information
297  self.new_robot_srdf = open(self.package_path + "/config/" + file_name, 'w')
298 
299  self.new_robot_srdf.write('<?xml version="1.0" ?>\n')
300  banner = ["This does not replace URDF, and is not an extension of URDF.\n" +
301  " This is a format for representing semantic information about the robot structure.\n" +
302  " A URDF file must exist for this robot as well, where the joints and the links that are" +
303  "referenced are defined\n"]
304  self.add_comments(banner, "")
305  self.new_robot_srdf.write('<robot name="' + self.robot.name + '">\n')
306  comments = ["GROUPS: Representation of a set of joints and links. This can be useful for specifying DOF to " +
307  "plan for, defining arms, end effectors, etc",
308  "LINKS: When a link is specified, the parent joint of that link (if it exists) is automatically" +
309  "included",
310  "JOINTS: When a joint is specified, the child link of that joint (which will always exist) is" +
311  "automatically included",
312  "CHAINS: When a chain is specified, all the links along the chain (including endpoints) are" +
313  "included in the group. Additionally, all the joints that are parents to included links are " +
314  "also included. This means that joints along the chain and the parent joint of the base link " +
315  "are included in the group",
316  "SUBGROUPS: Groups can also be formed by referencing to already defined group names"]
317  self.add_comments(comments)
318 
319  def parse_arm_groups(self, manipulator_id, manipulator):
320  previous = self.arm_srdf_xmls[manipulator_id].documentElement
321  elt = next_element(previous)
322  while elt:
323  if elt.tagName == 'group':
324  # Check it is not a subgroup
325  if len(elt.childNodes) > 0:
326  group_name = elt.getAttribute('name')
327  if group_name == manipulator.arm.main_group or group_name in manipulator.arm.other_groups:
328  if group_name == manipulator.arm.main_group:
329  elt.setAttribute('name', manipulator.arm.internal_name)
330  else:
331  elt.setAttribute('name', manipulator.arm.prefix + group_name)
332  for index, group_element in enumerate(elt.getElementsByTagName("chain")):
333  attributes = ["base_link", "tip_link"]
334  for attribute in attributes:
335  node_attribute = group_element.getAttributeNode(attribute)
336  node_attribute.nodeValue = (manipulator.arm.prefix +
337  group_element.getAttribute(attribute))
338  for tagName in ["joint", "link", "group"]:
339  for index, group_element in enumerate(elt.getElementsByTagName(tagName)):
340  attribute_name = group_element.getAttribute("name")
341  node_attribute = group_element.getAttributeNode("name")
342  node_attribute.nodeValue = (manipulator.arm.prefix + attribute_name)
343 
344  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
345  if group_name == manipulator.arm.main_group and (manipulator.has_hand and
346  not manipulator.hand.is_lite):
347  elt.setAttribute('name', manipulator.arm.internal_name + "_and_wrist")
348  for group_element in elt.getElementsByTagName("chain"):
349  node_attribute = group_element.getAttributeNode("tip_link")
350  node_attribute.nodeValue = (manipulator.hand.prefix + "palm")
351  if len(elt.getElementsByTagName("joint")) > 0:
352  node = deepcopy(elt.getElementsByTagName("joint")[0])
353  node_attribute = node.getAttributeNode("name")
354  node_attribute.nodeValue = (manipulator.hand.prefix + "WRJ2")
355  newatt = elt.appendChild(node)
356  node = deepcopy(elt.getElementsByTagName("joint")[0])
357  node_attribute = node.getAttributeNode("name")
358  node_attribute.nodeValue = (manipulator.hand.prefix + "WRJ1")
359  newatt = elt.appendChild(node)
360  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
361  elt.setAttribute('name', manipulator.arm.internal_name + "_and_manipulator")
362  for group_element in elt.getElementsByTagName("chain"):
363  node_attribute = group_element.getAttributeNode("tip_link")
364  node_attribute.nodeValue = (manipulator.hand.prefix + "manipulator")
365  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
366  if group_name == manipulator.arm.main_group and (manipulator.has_hand):
367  new_group = xml.dom.minidom.Document().createElement('group')
368  new_group.setAttribute("name", manipulator.arm.internal_name + "_and_hand")
369  if manipulator.hand.is_lite:
370  arm_group = xml.dom.minidom.Document().createElement('group name="' +
371  manipulator.arm.internal_name + '"')
372  else:
373  arm_group = xml.dom.minidom.Document().createElement('group name="' +
374  manipulator.arm.internal_name + '"')
375  new_group.appendChild(arm_group)
376  hand_group = xml.dom.minidom.Document().createElement('group name="' +
377  manipulator.hand.internal_name + '"')
378  new_group.appendChild(hand_group)
379  new_group.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
380  elif elt.tagName == 'group_state':
381  group_state_name = elt.getAttribute('name')
382  group_name = elt.getAttribute('group')
383  if group_state_name in manipulator.arm.group_states and (group_name == manipulator.arm.main_group or
384  group_name in manipulator.arm.other_groups):
385  elt.setAttribute('name', manipulator.arm.prefix + group_state_name)
386  if group_name == manipulator.arm.main_group:
387  elt.setAttribute('group', manipulator.arm.internal_name)
388  else:
389  elt.setAttribute('group', manipulator.arm.prefix + group_name)
390  for index, group_element in enumerate(elt.getElementsByTagName("joint")):
391  attribute_name = group_element.getAttribute("name")
392  if attribute_name in ["WRJ1", "WRJ2"]:
393  if manipulator.has_hand:
394  if not manipulator.hand.is_lite:
395  node_attribute = group_element.getAttributeNode("name")
396  node_attribute.nodeValue = (manipulator.hand.prefix + attribute_name)
397  else:
398  group_element.parentNode.removeChild(group_element)
399  else:
400  node_attribute = group_element.getAttributeNode("name")
401  node_attribute.nodeValue = (manipulator.arm.prefix + attribute_name)
402  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
403  previous = elt
404  elt = next_element(previous)
405 
406  def add_bimanual_arm_groups(self, group_1, group_2):
407  new_group = xml.dom.minidom.Document().createElement('group')
408  new_group.setAttribute("name", "two_arms")
409  arm_group_1 = xml.dom.minidom.Document().createElement('group name="' + group_1 + '"')
410  new_group.appendChild(arm_group_1)
411  arm_group_2 = xml.dom.minidom.Document().createElement('group name="' + group_2 + '"')
412  new_group.appendChild(arm_group_2)
413  new_group.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
414 
415  new_group = xml.dom.minidom.Document().createElement('group')
416  new_group.setAttribute("name", "two_arms_and_hands")
417  arm_group_1 = xml.dom.minidom.Document().createElement('group name="' + group_1 + '_and_hand"')
418  new_group.appendChild(arm_group_1)
419  arm_group_2 = xml.dom.minidom.Document().createElement('group name="' + group_2 + '_and_hand"')
420  new_group.appendChild(arm_group_2)
421  new_group.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
422 
423  def parse_hand_groups(self, manipulator_id, manipulator):
424  previous = self.hand_srdf_xmls[manipulator_id].documentElement
425  elt = next_element(previous)
426  while elt:
427  if elt.tagName == 'group':
428  # Check it is not a subgroup
429  if len(elt.childNodes) > 0:
430  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
431  elif elt.tagName == 'group_state':
432  for index, group_element in enumerate(elt.getElementsByTagName("joint")):
433  attribute_name = group_element.getAttribute("name")
434  attribute_name = attribute_name.split("_")[1]
435  if attribute_name in ["WRJ1", "WRJ2"] and manipulator.has_arm:
436  group_element.parentNode.removeChild(group_element)
437  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
438  previous = elt
439  elt = next_element(previous)
440 
441  def parse_hand_end_effectors(self, manipulator_id, manipulator):
442  previous = self.hand_srdf_xmls[manipulator_id].documentElement
443  elt = next_element(previous)
444  while elt:
445  if elt.tagName == 'end_effector':
446  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
447  previous = elt
448  elt = next_element(previous)
449 
450  def parse_arm_end_effectors(self, manipulator_id, manipulator):
451  previous = self.arm_srdf_xmls[manipulator_id].documentElement
452  elt = next_element(previous)
453  while elt:
454  if elt.tagName == 'end_effector':
455  if manipulator.has_hand:
456  elt.getAttributeNode("name").nodeValue = manipulator.arm.internal_name + "_ee"
457  elt.getAttributeNode("parent_link").nodeValue = (manipulator.arm.prefix +
458  elt.getAttribute("parent_link"))
459  elt.getAttributeNode("group").nodeValue = manipulator.hand.internal_name
460  elt.setAttribute('parent_group', manipulator.arm.internal_name)
461  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
462  newElement = deepcopy(elt)
463  newElement.getAttributeNode("name").nodeValue = manipulator.arm.prefix + "and_wrist_ee"
464  newElement.getAttributeNode("parent_link").nodeValue = manipulator.hand.prefix + "palm"
465  newElement.getAttributeNode("group").nodeValue = manipulator.hand.prefix + "fingers"
466  newElement.setAttribute('parent_group', manipulator.arm.internal_name + "_and_wrist")
467  newElement.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
468  newElement = deepcopy(elt)
469  newElement.getAttributeNode("name").nodeValue = manipulator.arm.prefix + "and_manipulator_ee"
470  newElement.getAttributeNode("parent_link").nodeValue = manipulator.hand.prefix + "manipulator"
471  newElement.getAttributeNode("group").nodeValue = manipulator.hand.prefix + "fingers"
472  newElement.setAttribute('parent_group', manipulator.arm.internal_name + "_and_manipulator")
473  newElement.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
474  else:
475  elt.getAttributeNode("name").nodeValue = manipulator.arm.internal_name + "_ee"
476  elt.getAttributeNode("parent_link").nodeValue = (manipulator.arm.prefix +
477  elt.getAttribute("parent_link"))
478  elt.getAttributeNode("group").nodeValue = (manipulator.arm.prefix +
479  elt.getAttribute("group"))
480  elt.setAttribute('parent_group', manipulator.arm.internal_name)
481  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
482  previous = elt
483  elt = next_element(previous)
484 
485  def parse_arm_virtual_joint(self, manipulator_id, manipulator):
486  comment = ["VIRTUAL JOINT: Purpose: this element defines a virtual joint between a robot link and an " +
487  "external frame of reference (considered fixed with respect to the robot)"]
488  self.add_comments(comment)
489  previous = self.arm_srdf_xmls[manipulator_id].documentElement
490  elt = next_element(previous)
491  while elt:
492  if elt.tagName == 'virtual_joint':
493  elt.getAttributeNode("name").nodeValue = "world_to_" + manipulator.arm.internal_name
494  elt.getAttributeNode("child_link").nodeValue = manipulator.arm.prefix + elt.getAttribute("child_link")
495  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
496  previous = elt
497  elt = next_element(previous)
498 
499  def parse_hand_virtual_joint(self, manipulator_id, manipulator):
500  comment = ["VIRTUAL JOINT: Purpose: this element defines a virtual joint between a robot link and an " +
501  "external frame of reference (considered fixed with respect to the robot)"]
502  self.add_comments(comment)
503  previous = self.hand_srdf_xmls[manipulator_id].documentElement
504  elt = next_element(previous)
505  while elt:
506  if elt.tagName == 'virtual_joint':
507  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
508  previous = elt
509  elt = next_element(previous)
510 
511  def parse_arm_collisions(self, manipulator_id, manipulator):
512  comment = [manipulator.arm.internal_name + " collisions"]
513  self.add_comments(comment)
514  previous = self.arm_srdf_xmls[manipulator_id].documentElement
515  elt = next_element(previous)
516 
517  while elt:
518  if elt.tagName == 'disable_collisions':
519  elt.getAttributeNode("link1").nodeValue = (manipulator.arm.prefix + elt.getAttribute("link1"))
520  elt.getAttributeNode("link2").nodeValue = (manipulator.arm.prefix + elt.getAttribute("link2"))
521  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
522  newElement = deepcopy(elt)
523 
524  previous = elt
525  elt = next_element(previous)
526  # Add collisions between arm and hand
527  if manipulator.has_hand:
528  if rospy.has_param('/robot_description'):
529  urdf_str = rospy.get_param('/robot_description')
530  robot = URDF.from_xml_string(urdf_str)
531  arm_chain = robot.get_chain("world", manipulator.hand.prefix + "forearm", joints=False, fixed=False)
532 
533  newElement.getAttributeNode("link1").nodeValue = arm_chain[-2]
534  newElement.getAttributeNode("link2").nodeValue = manipulator.hand.prefix + "forearm"
535  newElement.getAttributeNode("reason").nodeValue = "Adjacent"
536  newElement.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
537 
538  newElement.getAttributeNode("link1").nodeValue = arm_chain[-3]
539  newElement.getAttributeNode("link2").nodeValue = manipulator.hand.prefix + "forearm"
540  newElement.getAttributeNode("reason").nodeValue = "Adjacent"
541  newElement.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
542 
543  newElement.getAttributeNode("link1").nodeValue = arm_chain[-4]
544  newElement.getAttributeNode("link2").nodeValue = manipulator.hand.prefix + "forearm"
545  newElement.getAttributeNode("reason").nodeValue = "Adjacent"
546  newElement.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
547 
548  def parse_hand_collisions(self, manipulator_id, manipulator):
549  comment = [manipulator.hand.internal_name + " collisions"]
550  self.add_comments(comment)
551  previous = self.hand_srdf_xmls[manipulator_id].documentElement
552  elt = next_element(previous)
553  while elt:
554  if elt.tagName == 'disable_collisions':
555  elt.writexml(self.new_robot_srdf, indent=" ", addindent=" ", newl="\n")
556 
557  previous = elt
558  elt = next_element(previous)
559 
560  def add_comments(self, comments, addindent=" "):
561  xml_comments = [xml.dom.minidom.Comment(c) for c in comments]
562  for comment in xml_comments:
563  comment.writexml(self.new_robot_srdf, indent=addindent, addindent=addindent, newl="\n")
564 
565 
566 if __name__ == '__main__':
567  rospy.init_node('robot_srdf_generator', anonymous=True)
568  robot_generator = SRDFRobotGenerator()
def process_includes(elt, macros=None, symbols=None)
def parse_hand_groups(self, manipulator_id, manipulator)
def parse_hand_end_effectors(self, manipulator_id, manipulator)
def parse_arm_virtual_joint(self, manipulator_id, manipulator)
def process_doc(doc, in_order=False, just_deps=False, just_includes=False, mappings=None, xacro_ns=True, kwargs)
def add_comments(self, comments, addindent=" ")
def __init__(self, description_file=None, load=True)
def parse_arm_groups(self, manipulator_id, manipulator)
def __init__(self, name, side, has_arm, has_hand)
def set_parameters(self, yamldoc)
def parse_hand_collisions(self, manipulator_id, manipulator)
def parse_hand_virtual_joint(self, manipulator_id, manipulator)
def add_bimanual_arm_groups(self, group_1, group_2)
def parse_arm_collisions(self, manipulator_id, manipulator)
def parse_arm_end_effectors(self, manipulator_id, manipulator)


sr_multi_moveit_config
Author(s): MoveIt Setup Assistant
autogenerated on Wed Oct 14 2020 04:05:22