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

Commit 3dfe04d

Browse files
Updated with recent ros2_control changes (#34)
Signed-off-by: ahcorde <[email protected]> * removed plugin's parseTransmissionsFromURDF since it just calls a 1-liner and returns true always, thus not handling errors. plugin now calls transmission parser directly and catches error exception * moved declaration of parameters to precede joint PID constructor as the PID constructor's ParameterInterface will cause parameter events to fire (and occasionally cause a SEGV). Also added defaults to force floating type on parameter to fix log errors due to wrong parameter type * updated transmission info member names to sync with ros2_controls master * split initSim() joint loop to first register all joint handles, then handles are fetched, then a second loop continues joint limit and PID setup * uncrustify and cpplint fixes * fix for CI, disabled ddengster branch checkout and overwrite since master now contains TransmissionInfo * Clean up CI and Dockerfile Signed-off-by: ahcorde <[email protected]> * Fixed velocity controller example (#40) * removed plugin's parseTransmissionsFromURDF since it just calls a 1-liner and returns true always, thus not handling errors. plugin now calls transmission parser directly and catches error exception * moved declaration of parameters to precede joint PID constructor as the PID constructor's ParameterInterface will cause parameter events to fire (and occasionally cause a SEGV). Also added defaults to force floating type on parameter to fix log errors due to wrong parameter type * updated transmission info member names to sync with ros2_controls master * split initSim() joint loop to first register all joint handles, then handles are fetched, then a second loop continues joint limit and PID setup * uncrustify and cpplint fixes * fix for CI, disabled ddengster branch checkout and overwrite since master now contains TransmissionInfo * removed duplicate registering of opmode handle * fixed velocity example due to declare_parameter default values pushing velocity controller into PID mode Co-authored-by: Colin MacKenzie <[email protected]>
1 parent d4f6e70 commit 3dfe04d

File tree

10 files changed

+438
-574
lines changed

10 files changed

+438
-574
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ jobs:
2828
cd /home/ros2_ws/src/
2929
git clone https://github.com/ros-controls/ros2_control
3030
git clone https://github.com/ros-controls/ros2_controllers
31-
git clone https://github.com/ddengster/ros2_control/ -b coffeebot_deps ros2_control_ddengster
32-
git clone https://github.com/ros-controls/control_toolbox/ -b ros2-master
33-
touch ros2_control_ddengster/COLCON_IGNORE
34-
cp -r ros2_control_ddengster/joint_limits_interface ros2_control_ddengster/transmission_interface ros2_control
35-
sed -i '/rclcpp/d' ros2_control/joint_limits_interface/CMakeLists.txt
3631
rosdep update
3732
rosdep install --from-paths ./ -i -y --rosdistro foxy \
3833
--ignore-src

Docker/Dockerfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ RUN mkdir -p /home/ros2_ws/src \
1616
&& cd /home/ros2_ws/src/ \
1717
&& git clone https://github.com/ros-simulation/gazebo_ros2_control \
1818
&& git clone https://github.com/ros-controls/ros2_control \
19-
&& git clone https://github.com/ros-controls/control_toolbox -b ros2-master \
2019
&& git clone https://github.com/ros-controls/ros2_controllers \
21-
&& git clone https://github.com/ddengster/ros2_control/ -b coffeebot_deps ros2_control_ddengster \
22-
&& touch ros2_control_ddengster/COLCON_IGNORE \
23-
&& cp -r ros2_control_ddengster/joint_limits_interface ros2_control_ddengster/transmission_interface ros2_control \
24-
&& sed -i '/rclcpp/d' ros2_control/joint_limits_interface/CMakeLists.txt \
25-
&& sed -i '/rclcpp/d' ros2_control/joint_limits_interface/package.xml \
2620
&& rosdep update \
2721
&& rosdep install --from-paths ./ -i -y --rosdistro foxy \
2822
--ignore-src

gazebo_ros2_control/include/gazebo_ros2_control/default_robot_hw_sim.hpp

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,12 @@
3535
#define GAZEBO_ROS2_CONTROL__DEFAULT_ROBOT_HW_SIM_HPP_
3636

3737
#include <algorithm>
38+
#include <memory>
3839
#include <string>
3940
#include <vector>
4041

4142
// ros_control
4243
#include "control_toolbox/pid_ros.hpp"
43-
#if 0 // @todo
44-
#include <hardware_interface/joint_command_interface.hpp>
45-
#include <hardware_interface/robot_hw.hpp>
46-
#endif
4744

4845
#include "joint_limits_interface/joint_limits.hpp"
4946
#include "joint_limits_interface/joint_limits_interface.hpp"
@@ -59,12 +56,12 @@
5956
#include "pluginlib/class_list_macros.hpp"
6057
#include "rclcpp/rclcpp.hpp"
6158

62-
// gazebo_ros_control
63-
#include "gazebo_ros2_control/robot_hw_sim.hpp"
64-
6559
// URDF
6660
#include "urdf/model.h"
6761

62+
// gazebo_ros_control
63+
#include "gazebo_ros2_control/robot_hw_sim.hpp"
64+
6865
namespace gazebo_ros2_control
6966
{
7067

@@ -87,36 +84,32 @@ class DefaultRobotHWSim : public gazebo_ros2_control::RobotHWSim
8784
// Methods used to control a joint.
8885
enum ControlMethod {EFFORT, POSITION, POSITION_PID, VELOCITY, VELOCITY_PID};
8986

87+
private:
88+
rclcpp::Node::SharedPtr nh_;
89+
9090
protected:
91-
// Register the limits of the joint specified by joint_name and joint_handle. The limits are
92-
// retrieved from joint_limit_nh. If urdf_model is not NULL, limits are retrieved from it also.
93-
// Return the joint's type, lower position limit, upper position limit, and effort limit.
91+
/// \brief Register the limits of the joint specified by joint_name and joint_handle.
92+
/// The limits are retrieved from joint_limit_nh. If urdf_model is not NULL, limits
93+
/// are retrieved from it also. Return the joint's type, lower position limit, upper
94+
/// position limit, and effort limit.
9495
void registerJointLimits(
95-
const std::string & joint_name,
96-
const hardware_interface::JointStateHandle & joint_handle,
97-
const ControlMethod ctrl_method,
98-
const rclcpp::Node::SharedPtr & joint_limit_nh,
96+
size_t joint_nr,
9997
const urdf::Model * const urdf_model,
10098
int * const joint_type, double * const lower_limit,
10199
double * const upper_limit, double * const effort_limit,
102100
double * const vel_limit);
103101

104-
unsigned int n_dof_;
102+
/// \brief Refreshes all valid handle references in a collection.
103+
/// Requests from the RobotHardware updated handle references. This is required after
104+
/// any call to RobotHardware::register_joint() and before a handle is used or bound
105+
/// to a controller since the internal implementation of register_joint binds to doubles
106+
/// inside a std::vector and thus growth of that vector invalidates all existing
107+
/// iterators (i.e. handles).
108+
/// See https://github.com/ros-controls/ros2_control/issues/212
109+
/// If a handle in the collection is unset (no joint name or interface name) then it is skipped.
110+
void bindJointHandles(std::vector<hardware_interface::JointHandle> & joint_iface_handles);
105111

106-
#if 0 // @todo
107-
hardware_interface::JointStateInterface js_interface_;
108-
hardware_interface::EffortJointInterface ej_interface_;
109-
hardware_interface::VelocityJointInterface vj_interface_;
110-
hardware_interface::PositionJointInterface pj_interface_;
111-
#endif
112-
#if 0 // @todo
113-
joint_limits_interface::EffortJointSaturationInterface ej_sat_interface_;
114-
joint_limits_interface::EffortJointSoftLimitsInterface ej_limits_interface_;
115-
joint_limits_interface::PositionJointSaturationInterface pj_sat_interface_;
116-
joint_limits_interface::PositionJointSoftLimitsInterface pj_limits_interface_;
117-
joint_limits_interface::VelocityJointSaturationInterface vj_sat_interface_;
118-
joint_limits_interface::VelocityJointSoftLimitsInterface vj_limits_interface_;
119-
#endif
112+
unsigned int n_dof_;
120113
std::vector<std::string> joint_names_;
121114
std::vector<int> joint_types_;
122115
std::vector<double> joint_lower_limits_;
@@ -126,33 +119,43 @@ class DefaultRobotHWSim : public gazebo_ros2_control::RobotHWSim
126119
std::vector<ControlMethod> joint_control_methods_;
127120
std::vector<control_toolbox::PidROS> pid_controllers_;
128121
std::vector<double> joint_position_;
129-
std::vector<double> joint_velocity_;
130-
std::vector<double> joint_effort_;
131-
std::vector<double> joint_effort_command_;
132-
std::vector<double> joint_position_command_;
122+
123+
/// \brief stores the joint positions on ESTOP activation
124+
/// During ESTOP these positions will override the output position command value.
133125
std::vector<double> last_joint_position_command_;
134-
std::vector<double> joint_velocity_command_;
135-
std::vector<hardware_interface::OperationMode> joint_opmodes_;
136126

127+
/// \brief handles to the joints from within Gazebo
137128
std::vector<gazebo::physics::JointPtr> sim_joints_;
138129

139-
std::vector<hardware_interface::JointStateHandle> joint_states_;
140-
std::vector<hardware_interface::JointCommandHandle> joint_cmds_;
141-
std::vector<hardware_interface::JointCommandHandle> joint_eff_cmdhandle_;
142-
std::vector<hardware_interface::JointCommandHandle> joint_vel_cmdhandle_;
130+
/// \brief The current positions of the joints
131+
std::vector<hardware_interface::JointHandle> joint_pos_stateh_;
132+
/// \brief The current velocities of the joints
133+
std::vector<hardware_interface::JointHandle> joint_vel_stateh_;
134+
/// \brief The current effort forces applied to the joints
135+
std::vector<hardware_interface::JointHandle> joint_eff_stateh_;
136+
137+
/// \brief The current position command value (if control mode is POSITION) of the joints
138+
std::vector<hardware_interface::JointHandle> joint_pos_cmdh_;
139+
/// \brief The current effort command value (if control mode is EFFORT) of the joints
140+
std::vector<hardware_interface::JointHandle> joint_eff_cmdh_;
141+
/// \brief The current velocity command value (if control mode is VELOCITY) of the joints
142+
std::vector<hardware_interface::JointHandle> joint_vel_cmdh_;
143+
144+
/// \brief The operational mode (active/inactive) state of the joints
145+
std::vector<hardware_interface::OperationMode> joint_opmodes_;
146+
147+
/// \brief operational mode handles of the joints pointing to values in the joint_opmodes_
148+
/// collection
143149
std::vector<hardware_interface::OperationModeHandle> joint_opmodehandles_;
144150

145-
// limits
146-
std::vector<joint_limits_interface::PositionJointSaturationHandle> joint_pos_limit_handles_;
147-
std::vector<joint_limits_interface::PositionJointSoftLimitsHandle>
148-
joint_pos_soft_limit_handles_;
149-
std::vector<joint_limits_interface::EffortJointSaturationHandle> joint_eff_limit_handles_;
150-
std::vector<joint_limits_interface::EffortJointSoftLimitsHandle>
151-
joint_eff_soft_limit_handles_;
152-
std::vector<joint_limits_interface::VelocityJointSaturationHandle> joint_vel_limit_handles_;
153-
std::vector<joint_limits_interface::VelocityJointSoftLimitsHandle> joint_vel_soft_limit_handles_;
151+
/// \brief Limits for the joints if defined in the URDF or Node parameters
152+
/// The implementation of the joint limit will be chosen based on the URDF parameters and could be
153+
/// one of the hard (saturation) or soft limits based on the control mode (effort, position or
154+
/// velocity)
155+
std::vector<std::unique_ptr<joint_limits_interface::JointLimitHandle>> joint_limit_handles_;
154156

155157
std::string physics_type_;
158+
bool usingODE;
156159

157160
// e_stop_active_ is true if the emergency stop is active.
158161
bool e_stop_active_, last_e_stop_active_;

0 commit comments

Comments
 (0)