gz-sim icon indicating copy to clipboard operation
gz-sim copied to clipboard

Add interface to allow systems to declare parameters

Open ivanpauno opened this issue 2 years ago • 0 comments

🎉 New feature

Based on https://github.com/ignitionrobotics/ign-transport/pull/305. Replacement of https://github.com/ignitionrobotics/ign-gazebo/pull/1280.

Summary

This PR adds:

  • An interface that can be implemented by systems that allows them to declare parameters (ISystemConfigureParameters):
    • The gazebo simulation runner creates an instance of ignition::transport::parameters::ParametersRegistry (see https://github.com/ignitionrobotics/ign-transport/pull/305) with a namespace /world/<world_name> that provides the following services:
    • /world/<world_name>/list_parameters service: List available parameters names and types.
    • /world/<world_name>/get_parameter service: Get the type and value of a parameter.
    • /world/<world_name>/set_parameter service: Set a parameter: parameter name, value and type need to be provided.

Summary of what's needed to declare and use a parameter can be seen in the wheel slip demo branch: diff.

Test it

I haven't written automated tests yet, but there's a demo using parameters in the wheel slip plugin:

  • https://github.com/ignitionrobotics/ign-gazebo/tree/ivanpauno/parameters-component-wheel-slip-demo6
  • https://github.com/ignitionrobotics/ign-msgs/tree/ivanpauno/parameters-component-wheel-slip-demo8

Steps to run the demo:

  • Build from source ignition fortress checking out the two branches specified above (I can provide PRs for another version if needed).
  • Launch the trisphere cycle world:
    ign gazebo trisphere_cycle_wheel_slip.sdf
    
  • In another terminal with the workspace sourced:
    • List available parameters:

      ign param -r /world/wheel_slip -l
      
      Expected output

      systems.wheel_slip.trisphere_cycle1.wheel_front [ignition.msgs.WheelSlipParameters] systems.wheel_slip.trisphere_cycle1.wheel_rear_right [ignition.msgs.WheelSlipParameters] systems.wheel_slip.trisphere_cycle0.wheel_rear_right [ignition.msgs.WheelSlipParameters] systems.wheel_slip.trisphere_cycle1.wheel_rear_left [ignition.msgs.WheelSlipParameters] systems.wheel_slip.trisphere_cycle0.wheel_rear_left [ignition.msgs.WheelSlipParameters] systems.wheel_slip.trisphere_cycle0.wheel_front [ignition.msgs.WheelSlipParameters]

    • Get the systems.wheel_slip.trisphere_cycle1.wheel_front parameter:

      ign param -r /world/wheel_slip -g -n systems.wheel_slip.trisphere_cycle1.wheel_front
      
      Expected output

      Getting parameter [systems.wheel_slip.trisphere_cycle1.wheel_front] for registry namespace [/world/wheel_slip]... Parameter type [ign_msgs.WheelSlipParameters]


      slip_compliance_lateral: 1 slip_compliance_longitudinal: 1

    • Set the systems.wheel_slip.trisphere_cycle1.wheel_front parameter to a different value:

      ign param -r /world/wheel_slip -s -n systems.wheel_slip.trisphere_cycle1.wheel_front -t ign_msgs.WheelSlipParameters -m "
        slip_compliance_lateral: 1
        slip_compliance_longitudinal: 2"
      
      Expected output

      Setting parameter [systems.wheel_slip.trisphere_cycle1.wheel_front] for world [wheel_slip]...

      Parameter successfully set!

    • Get the systems.wheel_slip.trisphere_cycle1.wheel_front parameter again, its value should have changed:

      ign param -r /world/wheel_slip -g -n systems.wheel_slip.trisphere_cycle1.wheel_front
      
      Expected output

      Getting parameter [systems.wheel_slip.trisphere_cycle1.wheel_front] for registry namespace [/world/wheel_slip]... Parameter type [ign_msgs.WheelSlipParameters]


      slip_compliance_lateral: 1 slip_compliance_longitudinal: 2

Checklist

  • [ ] Signed all commits for DCO
  • [ ] Added tests
  • [ ] Added example and/or tutorial
  • [ ] Updated documentation (as needed)
  • [ ] Updated migration guide (as needed)
  • [ ] codecheck passed (See contributing)
  • [ ] All tests passed (See test coverage)
  • [ ] While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

ivanpauno avatar Apr 08 '22 18:04 ivanpauno