Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.

Commit 8bdfcf1

Browse files
ahcordeKarsten1987
andauthored
Updated with ros2-control Foxy API (#44)
* Updated with ros2-control foxy API Signed-off-by: ahcorde <ahcorde@gmail.com> * Fixed dependency Signed-off-by: ahcorde <ahcorde@gmail.com> * make compile on osx (#46) Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com> * Fixed velocity example Signed-off-by: ahcorde <ahcorde@gmail.com> * make linters happy Signed-off-by: ahcorde <ahcorde@gmail.com> * updated Dockerfile Signed-off-by: ahcorde <ahcorde@gmail.com> * Added effort example Signed-off-by: ahcorde <ahcorde@gmail.com> * Instructions to run with moveit2 Signed-off-by: ahcorde <ahcorde@gmail.com> * updated readme Signed-off-by: ahcorde <ahcorde@gmail.com> * Added PIMPL pattern and other fixes Signed-off-by: ahcorde <ahcorde@gmail.com> * updated Dockerfile Signed-off-by: ahcorde <ahcorde@gmail.com> * changed log level Signed-off-by: ahcorde <ahcorde@gmail.com> * Fixed gazebo_period units Signed-off-by: ahcorde <ahcorde@gmail.com> * Updated CI Signed-off-by: ahcorde <ahcorde@gmail.com> * updated CI Signed-off-by: ahcorde <ahcorde@gmail.com> * updated CI Signed-off-by: ahcorde <ahcorde@gmail.com> * update CI Signed-off-by: ahcorde <ahcorde@gmail.com> * updated Dockerfile Signed-off-by: ahcorde <ahcorde@gmail.com> * Added feedback Signed-off-by: ahcorde <ahcorde@gmail.com> * make linters happy Signed-off-by: ahcorde <ahcorde@gmail.com> * Removed PID controllers Signed-off-by: ahcorde <ahcorde@gmail.com> * make linters happy Signed-off-by: ahcorde <ahcorde@gmail.com> * Removed transmission interface Signed-off-by: ahcorde <ahcorde@gmail.com> * Removed e-stop Signed-off-by: ahcorde <ahcorde@gmail.com> * make linters happy Signed-off-by: ahcorde <ahcorde@gmail.com> * clean code Signed-off-by: ahcorde <ahcorde@gmail.com> * Fix CI Signed-off-by: ahcorde <ahcorde@gmail.com> * Changed log level of a trace Signed-off-by: ahcorde <ahcorde@gmail.com> * Added rclcpp dependency to gazebo_hardware_plugin Signed-off-by: ahcorde <ahcorde@gmail.com> * Fixed bug in control method Signed-off-by: ahcorde <ahcorde@gmail.com> * Support more than one ros2_control tag Signed-off-by: ahcorde <ahcorde@gmail.com> * make linters happy Signed-off-by: ahcorde <ahcorde@gmail.com> * unify yaml files Signed-off-by: ahcorde <ahcorde@gmail.com> Co-authored-by: Karsten Knese <Karsten1987@users.noreply.github.com>
1 parent 3dfe04d commit 8bdfcf1

29 files changed

+863
-1310
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ jobs:
1818
cd ..
1919
mkdir -p /home/ros2_ws/src
2020
cp -r gazebo_ros2_control /home/ros2_ws/src/
21-
apt-get upgrade -q -y
21+
apt-get update && apt-get upgrade -q -y
2222
apt-get update && apt-get install -q -y --no-install-recommends \
2323
dirmngr \
2424
gnupg2 \
2525
lsb-release \
2626
python3-colcon-ros
27-
apt-get upgrade -y
2827
cd /home/ros2_ws/src/
29-
git clone https://github.com/ros-controls/ros2_control
30-
git clone https://github.com/ros-controls/ros2_controllers
3128
rosdep update
3229
rosdep install --from-paths ./ -i -y --rosdistro foxy \
3330
--ignore-src
@@ -36,7 +33,6 @@ jobs:
3633
run: |
3734
cd /home/ros2_ws/
3835
. /opt/ros/foxy/local_setup.sh
39-
export CMAKE_PREFIX_PATH=$AMENT_PREFIX_PATH:$CMAKE_PREFIX_PATH
4036
colcon build --packages-up-to gazebo_ros2_control_demos
4137
- name: Run tests
4238
id: test

Docker/Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ RUN apt-get update && apt-get install -q -y --no-install-recommends \
1515
RUN mkdir -p /home/ros2_ws/src \
1616
&& cd /home/ros2_ws/src/ \
1717
&& git clone https://github.com/ros-simulation/gazebo_ros2_control \
18-
&& git clone https://github.com/ros-controls/ros2_control \
19-
&& git clone https://github.com/ros-controls/ros2_controllers \
2018
&& rosdep update \
2119
&& rosdep install --from-paths ./ -i -y --rosdistro foxy \
2220
--ignore-src
2321

2422
RUN cd /home/ros2_ws/ \
2523
&& . /opt/ros/foxy/setup.sh \
26-
&& export CMAKE_PREFIX_PATH=$AMENT_PREFIX_PATH:$CMAKE_PREFIX_PATH \
27-
&& colcon build
24+
&& colcon build --merge-install
2825

2926
COPY entrypoint.sh /entrypoint.sh
3027
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 48 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# gazebo_ros2_control
22

3-
43
This is a ROS 2 package for integrating the `ros2_control` controller architecture with the [Gazebo](http://gazebosim.org/) simulator.
54

65
This package provides a Gazebo plugin which instantiates a `ros2_control` controller manager and connects it to a Gazebo model.
@@ -13,7 +12,7 @@ It is running Gazebo and some other ROS 2 nodes.
1312

1413
## Video + Pictures
1514

16-
![](img/gazebo_ros2_control_position_pid.gif)
15+
![](img/gazebo_ros2_control_position.gif)
1716

1817
## Running
1918

@@ -61,47 +60,59 @@ ros2 run gazebo_ros2_control_demos example_position
6160
```
6261

6362

64-
## Add transmission elements to a URDF
63+
## Add ros2_control tag to a URDF
6564

66-
To use `ros2_control` with your robot, you need to add some additional elements to your URDF. The `<transmission>` element is used to link actuators to joints, see the `<transmission>` spec for exact XML format.
65+
To use `ros2_control` with your robot, you need to add some additional elements to your URDF.
66+
You should include the tag `<ros2_control>` to access and control the robot interfaces. We should
67+
include
6768

68-
For the purposes of `gazebo_ros2_control` in its current implementation, the only important information in these transmission tags are:
69+
- a specific `<plugin>` for our robot
70+
- `<joint>` tag including the robot controllers: commands and states.
6971

70-
- `<joint name="">` the name must correspond to a joint else where in your URDF
71-
- `<type>` the type of transmission. Currently only `transmission_interface/SimpleTransmission` is implemented.
72-
- `<hardwareInterface>` within the `<actuator>` and `<joint>` tags, this tells the `gazebo_ros2_control` plugin what hardware interface to load (position, velocity or effort interfaces).
72+
```xml
73+
<ros2_control name="GazeboSystem" type="system">
74+
<hardware>
75+
<plugin>gazebo_ros2_control/GazeboSystem</plugin>
76+
</hardware>
77+
<joint name="slider_to_cart">
78+
<command_interface name="effort">
79+
<param name="min">-1000</param>
80+
<param name="max">1000</param>
81+
</command_interface>
82+
<state_interface name="position"/>
83+
<state_interface name="velocity"/>
84+
<state_interface name="effort"/>
85+
</joint>
86+
</ros2_control>
87+
```
7388

7489
## Add the gazebo_ros2_control plugin
7590

76-
In addition to the transmission tags, a Gazebo plugin needs to be added to your URDF that
77-
actually parses the transmission tags and loads the appropriate hardware interfaces and
91+
In addition to the `ros2_control` tags, a Gazebo plugin needs to be added to your URDF that
92+
actually parses the `ros2_control` tags and loads the appropriate hardware interfaces and
7893
controller manager. By default the `gazebo_ros2_control` plugin is very simple, though it is also
7994
extensible via an additional plugin architecture to allow power users to create their own custom
8095
robot hardware interfaces between `ros2_control` and Gazebo.
8196

8297
```xml
8398
<gazebo>
8499
<plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control">
85-
<robot_sim_type>gazebo_ros2_control/DefaultRobotHWSim</robot_sim_type>
86100
<robot_param>robot_description</robot_param>
87101
<robot_param_node>robot_state_publisher</robot_param_node>
88102
<parameters>$(find gazebo_ros2_control_demos)/config/cartpole_controller.yaml</parameters>
89-
<e_stop_topic>False</e_stop_topic>
90103
</plugin>
91104
</gazebo>
92105
```
93106

94107
The `gazebo_ros2_control` `<plugin>` tag also has the following optional child elements:
95108

96-
- `<control_period>`: The period of the controller update (in seconds), defaults to Gazebo's period
97109
- `<robot_param>`: The location of the `robot_description` (URDF) on the parameter server, defaults to `robot_description`
98110
- `<robot_param_node>`: Name of the node where the `robot_param` is located, defauls to `robot_state_publisher`
99-
- `<robot_sim_type>`: The pluginlib name of a custom robot sim interface to be used, defaults to `gazebo_ros2_control/DefaultRobotHWSim`
100111
- `<parameters>`: YAML file with the configuration of the controllers
101112

102113
#### Default gazebo_ros2_control Behavior
103114

104-
By default, without a `<robot_sim_type>` tag, `gazebo_ros2_control` will attempt to get all of the information it needs to interface with a ros2_control-based controller out of the URDF. This is sufficient for most cases, and good for at least getting started.
115+
By default, without a `<plugin>` tag, `gazebo_ros2_control` will attempt to get all of the information it needs to interface with a ros2_control-based controller out of the URDF. This is sufficient for most cases, and good for at least getting started.
105116

106117
The default behavior provides the following ros2_control interfaces:
107118

@@ -113,14 +124,21 @@ The default behavior provides the following ros2_control interfaces:
113124

114125
The `gazebo_ros2_control` Gazebo plugin also provides a pluginlib-based interface to implement custom interfaces between Gazebo and `ros2_control` for simulating more complex mechanisms (nonlinear springs, linkages, etc).
115126

116-
These plugins must inherit `gazebo_ros2_control::RobotHWSim` which implements a simulated `ros2_control` `hardware_interface::RobotHW`. RobotHWSim provides API-level access to read and command joint properties in the Gazebo simulator.
117-
118-
The respective RobotHWSim sub-class is specified in a URDF model and is loaded when the robot model is loaded. For example, the following XML will load the default plugin (same behavior as when using no `<robot_sim_type>` tag):
127+
These plugins must inherit `gazebo_ros2_control::GazeboSystemInterface` which implements a simulated `ros2_control`
128+
`hardware_interface::SystemInterface`. SystemInterface provides API-level access to read and command joint properties.
119129

130+
The respective GazeboSystemInterface sub-class is specified in a URDF model and is loaded when the
131+
robot model is loaded. For example, the following XML will load the default plugin:
120132
```xml
133+
<ros2_control name="GazeboSystem" type="system">
134+
<hardware>
135+
<plugin>gazebo_ros2_control/GazeboSystem</plugin>
136+
</hardware>
137+
...
138+
<ros2_control>
121139
<gazebo>
122140
<plugin name="gazebo_ros2_control" filename="libgazebo_ros2_control.so">
123-
<robot_sim_type>gazebo_ros2_control/DefaultRobotHWSim</robot_sim_type>
141+
...
124142
</plugin>
125143
</gazebo>
126144
```
@@ -138,13 +156,13 @@ Use the tag `<parameters>` inside `<plugin>` to set the YAML file with the contr
138156
```
139157

140158
This controller publishes the state of all resources registered to a
141-
`hardware_interface::JointStateInterface` to a topic of type `sensor_msgs/msg/JointState`. The following is a basic configuration of the controller.
159+
`hardware_interface::StateInterface` to a topic of type `sensor_msgs/msg/JointState`.
160+
The following is a basic configuration of the controller.
142161

143162
```yaml
144163
joint_state_controller:
145164
ros__parameters:
146165
type: joint_state_controller/JointStateController
147-
publish_rate: 50
148166
```
149167
150168
This controller creates an action called `/cart_pole_controller/follow_joint_trajectory` of type `control_msgs::action::FollowJointTrajectory`.
@@ -157,37 +175,7 @@ cart_pole_controller:
157175
- slider_to_cart
158176
write_op_modes:
159177
- slider_to_cart
160-
state_publish_rate: 25
161-
action_monitor_rate: 20
162-
constraints:
163-
stopped_velocity_tolerance: 0.05
164-
goal_time: 5
165-
```
166-
167-
#### Setting PID gains
168-
169-
To set the PID gains for a specific joint you need to define them inside `<plugin><ros></plugin></ros>`. Using the generic way of defining parameters with `gazebo_ros`. The name of the parameter correspond the name of the joint followed by a dot and the name of the parameter: `p`, `i`, `d`, `i_clamp_max`, `i_clamp_min` and `antiwindup`.
170-
171-
```xml
172-
<gazebo>
173-
<plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control">
174-
<ros>
175-
<namespace>/my_robot</namespace>
176-
<parameter name="slider_to_cart.p" type="double">50.0</parameter>
177-
<parameter name="slider_to_cart.i" type="double">10.0</parameter>
178-
<parameter name="slider_to_cart.d" type="double">15.0</parameter>
179-
<parameter name="slider_to_cart.i_clamp_max" type="double">3.0</parameter>
180-
<parameter name="slider_to_cart.i_clamp_min" type="double">-3.0</parameter>
181-
<parameter name="slider_to_cart.antiwindup" type="bool">false</parameter>
182-
<remapping>e_stop_topic:=emergency_stop</remapping>
183-
</ros>
184-
<robot_sim_type>gazebo_ros2_control/DefaultRobotHWSim</robot_sim_type>
185-
<parameters>$(find gazebo_ros2_control_demos)/config/cartpole_controller.yaml</parameters>
186-
...
187-
</plugins>
188-
</gazebo>
189178
```
190-
191179
#### Executing the examples
192180

193181
There are some examples in the `gazebo_ros2_control_demos` package. These examples allow to launch a cart in a 30 meter rail.
@@ -197,9 +185,9 @@ There are some examples in the `gazebo_ros2_control_demos` package. These exampl
197185
You can run some of the configuration running the following commands:
198186

199187
```bash
200-
ros2 launch gazebo_ros2_control_demos cart_example_position_pid.launch.py
201188
ros2 launch gazebo_ros2_control_demos cart_example_position.launch.py
202189
ros2 launch gazebo_ros2_control_demos cart_example_velocity.launch.py
190+
ros2 launch gazebo_ros2_control_demos cart_example_effort.launch.py
203191
```
204192

205193
Send example commands:
@@ -209,30 +197,18 @@ When the Gazebo world is launched you can run some of the following commads to m
209197
```bash
210198
ros2 run gazebo_ros2_control_demos example_position
211199
ros2 run gazebo_ros2_control_demos example_velocity
200+
ros2 run gazebo_ros2_control_demos example_effort
212201
```
213202

214-
To get or modify the values of the PID controller you can run the following commands:
203+
#### Gazebo + Moveit2 + ROS 2
215204

216-
```bash
217-
ros2 param get /gazebo_ros2_control slider_to_cart.p
218-
ros2 param get /gazebo_ros2_control slider_to_cart.i
219-
ros2 param get /gazebo_ros2_control slider_to_cart.d
220-
ros2 param get /gazebo_ros2_control slider_to_cart.i_clamp_max
221-
ros2 param get /gazebo_ros2_control slider_to_cart.i_clamp_min
222-
```
205+
This example works with [ROS 2 Foxy](https://index.ros.org/doc/ros2/Installation/Foxy/).
206+
You should install Moveit2 from sources, the instructions are available in this [link](https://moveit.ros.org/install-moveit2/source/).
207+
208+
The repository with all the required packages are in the [gazebo_ros_demos](https://github.com/ros-simulation/gazebo_ros_demos/tree/ahcorde/port/ros2).
223209

224210
```bash
225-
ros2 param set /gazebo_ros2_control slider_to_cart.p 50.0
226-
ros2 param set /gazebo_ros2_control slider_to_cart.i 10.0
227-
ros2 param set /gazebo_ros2_control slider_to_cart.d 15.0
228-
ros2 param set /gazebo_ros2_control slider_to_cart.i_clamp_max 3.0
229-
ros2 param set /gazebo_ros2_control slider_to_cart.i_clamp_min -3.0
211+
ros2 launch rrbot_moveit_demo_nodes rrbot_demo.launch.py
230212
```
231213

232-
# NOTES
233-
234-
`ros2_control` and `ros2_controllers` are in a redesign phase. Some of the packages are unofficial.
235-
In the following links you can track some of the missing features.
236-
237-
- https://github.com/ros-controls/ros2_control/issues/26
238-
- https://github.com/ros-controls/ros2_control/issues/32
214+
![](img/moveit2.gif)

gazebo_ros2_control/CMakeLists.txt

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,69 @@ project(gazebo_ros2_control)
33

44
find_package(ament_cmake REQUIRED)
55
find_package(angles REQUIRED)
6-
find_package(control_toolbox REQUIRED)
76
find_package(controller_manager REQUIRED)
87
find_package(gazebo_dev REQUIRED)
98
find_package(gazebo_ros REQUIRED)
109
find_package(hardware_interface REQUIRED)
11-
find_package(joint_limits_interface REQUIRED)
1210
find_package(pluginlib REQUIRED)
1311
find_package(rclcpp REQUIRED)
14-
find_package(transmission_interface REQUIRED)
1512
find_package(urdf REQUIRED)
1613
find_package(yaml_cpp_vendor REQUIRED)
1714

1815
# Default to C++14
1916
if(NOT CMAKE_CXX_STANDARD)
2017
set(CMAKE_CXX_STANDARD 14)
2118
endif()
19+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
20+
add_compile_options(-Wall -Wextra -Wconversion -Wno-sign-conversion -Wpedantic -Wnon-virtual-dtor -Woverloaded-virtual)
21+
endif()
2222

2323
include_directories(include)
24+
link_directories(
25+
${gazebo_dev_LIBRARY_DIRS}
26+
)
2427

2528
# Libraries
26-
add_library(${PROJECT_NAME} SHARED src/gazebo_ros2_control_plugin.cpp)
29+
add_library(${PROJECT_NAME} SHARED
30+
src/gazebo_ros2_control_plugin.cpp
31+
)
2732
ament_target_dependencies(${PROJECT_NAME}
33+
angles
2834
controller_manager
2935
gazebo_dev
3036
gazebo_ros
3137
hardware_interface
3238
pluginlib
3339
rclcpp
34-
transmission_interface
3540
urdf
3641
yaml_cpp_vendor
3742
)
3843

39-
add_library(default_robot_hw_sim SHARED src/default_robot_hw_sim.cpp)
40-
ament_target_dependencies(default_robot_hw_sim
44+
add_library(gazebo_hardware_plugins SHARED
45+
src/gazebo_system.cpp
46+
)
47+
ament_target_dependencies(gazebo_hardware_plugins
4148
angles
42-
control_toolbox
4349
gazebo_dev
4450
hardware_interface
45-
joint_limits_interface
4651
rclcpp
47-
transmission_interface
4852
)
4953

5054
## Install
51-
install(TARGETS default_robot_hw_sim ${PROJECT_NAME}
55+
install(TARGETS
56+
${PROJECT_NAME}
57+
gazebo_hardware_plugins
5258
ARCHIVE DESTINATION lib
5359
LIBRARY DESTINATION lib
5460
RUNTIME DESTINATION bin
5561
)
5662

5763
ament_export_dependencies(ament_cmake)
5864
ament_export_dependencies(rclcpp)
59-
ament_export_libraries(${PROJECT_NAME} default_robot_hw_sim)
65+
ament_export_libraries(
66+
${PROJECT_NAME}
67+
gazebo_hardware_plugins
68+
)
6069

6170
if(BUILD_TESTING)
6271
find_package(ament_cmake_gtest REQUIRED)
@@ -68,6 +77,6 @@ install(DIRECTORY include/${PROJECT_NAME}/
6877
DESTINATION include/${PROJECT_NAME}
6978
)
7079

71-
pluginlib_export_plugin_description_file(gazebo_ros2_control robot_hw_sim_plugins.xml)
80+
pluginlib_export_plugin_description_file(gazebo_ros2_control gazebo_hardware_plugins.xml)
7281

7382
ament_package()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<library path="gazebo_hardware_plugins">
2+
<class
3+
name="gazebo_ros2_control/GazeboSystem"
4+
type="gazebo_ros2_control::GazeboSystem"
5+
base_class_type="gazebo_ros2_control::GazeboSystemInterface">
6+
<description>
7+
GazeboPositionJoint
8+
</description>
9+
</class>
10+
</library>

0 commit comments

Comments
 (0)