Skip to content

Commit 76f703e

Browse files
[Example 2] Moving and Restructuring (#233)
Co-authored-by: Dr. Denis <[email protected]>
1 parent 31bc4bc commit 76f703e

File tree

19 files changed

+658
-118
lines changed

19 files changed

+658
-118
lines changed

README.md

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ Check README file inside each example folder for detailed description.
6969

7070
##### Example 2
7171

72-
....
72+
*DiffBot*, or ''Differential Mobile Robot'', is a simple mobile base with differential drive.
73+
The robot is basically a box moving according to differential drive kinematics.
7374

7475

7576
## Quick Hints
@@ -144,89 +145,6 @@ This repository provides the following simple example robots: a 2 degrees of fre
144145
The first two examples demonstrate the minimal setup for those two robots to run.
145146
Later examples show more details about `ros2_control`-concepts and some more advanced use-cases.
146147

147-
148-
## *DiffBot*
149-
150-
*DiffBot*, or ''Differential Mobile Robot'', is a simple mobile base with differential drive.
151-
The robot is basically a box moving according to differential drive kinematics.
152-
The *DiffBot* URDF files can be found in `urdf` folder of `diffbot_description` package.
153-
154-
1. To check that *DiffBot* description is working properly use following launch commands:
155-
```
156-
ros2 launch diffbot_description view_robot.launch.py
157-
```
158-
**NOTE**: Getting the following output in terminal is OK: `Warning: Invalid frame ID "odom" passed to canTransform argument target_frame - frame does not exist`.
159-
This happens because `joint_state_publisher_gui` node need some time to start.
160-
161-
1. To start *DiffBot* example open a terminal, source your ROS2-workspace and execute its launch file with:
162-
```
163-
ros2 launch ros2_control_demo_bringup diffbot.launch.py
164-
```
165-
The launch file loads and starts the robot hardware, controllers and opens `RViz`.
166-
In the starting terminal you will see a lot of output from the hardware implementation showing its internal states.
167-
This excessive printing is only added for demonstration. In general, printing to the terminal should be avoided as much as possible in a hardware interface implementation.
168-
169-
If you can see an orange box in `RViz` everything has started properly.
170-
Still, to be sure, let's introspect the control system before moving *DiffBot*.
171-
172-
1. Check if the hardware interface loaded properly, by opening another terminal and executing:
173-
```
174-
ros2 control list_hardware_interfaces
175-
```
176-
You should get:
177-
```
178-
command interfaces
179-
left_wheel_joint/velocity [claimed]
180-
right_wheel_joint/velocity [claimed]
181-
state interfaces
182-
left_wheel_joint/position
183-
left_wheel_joint/velocity
184-
right_wheel_joint/position
185-
right_wheel_joint/velocity
186-
```
187-
The `[claimed]` marker on command interfaces means that a controller has access to command *DiffBot*.
188-
189-
1. Check if controllers are running:
190-
```
191-
ros2 control list_controllers
192-
```
193-
You should get:
194-
```
195-
diffbot_base_controller[diff_drive_controller/DiffDriveController] active
196-
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
197-
```
198-
199-
1. If everything is fine, now you can send a command to *Diff Drive Controller* using ros2 cli interface:
200-
```
201-
ros2 topic pub --rate 30 /diffbot_base_controller/cmd_vel_unstamped geometry_msgs/msg/Twist "linear:
202-
x: 0.7
203-
y: 0.0
204-
z: 0.0
205-
angular:
206-
x: 0.0
207-
y: 0.0
208-
z: 1.0"
209-
```
210-
You should now see an orange box circling in `RViz`.
211-
Also, you should see changing states in the terminal where launch file is started.
212-
213-
214-
Files used for this demos:
215-
- Launch file: [diffbot.launch.py](ros2_control_demo_bringup/launch/diffbot.launch.py)
216-
- Controllers yaml: [diffbot_controllers.yaml](ros2_control_demo_bringup/config/diffbot_controllers.yaml)
217-
- URDF file: [diffbot.urdf.xacro](ros2_control_demo_description/diffbot_description/urdf/diffbot.urdf.xacro)
218-
- Description: [diffbot_description.urdf.xacro](ros2_control_demo_description/diffbot_description/urdf/diffbot_description.urdf.xacro)
219-
- `ros2_control` tag: [diffbot.ros2_control.xacro](ros2_control_demo_description/diffbot_description/ros2_control/diffbot.ros2_control.xacro)
220-
- RViz configuration: [diffbot.rviz](ros2_control_demo_description/diffbot_description/config/diffbot.rviz)
221-
222-
- Hardware interface plugin: [diffbot_system.cpp](ros2_control_demo_hardware/src/diffbot_system.cpp)
223-
224-
225-
Controllers from this demo:
226-
- `Joint State Broadcaster` ([`ros2_controllers` repository](https://github.com/ros-controls/ros2_controllers)): [doc](https://ros-controls.github.io/control.ros.org/ros2_controllers/joint_state_broadcaster/doc/userdoc.html)
227-
- `Diff Drive Controller` ([`ros2_controllers` repository](https://github.com/ros-controls/ros2_controllers)): [doc](https://ros-controls.github.io/control.ros.org/ros2_controllers/diff_drive_controller/doc/userdoc.html)
228-
229-
230148
# Examples of ros2_control concepts
231149

232150
Each of the described example cases from the [roadmap](https://github.com/ros-controls/roadmap/blob/master/design_drafts/components_architecture_and_urdf_examples.md) has its own launch and URDF file.

example_2/CMakeLists.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(ros2_control_demo_example_2)
3+
4+
# Default to C++14
5+
if(NOT CMAKE_CXX_STANDARD)
6+
set(CMAKE_CXX_STANDARD 14)
7+
endif()
8+
9+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
10+
add_compile_options(-Wall -Wextra)
11+
endif()
12+
13+
# find dependencies
14+
set(THIS_PACKAGE_INCLUDE_DEPENDS
15+
hardware_interface
16+
pluginlib
17+
rclcpp
18+
rclcpp_lifecycle
19+
)
20+
21+
# find dependencies
22+
find_package(ament_cmake REQUIRED)
23+
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
24+
find_package(${Dependency} REQUIRED)
25+
endforeach()
26+
27+
28+
## COMPILE
29+
add_library(
30+
${PROJECT_NAME}
31+
SHARED
32+
hardware/diffbot_system.cpp
33+
)
34+
target_include_directories(
35+
${PROJECT_NAME}
36+
PRIVATE
37+
hardware/include
38+
)
39+
ament_target_dependencies(
40+
${PROJECT_NAME}
41+
${THIS_PACKAGE_INCLUDE_DEPENDS}
42+
)
43+
44+
# Causes the visibility macros to use dllexport rather than dllimport,
45+
# which is appropriate when building the dll but not consuming it.
46+
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROS2_CONTROL_DEMO_EXAMPLE_2_BUILDING_DLL")
47+
48+
# Export hardware plugins
49+
pluginlib_export_plugin_description_file(hardware_interface ros2_control_demo_example_2.xml)
50+
51+
# INSTALL
52+
install(
53+
TARGETS ${PROJECT_NAME}
54+
DESTINATION lib
55+
)
56+
install(
57+
DIRECTORY hardware/include/
58+
DESTINATION include
59+
)
60+
install(
61+
DIRECTORY description/launch description/ros2_control description/urdf description/rviz
62+
DESTINATION share/${PROJECT_NAME}
63+
)
64+
install(
65+
DIRECTORY bringup/launch bringup/config
66+
DESTINATION share/${PROJECT_NAME}
67+
)
68+
69+
if(BUILD_TESTING)
70+
find_package(ament_cmake_gtest REQUIRED)
71+
endif()
72+
73+
## EXPORTS
74+
ament_export_include_directories(
75+
include
76+
)
77+
ament_export_libraries(
78+
${PROJECT_NAME}
79+
)
80+
ament_export_dependencies(
81+
${THIS_PACKAGE_INCLUDE_DEPENDS}
82+
)
83+
ament_package()

example_2/README.rst

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
*********
2+
DiffBot
3+
*********
4+
5+
*DiffBot*, or ''Differential Mobile Robot'', is a simple mobile base with differential drive.
6+
The robot is basically a box moving according to differential drive kinematics.
7+
The *DiffBot* URDF files can be found in ``description/urdf`` folder.
8+
9+
1. To check that *DiffBot* description is working properly use following launch commands
10+
11+
.. code-block:: shell
12+
13+
ros2 launch ros2_control_demo_example_2 view_robot.launch.py
14+
15+
.. warning::
16+
Getting the following output in terminal is OK: ``Warning: Invalid frame ID "odom" passed to canTransform argument target_frame - frame does not exist``.
17+
This happens because ``joint_state_publisher_gui`` node need some time to start.
18+
19+
.. image:: doc/diffbot.png
20+
:width: 400
21+
:alt: Differential Mobile Robot
22+
23+
2. To start *DiffBot* example open a terminal, source your ROS2-workspace and execute its launch file with
24+
25+
.. code-block:: shell
26+
27+
ros2 launch ros2_control_demo_example_2 diffbot.launch.py
28+
29+
The launch file loads and starts the robot hardware, controllers and opens *RViz*.
30+
In the starting terminal you will see a lot of output from the hardware implementation showing its internal states.
31+
This excessive printing is only added for demonstration. In general, printing to the terminal should be avoided as much as possible in a hardware interface implementation.
32+
33+
If you can see an orange box in *RViz* everything has started properly.
34+
Still, to be sure, let's introspect the control system before moving *DiffBot*.
35+
36+
3. Check if the hardware interface loaded properly, by opening another terminal and executing
37+
38+
.. code-block:: shell
39+
40+
ros2 control list_hardware_interfaces
41+
42+
You should get
43+
44+
.. code-block:: shell
45+
46+
command interfaces
47+
left_wheel_joint/velocity [claimed]
48+
right_wheel_joint/velocity [claimed]
49+
state interfaces
50+
left_wheel_joint/position
51+
left_wheel_joint/velocity
52+
right_wheel_joint/position
53+
right_wheel_joint/velocity
54+
55+
The ``[claimed]`` marker on command interfaces means that a controller has access to command *DiffBot*.
56+
57+
4. Check if controllers are running
58+
59+
.. code-block:: shell
60+
61+
ros2 control list_controllers
62+
63+
You should get
64+
65+
.. code-block:: shell
66+
67+
diffbot_base_controller[diff_drive_controller/DiffDriveController] active
68+
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
69+
70+
5. If everything is fine, now you can send a command to *Diff Drive Controller* using ros2 cli interface:
71+
72+
.. code-block:: shell
73+
74+
ros2 topic pub --rate 30 /diffbot_base_controller/cmd_vel_unstamped geometry_msgs/msg/Twist "linear:
75+
x: 0.7
76+
y: 0.0
77+
z: 0.0
78+
angular:
79+
x: 0.0
80+
y: 0.0
81+
z: 1.0"
82+
83+
You should now see an orange box circling in *RViz*.
84+
Also, you should see changing states in the terminal where launch file is started.
85+
86+
.. code-block:: shell
87+
88+
[DiffBotSystemHardware]: Got command 43.33333 for 'left_wheel_joint'!
89+
[DiffBotSystemHardware]: Got command 50.00000 for 'right_wheel_joint'!
90+
91+
Files used for this demos
92+
#########################
93+
94+
- Launch file: `diffbot.launch.py <bringup/launch/diffbot.launch.py>`__
95+
- Controllers yaml: `diffbot_controllers.yaml <bringup/config/diffbot_controllers.yaml>`__
96+
- URDF file: `diffbot.urdf.xacro <description/urdf/diffbot.urdf.xacro>`__
97+
98+
+ Description: `diffbot_description.urdf.xacro <description/urdf/diffbot_description.urdf.xacro>`__
99+
+ ``ros2_control`` tag: `diffbot.ros2_control.xacro <description/ros2_control/diffbot.ros2_control.xacro>`__
100+
101+
- RViz configuration: `diffbot.rviz <description/rviz/diffbot.rviz>`__
102+
103+
- Hardware interface plugin: `diffbot_system.cpp <hardware/diffbot_system.cpp>`__
104+
105+
106+
Controllers from this demo
107+
##########################
108+
109+
- ``Joint State Broadcaster`` (`*ros2_controllers* repository <https://github.com/ros-controls/ros2_controllers>`__): `doc <https://control.ros.org/master/doc/ros2_controllers/joint_state_broadcaster/doc/userdoc.html>`__
110+
- ``Diff Drive Controller`` (`*ros2_controllers* repository <https://github.com/ros-controls/ros2_controllers>`__): `doc <https://control.ros.org/master/doc/ros2_controllers/diff_drive_controller/doc/userdoc.html>`__

ros2_control_demo_bringup/launch/diffbot.launch.py renamed to example_2/bringup/launch/diffbot.launch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ def generate_launch_description():
2828
PathJoinSubstitution([FindExecutable(name="xacro")]),
2929
" ",
3030
PathJoinSubstitution(
31-
[FindPackageShare("diffbot_description"), "urdf", "diffbot.urdf.xacro"]
31+
[FindPackageShare("ros2_control_demo_example_2"), "urdf", "diffbot.urdf.xacro"]
3232
),
3333
]
3434
)
3535
robot_description = {"robot_description": robot_description_content}
3636

3737
robot_controllers = PathJoinSubstitution(
3838
[
39-
FindPackageShare("ros2_control_demo_bringup"),
39+
FindPackageShare("ros2_control_demo_example_2"),
4040
"config",
4141
"diffbot_controllers.yaml",
4242
]
4343
)
4444
rviz_config_file = PathJoinSubstitution(
45-
[FindPackageShare("diffbot_description"), "config", "diffbot.rviz"]
45+
[FindPackageShare("ros2_control_demo_example_2"), "rviz", "diffbot.rviz"]
4646
)
4747

4848
control_node = Node(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def generate_launch_description():
2626
declared_arguments.append(
2727
DeclareLaunchArgument(
2828
"description_package",
29-
default_value="diffbot_description",
29+
default_value="ros2_control_demo_example_2",
3030
description="Description package with robot URDF/xacro files. Usually the argument \
3131
is not set, it enables use of a custom description.",
3232
)
@@ -69,7 +69,7 @@ def generate_launch_description():
6969
robot_description = {"robot_description": robot_description_content}
7070

7171
rviz_config_file = PathJoinSubstitution(
72-
[FindPackageShare(description_package), "config", "diffbot_view.rviz"]
72+
[FindPackageShare(description_package), "rviz", "diffbot_view.rviz"]
7373
)
7474

7575
joint_state_publisher_node = Node(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<ros2_control name="${name}" type="system">
77
<hardware>
8-
<plugin>ros2_control_demo_hardware/DiffBotSystemHardware</plugin>
8+
<plugin>ros2_control_demo_example_2/DiffBotSystemHardware</plugin>
99
<param name="example_param_hw_start_duration_sec">0</param>
1010
<param name="example_param_hw_stop_duration_sec">3.0</param>
1111
</hardware>

0 commit comments

Comments
 (0)