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

Commit c94af39

Browse files
committed
Updated with ros2-control foxy API
Signed-off-by: ahcorde <[email protected]>
1 parent 3dfe04d commit c94af39

16 files changed

+759
-1099
lines changed

README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ ros2 run gazebo_ros2_control_demos example_position
6363

6464
## Add transmission elements to a URDF
6565

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.
66+
To use `ros2_control` with your robot, you need to add some additional elements to your URDF.
67+
The `<transmission>` element is used to link actuators to joints, see the `<transmission>` spec for exact XML format.
6768

68-
For the purposes of `gazebo_ros2_control` in its current implementation, the only important information in these transmission tags are:
69+
For the purposes of `gazebo_ros2_control` in its current implementation, the only important information
70+
in these transmission tags are:
6971

7072
- `<joint name="">` the name must correspond to a joint else where in your URDF
7173
- `<type>` the type of transmission. Currently only `transmission_interface/SimpleTransmission` is implemented.
@@ -82,11 +84,12 @@ robot hardware interfaces between `ros2_control` and Gazebo.
8284
```xml
8385
<gazebo>
8486
<plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control">
85-
<robot_sim_type>gazebo_ros2_control/DefaultRobotHWSim</robot_sim_type>
87+
<robot_sim_type>gazebo_ros2_control/GazeboSystem</robot_sim_type>
8688
<robot_param>robot_description</robot_param>
8789
<robot_param_node>robot_state_publisher</robot_param_node>
8890
<parameters>$(find gazebo_ros2_control_demos)/config/cartpole_controller.yaml</parameters>
8991
<e_stop_topic>False</e_stop_topic>
92+
<control_period>0.01</control_period>
9093
</plugin>
9194
</gazebo>
9295
```
@@ -96,8 +99,9 @@ The `gazebo_ros2_control` `<plugin>` tag also has the following optional child e
9699
- `<control_period>`: The period of the controller update (in seconds), defaults to Gazebo's period
97100
- `<robot_param>`: The location of the `robot_description` (URDF) on the parameter server, defaults to `robot_description`
98101
- `<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`
102+
- `<robot_sim_type>`: The pluginlib name of a custom robot sim interface to be used, defaults to `gazebo_ros2_control/GazeboSystem`
100103
- `<parameters>`: YAML file with the configuration of the controllers
104+
- `<e_stop_topic>`: Topic to publish the emergency stop
101105

102106
#### Default gazebo_ros2_control Behavior
103107

@@ -113,14 +117,17 @@ The default behavior provides the following ros2_control interfaces:
113117

114118
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).
115119

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.
120+
These plugins must inherit `gazebo_ros2_control::GazeboSystemInterface` which implements a simulated `ros2_control`
121+
`hardware_interface::SystemInterface`. SystemInterface provides API-level access to read and command joint properties.
117122

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):
123+
The respective GazeboSystemInterface sub-class is specified in a URDF model and is loaded when the
124+
robot model is loaded. For example, the following XML will load the default plugin
125+
(same behavior as when using no `<robot_sim_type>` tag):
119126

120127
```xml
121128
<gazebo>
122129
<plugin name="gazebo_ros2_control" filename="libgazebo_ros2_control.so">
123-
<robot_sim_type>gazebo_ros2_control/DefaultRobotHWSim</robot_sim_type>
130+
<robot_sim_type>gazebo_ros2_control/GazeboSystem</robot_sim_type>
124131
</plugin>
125132
</gazebo>
126133
```
@@ -138,13 +145,13 @@ Use the tag `<parameters>` inside `<plugin>` to set the YAML file with the contr
138145
```
139146

140147
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.
148+
`hardware_interface::StateInterface` to a topic of type `sensor_msgs/msg/JointState`.
149+
The following is a basic configuration of the controller.
142150

143151
```yaml
144152
joint_state_controller:
145153
ros__parameters:
146154
type: joint_state_controller/JointStateController
147-
publish_rate: 50
148155
```
149156
150157
This controller creates an action called `/cart_pole_controller/follow_joint_trajectory` of type `control_msgs::action::FollowJointTrajectory`.
@@ -166,7 +173,9 @@ cart_pole_controller:
166173

167174
#### Setting PID gains
168175

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`.
176+
To set the PID gains for a specific joint you need to define them inside `<plugin><ros></plugin></ros>`.
177+
Using the generic way of defining parameters with `gazebo_ros`. The name of the parameter correspond to
178+
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`.
170179

171180
```xml
172181
<gazebo>
@@ -181,7 +190,7 @@ To set the PID gains for a specific joint you need to define them inside `<plugi
181190
<parameter name="slider_to_cart.antiwindup" type="bool">false</parameter>
182191
<remapping>e_stop_topic:=emergency_stop</remapping>
183192
</ros>
184-
<robot_sim_type>gazebo_ros2_control/DefaultRobotHWSim</robot_sim_type>
193+
<robot_sim_type>gazebo_ros2_control/GazeboSystem</robot_sim_type>
185194
<parameters>$(find gazebo_ros2_control_demos)/config/cartpole_controller.yaml</parameters>
186195
...
187196
</plugins>
@@ -228,11 +237,3 @@ ros2 param set /gazebo_ros2_control slider_to_cart.d 15.0
228237
ros2 param set /gazebo_ros2_control slider_to_cart.i_clamp_max 3.0
229238
ros2 param set /gazebo_ros2_control slider_to_cart.i_clamp_min -3.0
230239
```
231-
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

gazebo_ros2_control/CMakeLists.txt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ find_package(controller_manager REQUIRED)
88
find_package(gazebo_dev REQUIRED)
99
find_package(gazebo_ros REQUIRED)
1010
find_package(hardware_interface REQUIRED)
11-
find_package(joint_limits_interface REQUIRED)
1211
find_package(pluginlib REQUIRED)
1312
find_package(rclcpp REQUIRED)
1413
find_package(transmission_interface REQUIRED)
@@ -23,7 +22,9 @@ endif()
2322
include_directories(include)
2423

2524
# Libraries
26-
add_library(${PROJECT_NAME} SHARED src/gazebo_ros2_control_plugin.cpp)
25+
add_library(${PROJECT_NAME} SHARED
26+
src/gazebo_ros2_control_plugin.cpp
27+
)
2728
ament_target_dependencies(${PROJECT_NAME}
2829
controller_manager
2930
gazebo_dev
@@ -36,27 +37,31 @@ ament_target_dependencies(${PROJECT_NAME}
3637
yaml_cpp_vendor
3738
)
3839

39-
add_library(default_robot_hw_sim SHARED src/default_robot_hw_sim.cpp)
40-
ament_target_dependencies(default_robot_hw_sim
41-
angles
42-
control_toolbox
43-
gazebo_dev
40+
add_library(gazebo_hardware_plugins SHARED
41+
src/gazebo_system.cpp
42+
)
43+
ament_target_dependencies(gazebo_hardware_plugins
4444
hardware_interface
45-
joint_limits_interface
46-
rclcpp
47-
transmission_interface
45+
gazebo_dev
46+
control_toolbox
47+
angles
4848
)
4949

5050
## Install
51-
install(TARGETS default_robot_hw_sim ${PROJECT_NAME}
51+
install(TARGETS
52+
${PROJECT_NAME}
53+
gazebo_hardware_plugins
5254
ARCHIVE DESTINATION lib
5355
LIBRARY DESTINATION lib
5456
RUNTIME DESTINATION bin
5557
)
5658

5759
ament_export_dependencies(ament_cmake)
5860
ament_export_dependencies(rclcpp)
59-
ament_export_libraries(${PROJECT_NAME} default_robot_hw_sim)
61+
ament_export_libraries(
62+
${PROJECT_NAME}
63+
gazebo_hardware_plugins
64+
)
6065

6166
if(BUILD_TESTING)
6267
find_package(ament_cmake_gtest REQUIRED)
@@ -68,6 +73,6 @@ install(DIRECTORY include/${PROJECT_NAME}/
6873
DESTINATION include/${PROJECT_NAME}
6974
)
7075

71-
pluginlib_export_plugin_description_file(gazebo_ros2_control robot_hw_sim_plugins.xml)
76+
pluginlib_export_plugin_description_file(gazebo_ros2_control gazebo_hardware_plugins.xml)
7277

7378
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>

gazebo_ros2_control/include/gazebo_ros2_control/default_robot_hw_sim.hpp

Lines changed: 0 additions & 168 deletions
This file was deleted.

gazebo_ros2_control/include/gazebo_ros2_control/gazebo_ros2_control_plugin.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,16 @@
3939
#include <string>
4040
#include <vector>
4141

42-
// ROS
43-
#include "pluginlib/class_loader.hpp"
44-
#include "rclcpp/rclcpp.hpp"
45-
#include "std_msgs/msg/bool.hpp"
42+
#include "controller_manager/controller_manager.hpp"
4643

47-
// Gazebo
4844
#include "gazebo/common/common.hh"
49-
#include "gazebo/physics/physics.hh"
45+
#include "gazebo/physics/Model.hh"
46+
47+
#include "pluginlib/class_loader.hpp"
48+
49+
#include "rclcpp/rclcpp.hpp"
50+
#include "rclcpp_lifecycle/lifecycle_node.hpp"
5051

51-
// ros_control
52-
#include "controller_manager/controller_manager.hpp"
53-
#include "gazebo_ros2_control/robot_hw_sim.hpp"
5452
#include "transmission_interface/transmission_parser.hpp"
5553

5654
namespace gazebo_ros2_control

0 commit comments

Comments
 (0)