Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Describing the Parameters

Since the parameters are essentially a user interface for the engineer, make sure to design the parameters first, before developing the rest. Some guidelines:

  • Make the parameters as simple to use as possible.
  • Add a clear description of the parameter.
  • Don't use secret language or hidden codes.
  • Keep the units uniform (distance in meters, time in seconds, etc.).
  • Keep the names uniform.

To declare the parameters, ROS2 provides the function declare_parameter. Make sure you describe the parameter with a ParameterDescriptor as well, so you can describe the type, limits, description, options, etc. Describing the parameters this way also allows RQt to access them properly.

Booleans

A boolean parameter is described as follows:

self.declare_parameter('my_parameter',False,ParameterDescriptor(
    type=ParameterType.PARAMETER_BOOL,
    description='Boolean parameter.'
))

In the Monitor, this will show up as a checkbox.

Integers

An integer parameter is described as follows:

self.declare_parameter('my_parameter',0,ParameterDescriptor(
    type=ParameterType.PARAMETER_INTEGER,
    description='Integer parameter.'
))

In the Monitor, this will show up as an input text field.

Ranged Integers

A ranged integer parameter is described as follows:

self.declare_parameter('my_parameter',0,ParameterDescriptor(
    type=ParameterType.PARAMETER_INTEGER,
    description='Ranged integer parameter.'
    integer_range=[IntegerRange(from_value=0,to_value=100,step=5)]
))

In the Monitor, this will show up as a slider.

Integers with Options

An integer with options is described as follows:

self.declare_parameter('my_parameter',0,ParameterDescriptor(
    type=ParameterType.PARAMETER_INTEGER,
    description='Integer parameter with options.'
    additional_constraints='{"options": [2,3,5,7,11]}'
))

In the Monitor, this will show up as a dropdown menu.

Doubles

An double parameter is described as follows:

self.declare_parameter('my_parameter',0.0,ParameterDescriptor(
    type=ParameterType.PARAMETER_DOUBLE,
    description='Double parameter.'
))

In the Monitor, this will show up as an input text field.

Note: Make sure to use an actual floating point value as default/initial value in the call (here 0.0).

Ranged Doubles

A ranged double parameter is described as follows:

self.declare_parameter('my_parameter',0.0,ParameterDescriptor(
    type=ParameterType.PARAMETER_DOUBLE,
    description='Ranged double parameter.',
    floating_point_range=[FloatingPointRange(from_value=0.0,to_value=10.0,step=0.5)]
))

In the Monitor, this will show up as a slider.

Note: Make sure to use an actual floating point value as default/initial value in the call (here 0.0).

Doubles with Options

A double with options is described as follows:

self.declare_parameter('my_parameter',0.0,ParameterDescriptor(
    type=ParameterType.PARAMETER_DOUBLE,
    description='Double parameter with options.'
    additional_constraints='{"options": [3.1415927,2.7182818,1.6180339]}'
))

In the Monitor, this will show up as a dropdown menu.

Note: Make sure to use an actual floating point value as default/initial value in the call (here 0.0).

Strings

A string parameter is described as follows:

self.declare_parameter('my_parameter','Hello',ParameterDescriptor(
    type=ParameterType.PARAMETER_STRING,
    description='String parameter.'
))

In the Monitor, this will show up as an input text field.

Strings with Options

A string with options is described as follows:

self.declare_parameter('my_parameter','Hello',ParameterDescriptor(
    type=ParameterType.PARAMETER_STRING,
    description='String parameter with options.'
    additional_constraints='{"options": ["Hello","World"]}'
))

In the Monitor, this will show up as a dropdown menu.

Arrays of Booleans, Integers, Doubles or Strings

Support for array parameters is still under construction. It is possible to use array parameters, and they are persistent, but there is currently no Monitor interface to edit them.

Read-only Parameters

To block the engineer from changing the parameter using the Monitor, you can make it a read-only parameter. Add read_only=True to the ParameterDescriptor.

Private Parameters

To unclog the Monitor's parameter page, and the engineer's understanding of the system, it is also possible to complete hide a parameter. In order to do this add "private": true to the additional_constraints in the ParameterDescriptor.