Skip to content

Commit 7a5cf6d

Browse files
Adding mock_hardware to diffbot and update docs for all usages (ros-controls#357)
* Add mock_hardware to diffbot * Fix position_state_following_offset and description
1 parent b764e46 commit 7a5cf6d

File tree

12 files changed

+99
-15
lines changed

12 files changed

+99
-15
lines changed

example_2/bringup/launch/diffbot.launch.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,17 @@ def generate_launch_description():
3232
description="Start RViz2 automatically with this launch file.",
3333
)
3434
)
35+
declared_arguments.append(
36+
DeclareLaunchArgument(
37+
"use_mock_hardware",
38+
default_value="false",
39+
description="Start robot with mock hardware mirroring command to its states.",
40+
)
41+
)
3542

3643
# Initialize Arguments
3744
gui = LaunchConfiguration("gui")
45+
use_mock_hardware = LaunchConfiguration("use_mock_hardware")
3846

3947
# Get URDF via xacro
4048
robot_description_content = Command(
@@ -44,6 +52,9 @@ def generate_launch_description():
4452
PathJoinSubstitution(
4553
[FindPackageShare("ros2_control_demo_example_2"), "urdf", "diffbot.urdf.xacro"]
4654
),
55+
" ",
56+
"use_mock_hardware:=",
57+
use_mock_hardware,
4758
]
4859
)
4960
robot_description = {"robot_description": robot_description_content}

example_2/description/ros2_control/diffbot.ros2_control.xacro

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
<?xml version="1.0"?>
22
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
33

4-
<xacro:macro name="diffbot_ros2_control" params="name prefix">
4+
<xacro:macro name="diffbot_ros2_control" params="name prefix use_mock_hardware">
55

66
<ros2_control name="${name}" type="system">
7-
<hardware>
8-
<plugin>ros2_control_demo_example_2/DiffBotSystemHardware</plugin>
9-
<param name="example_param_hw_start_duration_sec">0</param>
10-
<param name="example_param_hw_stop_duration_sec">3.0</param>
11-
</hardware>
7+
<xacro:unless value="${use_mock_hardware}">
8+
<hardware>
9+
<plugin>ros2_control_demo_example_2/DiffBotSystemHardware</plugin>
10+
<param name="example_param_hw_start_duration_sec">0</param>
11+
<param name="example_param_hw_stop_duration_sec">3.0</param>
12+
</hardware>
13+
</xacro:unless>
14+
<xacro:if value="${use_mock_hardware}">
15+
<hardware>
16+
<plugin>mock_components/GenericSystem</plugin>
17+
<param name="calculate_dynamics">true</param>
18+
</hardware>
19+
</xacro:if>
1220
<joint name="${prefix}left_wheel_joint">
1321
<command_interface name="velocity"/>
1422
<state_interface name="position"/>

example_2/description/urdf/diffbot.urdf.xacro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
<xacro:diffbot prefix="$(arg prefix)" />
1515

1616
<xacro:diffbot_ros2_control
17-
name="DiffBot" prefix="$(arg prefix)" />
17+
name="DiffBot" prefix="$(arg prefix)" use_mock_hardware="$(arg use_mock_hardware)"/>
1818

1919
</robot>

example_2/doc/userdoc.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Tutorial steps
6969
7070
The ``[claimed]`` marker on command interfaces means that a controller has access to command *DiffBot*.
7171

72+
Furthermore, we can see that the command interface is of type ``velocity``, which is typical for a differential drive robot.
73+
7274
4. Check if controllers are running
7375

7476
.. code-block:: shell
@@ -103,6 +105,69 @@ Tutorial steps
103105
[DiffBotSystemHardware]: Got command 43.33333 for 'left_wheel_joint'!
104106
[DiffBotSystemHardware]: Got command 50.00000 for 'right_wheel_joint'!
105107
108+
6. Let's introspect the ros2_control hardware component. Calling
109+
110+
.. code-block:: shell
111+
112+
ros2 control list_hardware_components
113+
114+
should give you
115+
116+
.. code-block:: shell
117+
118+
Hardware Component 1
119+
name: DiffBot
120+
type: system
121+
plugin name: ros2_control_demo_example_2/DiffBotSystemHardware
122+
state: id=3 label=active
123+
command interfaces
124+
left_wheel_joint/velocity [available] [claimed]
125+
right_wheel_joint/velocity [available] [claimed]
126+
127+
This shows that the custom hardware interface plugin is loaded and running. If you work on a real
128+
robot and don't have a simulator running, it is often faster to use the ``mock_components/GenericSystem``
129+
hardware component instead of writing a custom one. Stop the launch file and start it again with
130+
an additional parameter
131+
132+
.. code-block:: shell
133+
134+
ros2 launch ros2_control_demo_example_2 diffbot.launch.py use_mock_hardware:=True
135+
136+
Calling
137+
138+
.. code-block:: shell
139+
140+
ros2 control list_hardware_components
141+
142+
now should give you
143+
144+
.. code-block:: shell
145+
146+
Hardware Component 1
147+
name: DiffBot
148+
type: system
149+
plugin name: mock_components/GenericSystem
150+
state: id=3 label=active
151+
command interfaces
152+
left_wheel_joint/velocity [available] [claimed]
153+
right_wheel_joint/velocity [available] [claimed]
154+
155+
You see that a different plugin was loaded. Having a look into the `diffbot.ros2_control.xacro <https://github.com/ros-controls/ros2_control_demos/tree/{REPOS_FILE_BRANCH}/example_2/description/ros2_control/diffbot.ros2_control.xacro>`__, one can find the
156+
instructions to load this plugin together with the parameter ``calculate_dynamics``.
157+
158+
.. code-block:: xml
159+
160+
<hardware>
161+
<plugin>mock_components/GenericSystem</plugin>
162+
<param name="calculate_dynamics">true</param>
163+
</hardware>
164+
165+
This enables the integration of the velocity commands to the position state interface, which can be
166+
checked by means of ``ros2 topic echo /joint_states``: The position values are increasing over time if the robot is moving.
167+
You now can test the setup with the commands from above, it should work identically as the custom hardware component plugin.
168+
169+
More information on mock_components can be found in the :ref:`ros2_control documentation <mock_components_userdoc>`.
170+
106171
Files used for this demos
107172
--------------------------
108173

example_3/bringup/launch/rrbot_system_multi_interface.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def generate_launch_description():
4545
DeclareLaunchArgument(
4646
"mock_sensor_commands",
4747
default_value="false",
48-
description="Enable fake command interfaces for sensors used for simple simulations. \
48+
description="Enable mocked command interfaces for sensors used for simple simulations. \
4949
Used only if 'use_mock_hardware' parameter is true.",
5050
)
5151
)

example_3/description/ros2_control/rrbot_system_multi_interface.ros2_control.xacro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<xacro:if value="${use_mock_hardware}">
1010
<plugin>mock_components/GenericSystem</plugin>
1111
<param name="mock_sensor_commands">${mock_sensor_commands}</param>
12-
<param name="state_following_offset">0.0</param>
12+
<param name="position_state_following_offset">0.0</param>
1313
</xacro:if>
1414
<xacro:unless value="${use_mock_hardware}">
1515
<plugin>ros2_control_demo_example_3/RRBotSystemMultiInterfaceHardware</plugin>

example_4/bringup/launch/rrbot_system_with_sensor.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def generate_launch_description():
4545
DeclareLaunchArgument(
4646
"mock_sensor_commands",
4747
default_value="false",
48-
description="Enable fake command interfaces for sensors used for simple simulations. \
48+
description="Enable mocked command interfaces for sensors used for simple simulations. \
4949
Used only if 'use_mock_hardware' parameter is true.",
5050
)
5151
)

example_4/description/ros2_control/rrbot_system_with_sensor.ros2_control.xacro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<xacro:if value="${use_mock_hardware}">
1010
<plugin>mock_components/GenericSystem</plugin>
1111
<param name="mock_sensor_commands">${mock_sensor_commands}</param>
12-
<param name="state_following_offset">0.0</param>
12+
<param name="position_state_following_offset">0.0</param>
1313
</xacro:if>
1414
<xacro:unless value="${use_mock_hardware}">
1515
<plugin>ros2_control_demo_example_4/RRBotSystemWithSensorHardware</plugin>

example_5/bringup/launch/rrbot_system_with_external_sensor.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def generate_launch_description():
4545
DeclareLaunchArgument(
4646
"mock_sensor_commands",
4747
default_value="false",
48-
description="Enable fake command interfaces for sensors used for simple simulations. \
48+
description="Enable mocked command interfaces for sensors used for simple simulations. \
4949
Used only if 'use_mock_hardware' parameter is true.",
5050
)
5151
)

example_5/description/ros2_control/external_rrbot_force_torque_sensor.ros2_control.xacro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<xacro:if value="${use_mock_hardware}">
99
<plugin>mock_components/GenericSystem</plugin>
1010
<param name="mock_sensor_commands">${mock_sensor_commands}</param>
11-
<param name="state_following_offset">0.0</param>
11+
<param name="position_state_following_offset">0.0</param>
1212
</xacro:if>
1313
<xacro:unless value="${use_mock_hardware}">
1414
<plugin>ros2_control_demo_example_5/ExternalRRBotForceTorqueSensorHardware</plugin>

0 commit comments

Comments
 (0)