From 2a3196a5b180f68768c704ae5772fcaa0709d061 Mon Sep 17 00:00:00 2001 From: Christoph Froehlich Date: Thu, 7 Sep 2023 13:28:56 +0000 Subject: [PATCH 1/2] Add mock_hardware to diffbot --- example_2/bringup/launch/diffbot.launch.py | 11 ++++ .../ros2_control/diffbot.ros2_control.xacro | 20 ++++-- example_2/description/urdf/diffbot.urdf.xacro | 2 +- example_2/doc/userdoc.rst | 65 +++++++++++++++++++ 4 files changed, 91 insertions(+), 7 deletions(-) diff --git a/example_2/bringup/launch/diffbot.launch.py b/example_2/bringup/launch/diffbot.launch.py index 45ca0237..7a71af0b 100644 --- a/example_2/bringup/launch/diffbot.launch.py +++ b/example_2/bringup/launch/diffbot.launch.py @@ -32,9 +32,17 @@ def generate_launch_description(): description="Start RViz2 automatically with this launch file.", ) ) + declared_arguments.append( + DeclareLaunchArgument( + "use_mock_hardware", + default_value="false", + description="Start robot with mock hardware mirroring command to its states.", + ) + ) # Initialize Arguments gui = LaunchConfiguration("gui") + use_mock_hardware = LaunchConfiguration("use_mock_hardware") # Get URDF via xacro robot_description_content = Command( @@ -44,6 +52,9 @@ def generate_launch_description(): PathJoinSubstitution( [FindPackageShare("ros2_control_demo_example_2"), "urdf", "diffbot.urdf.xacro"] ), + " ", + "use_mock_hardware:=", + use_mock_hardware, ] ) robot_description = {"robot_description": robot_description_content} diff --git a/example_2/description/ros2_control/diffbot.ros2_control.xacro b/example_2/description/ros2_control/diffbot.ros2_control.xacro index e1f184d5..f30dcab6 100644 --- a/example_2/description/ros2_control/diffbot.ros2_control.xacro +++ b/example_2/description/ros2_control/diffbot.ros2_control.xacro @@ -1,14 +1,22 @@ - + - - ros2_control_demo_example_2/DiffBotSystemHardware - 0 - 3.0 - + + + ros2_control_demo_example_2/DiffBotSystemHardware + 0 + 3.0 + + + + + mock_components/GenericSystem + true + + diff --git a/example_2/description/urdf/diffbot.urdf.xacro b/example_2/description/urdf/diffbot.urdf.xacro index 0f68baad..7249ffe8 100644 --- a/example_2/description/urdf/diffbot.urdf.xacro +++ b/example_2/description/urdf/diffbot.urdf.xacro @@ -14,6 +14,6 @@ + name="DiffBot" prefix="$(arg prefix)" use_mock_hardware="$(arg use_mock_hardware)"/> diff --git a/example_2/doc/userdoc.rst b/example_2/doc/userdoc.rst index c986757d..116da462 100644 --- a/example_2/doc/userdoc.rst +++ b/example_2/doc/userdoc.rst @@ -69,6 +69,8 @@ Tutorial steps The ``[claimed]`` marker on command interfaces means that a controller has access to command *DiffBot*. + Furthermore, we can see that the command interface is of type ``velocity``, which is typical for a differential drive robot. + 4. Check if controllers are running .. code-block:: shell @@ -103,6 +105,69 @@ Tutorial steps [DiffBotSystemHardware]: Got command 43.33333 for 'left_wheel_joint'! [DiffBotSystemHardware]: Got command 50.00000 for 'right_wheel_joint'! +6. Let's introspect the ros2_control hardware component. Calling + + .. code-block:: shell + + ros2 control list_hardware_components + + should give you + + .. code-block:: shell + + Hardware Component 1 + name: DiffBot + type: system + plugin name: ros2_control_demo_example_2/DiffBotSystemHardware + state: id=3 label=active + command interfaces + left_wheel_joint/velocity [available] [claimed] + right_wheel_joint/velocity [available] [claimed] + + This shows that the custom hardware interface plugin is loaded and running. If you work on a real + robot and don't have a simulator running, it is often faster to use the ``mock_components/GenericSystem`` + hardware component instead of writing a custom one. Stop the launch file and start it again with + an additional parameter + + .. code-block:: shell + + ros2 launch ros2_control_demo_example_2 diffbot.launch.py use_mock_hardware:=True + + Calling + + .. code-block:: shell + + ros2 control list_hardware_components + + now should give you + + .. code-block:: shell + + Hardware Component 1 + name: DiffBot + type: system + plugin name: mock_components/GenericSystem + state: id=3 label=active + command interfaces + left_wheel_joint/velocity [available] [claimed] + right_wheel_joint/velocity [available] [claimed] + + You see that a different plugin was loaded. Having a look into the `diffbot.ros2_control.xacro `__, one can find the + instructions to load this plugin together with the parameter ``calculate_dynamics``. + + .. code-block:: xml + + + mock_components/GenericSystem + true + + + This enables the integration of the velocity commands to the position state interface, which can be + checked by means of ``ros2 topic echo /joint_states``: The position values are increasing over time if the robot is moving. + You now can test the setup with the commands from above, it should work identically as the custom hardware component plugin. + + More information on mock_components can be found in the :ref:`ros2_control documentation `. + Files used for this demos -------------------------- From 258ba16a14bf7a49b0701fb8584d2983a4612081 Mon Sep 17 00:00:00 2001 From: Christoph Froehlich Date: Thu, 7 Sep 2023 13:29:12 +0000 Subject: [PATCH 2/2] Fix position_state_following_offset and description --- example_3/bringup/launch/rrbot_system_multi_interface.launch.py | 2 +- .../rrbot_system_multi_interface.ros2_control.xacro | 2 +- example_4/bringup/launch/rrbot_system_with_sensor.launch.py | 2 +- .../ros2_control/rrbot_system_with_sensor.ros2_control.xacro | 2 +- .../bringup/launch/rrbot_system_with_external_sensor.launch.py | 2 +- .../external_rrbot_force_torque_sensor.ros2_control.xacro | 2 +- .../ros2_control/rrbot_system_position_only.ros2_control.xacro | 2 +- example_6/bringup/launch/rrbot_modular_actuators.launch.py | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/example_3/bringup/launch/rrbot_system_multi_interface.launch.py b/example_3/bringup/launch/rrbot_system_multi_interface.launch.py index 761e0515..e10c7997 100644 --- a/example_3/bringup/launch/rrbot_system_multi_interface.launch.py +++ b/example_3/bringup/launch/rrbot_system_multi_interface.launch.py @@ -45,7 +45,7 @@ def generate_launch_description(): DeclareLaunchArgument( "mock_sensor_commands", default_value="false", - description="Enable fake command interfaces for sensors used for simple simulations. \ + description="Enable mocked command interfaces for sensors used for simple simulations. \ Used only if 'use_mock_hardware' parameter is true.", ) ) diff --git a/example_3/description/ros2_control/rrbot_system_multi_interface.ros2_control.xacro b/example_3/description/ros2_control/rrbot_system_multi_interface.ros2_control.xacro index 98c3e1af..b0be21fa 100644 --- a/example_3/description/ros2_control/rrbot_system_multi_interface.ros2_control.xacro +++ b/example_3/description/ros2_control/rrbot_system_multi_interface.ros2_control.xacro @@ -9,7 +9,7 @@ mock_components/GenericSystem ${mock_sensor_commands} - 0.0 + 0.0 ros2_control_demo_example_3/RRBotSystemMultiInterfaceHardware diff --git a/example_4/bringup/launch/rrbot_system_with_sensor.launch.py b/example_4/bringup/launch/rrbot_system_with_sensor.launch.py index 7e78ff09..b9503914 100644 --- a/example_4/bringup/launch/rrbot_system_with_sensor.launch.py +++ b/example_4/bringup/launch/rrbot_system_with_sensor.launch.py @@ -45,7 +45,7 @@ def generate_launch_description(): DeclareLaunchArgument( "mock_sensor_commands", default_value="false", - description="Enable fake command interfaces for sensors used for simple simulations. \ + description="Enable mocked command interfaces for sensors used for simple simulations. \ Used only if 'use_mock_hardware' parameter is true.", ) ) diff --git a/example_4/description/ros2_control/rrbot_system_with_sensor.ros2_control.xacro b/example_4/description/ros2_control/rrbot_system_with_sensor.ros2_control.xacro index af0823fe..7b821e01 100644 --- a/example_4/description/ros2_control/rrbot_system_with_sensor.ros2_control.xacro +++ b/example_4/description/ros2_control/rrbot_system_with_sensor.ros2_control.xacro @@ -9,7 +9,7 @@ mock_components/GenericSystem ${mock_sensor_commands} - 0.0 + 0.0 ros2_control_demo_example_4/RRBotSystemWithSensorHardware diff --git a/example_5/bringup/launch/rrbot_system_with_external_sensor.launch.py b/example_5/bringup/launch/rrbot_system_with_external_sensor.launch.py index 1811949c..22919564 100755 --- a/example_5/bringup/launch/rrbot_system_with_external_sensor.launch.py +++ b/example_5/bringup/launch/rrbot_system_with_external_sensor.launch.py @@ -45,7 +45,7 @@ def generate_launch_description(): DeclareLaunchArgument( "mock_sensor_commands", default_value="false", - description="Enable fake command interfaces for sensors used for simple simulations. \ + description="Enable mocked command interfaces for sensors used for simple simulations. \ Used only if 'use_mock_hardware' parameter is true.", ) ) diff --git a/example_5/description/ros2_control/external_rrbot_force_torque_sensor.ros2_control.xacro b/example_5/description/ros2_control/external_rrbot_force_torque_sensor.ros2_control.xacro index c63d2bcb..521a090a 100644 --- a/example_5/description/ros2_control/external_rrbot_force_torque_sensor.ros2_control.xacro +++ b/example_5/description/ros2_control/external_rrbot_force_torque_sensor.ros2_control.xacro @@ -8,7 +8,7 @@ mock_components/GenericSystem ${mock_sensor_commands} - 0.0 + 0.0 ros2_control_demo_example_5/ExternalRRBotForceTorqueSensorHardware diff --git a/example_5/description/ros2_control/rrbot_system_position_only.ros2_control.xacro b/example_5/description/ros2_control/rrbot_system_position_only.ros2_control.xacro index 04f032d4..4ca6c5d2 100644 --- a/example_5/description/ros2_control/rrbot_system_position_only.ros2_control.xacro +++ b/example_5/description/ros2_control/rrbot_system_position_only.ros2_control.xacro @@ -9,7 +9,7 @@ mock_components/GenericSystem ${mock_sensor_commands} - 0.0 + 0.0 ros2_control_demo_example_5/RRBotSystemPositionOnlyHardware diff --git a/example_6/bringup/launch/rrbot_modular_actuators.launch.py b/example_6/bringup/launch/rrbot_modular_actuators.launch.py index d84d2bec..24821fd7 100644 --- a/example_6/bringup/launch/rrbot_modular_actuators.launch.py +++ b/example_6/bringup/launch/rrbot_modular_actuators.launch.py @@ -45,7 +45,7 @@ def generate_launch_description(): DeclareLaunchArgument( "mock_sensor_commands", default_value="false", - description="Enable fake command interfaces for sensors used for simple simulations. \ + description="Enable mocked command interfaces for sensors used for simple simulations. \ Used only if 'use_mock_hardware' parameter is true.", ) )