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

SDF: support plugin with repeated elements #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

srmainwaring
Copy link

This PR adds support for SDF plugins that contain repeated elements (#139)

Repeated elements are specified by assigning a list to a tag in a dictionary of plugin arguments. For example running the code:

from pcg_gazebo.parsers.sdf import create_sdf_element
from pcg_gazebo.parsers.sdf import Plugin

plugin_args = dict(
    control=list([  
        dict(
            attributes=dict(
                channel="0"
            ),
            value=dict(
                jointName='steer_joint',
                useForce=1
            )
        ),
        dict(
            attributes=dict(
                channel="2"
            ),
            value=dict(
                jointName='motor_joint',
                useForce=1
            )
        )        
    ])
)

plugin = create_sdf_element('plugin')
plugin.name = 'plugin'
plugin.filename = 'libPlugin.so'
plugin.value = plugin_args
print(plugin)

ouputs

<plugin name="plugin" filename="libPlugin.so">
  <control channel="0">
    <jointName>steer_joint</jointName>
    <useForce>1</useForce>
  </control>
  <control channel="2">
    <jointName>motor_joint</jointName>
    <useForce>1</useForce>
  </control>
</plugin>

Lists of numbers and strings continue to work as before:

plugin_args = dict(
    xyz=[1.0, 2.0, 3.0],
    rpy=[0.1, 0.2, 0.3],
)

plugin = create_sdf_element('plugin')
plugin.name = 'plugin'
plugin.filename = 'libPlugin.so'
plugin.from_dict(plugin_args)
print(plugin)
<plugin name="plugin" filename="libPlugin.so">
  <xyz>1.0 2.0 3.0</xyz>
  <rpy>0.1 0.2 0.3</rpy>
</plugin>

- Plugin._add_child_element: allow multiple element with the same tag by assigning a list to the dictionary entry
- XMLCustom._get_elem_as_xml: process a list of repeated elements as well as a single element containing a list

Signed-off-by: Rhys Mainwaring <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant