Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow parsing of multiple visual or collision elements #26

Merged
merged 4 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/urdf_parser_py/urdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,19 @@ def joint_type(self, value): self.type = value
class Link(xmlr.Object):
def __init__(self, name=None, visual=None, inertial=None, collision=None,
origin=None):
self.aggregate_init()
self.name = name
self.visual = visual
self.visuals = []
self.inertial = inertial
self.collision = collision
self.collisions = []
self.origin = origin

xmlr.reflect(Link, params=[
name_attribute,
origin_element,
xmlr.AggregateElement('visual', Visual),
xmlr.AggregateElement('collision', Collision),
xmlr.Element('inertial', Inertial, False),
xmlr.Element('visual', Visual, False),
xmlr.Element('collision', Collision, False)
])


Expand Down
38 changes: 38 additions & 0 deletions test/test_urdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,44 @@ def test_robot_material_missing_color_and_texture(self):
</robot>'''
self.assertRaises(ParseException, self.parse, xml)

def test_link_multiple_visual(self):
xml = '''<?xml version="1.0"?>
<robot name="test">
<link name="link">
<visual>
<geometry>
<cylinder length="1" radius="1"/>
</geometry>
<material name="mat"/>
</visual>
<visual>
<geometry>
<cylinder length="4" radius="0.5"/>
</geometry>
<material name="mat2"/>
</visual>
</link>
</robot>'''
self.parse_and_compare(xml)

def test_link_multiple_collision(self):
xml = '''<?xml version="1.0"?>
<robot name="test">
<link name="link">
<collision>
<geometry>
<cylinder length="1" radius="1"/>
</geometry>
</collision>
<collision>
<geometry>
<cylinder length="4" radius="0.5"/>
</geometry>
</collision>
</link>
</robot>'''
self.parse_and_compare(xml)


class LinkOriginTestCase(unittest.TestCase):
@mock.patch('urdf_parser_py.xml_reflection.on_error',
Expand Down