Skip to content

Commit bc88acb

Browse files
pac48destoglbmagyar
authored
[DiffDriveController] Use generate parameter library (#386)
Co-authored-by: Denis Štogl <[email protected]> Co-authored-by: Bence Magyar <[email protected]>
1 parent 5a367e2 commit bc88acb

File tree

6 files changed

+250
-247
lines changed

6 files changed

+250
-247
lines changed

diff_drive_controller/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
3030
find_package(${Dependency} REQUIRED)
3131
endforeach()
3232

33+
find_package(generate_parameter_library REQUIRED)
34+
35+
generate_parameter_library(diff_drive_controller_parameters
36+
src/diff_drive_controller_parameter.yaml
37+
)
38+
3339
add_library(${PROJECT_NAME} SHARED
3440
src/diff_drive_controller.cpp
3541
src/odometry.cpp
@@ -39,6 +45,9 @@ target_include_directories(${PROJECT_NAME}
3945
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
4046
$<INSTALL_INTERFACE:include>)
4147
ament_target_dependencies(${PROJECT_NAME} ${THIS_PACKAGE_INCLUDE_DEPENDS})
48+
target_link_libraries(${PROJECT_NAME}
49+
diff_drive_controller_parameters
50+
)
4251
# Causes the visibility macros to use dllexport rather than dllimport,
4352
# which is appropriate when building the dll but not consuming it.
4453
target_compile_definitions(${PROJECT_NAME} PRIVATE "DIFF_DRIVE_CONTROLLER_BUILDING_DLL")

diff_drive_controller/doc/userdoc.rst

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -70,79 +70,10 @@ Services
7070
Parameters
7171
------------
7272

73-
Wheels
74-
,,,,,,,
75-
left_wheel_names [array<string>]
76-
Link names of the left side wheels.
77-
78-
right_wheel_names [array<string>]
79-
Link names of the right side wheels.
80-
81-
wheel_separation [double]
82-
Shortest distance between the left and right wheels.
83-
If this parameter is wrong, the robot will not behave correctly in curves.
84-
85-
wheels_per_side [integer]
86-
Number of wheels on each wide of the robot.
87-
This is important to take the wheels slip into account when multiple wheels on each side are present.
88-
If there are more wheels then control signals for each side, you should enter number or control signals.
89-
For example, Husky has two wheels on each side, but they use one control signal, in this case "1" is the correct value of the parameter.
90-
91-
wheel_radius [double]
92-
Radius of a wheel, i.e., wheels size, used for transformation of linear velocity into wheel rotations.
93-
If this parameter is wrong the robot will move faster or slower then expected.
94-
95-
wheel_separation_multiplier [double]
96-
Correction factor for wheel separation (TODO(destogl): Please help me describe this correctly)
97-
98-
left_wheel_radius_multiplier [double]
99-
Correction factor when radius of left wheels differs from the nominal value in ``wheel_radius`` parameter.
100-
101-
right_wheel_radius_multiplier [double]
102-
Correction factor when radius of right wheels differs from the nominal value in ``wheel_radius`` parameter.
103-
104-
Odometry
105-
,,,,,,,,,
106-
base_frame_id [string] (default: "base_link")
107-
Name of the frame for odometry.
108-
This frame is parent of ``base_frame_id`` when controller publishes odometry.
109-
110-
odom_frame_id [string] (default: "odom")
111-
Name of the robot's base frame that is child of the odometry frame.
73+
Check `parameter definition file for details <https://github.com/ros-controls/ros2_controllers/blob/master/diff_drive_controller/src/diff_drive_controller_parameter.yaml>`_.
11274

113-
pose_covariance_diagonal [array<double>[6]] (default: "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]")
114-
Odometry covariance for the encoder output of the robot for the pose.
115-
These values should be tuned to your robot's sample odometry data, but these values are a good place to start:
116-
``[0.001, 0.001, 0.001, 0.001, 0.001, 0.01]``.
117-
118-
twist_covariance_diagonal [array<double>[6]] (default: "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]")
119-
Odometry covariance for the encoder output of the robot for the speed.
120-
These values should be tuned to your robot's sample odometry data, but these values are a good place to start:
121-
``[0.001, 0.001, 0.001, 0.001, 0.001, 0.01]``.
122-
123-
open_loop [bool] (default: "false")
124-
If set to false the odometry of the robot will be calculated from the commanded values and not from feedback.
125-
126-
position_feedback [bool] (default: "true")
127-
Is there position feedback from hardware.
128-
129-
enable_odom_tf [bool] (default: "true")
130-
Publish transformation between ``odom_frame_id`` and ``base_frame_id``.
131-
132-
velocity_rolling_window_size [int] (default: "10")
133-
(TODO(destogl): Please help me describe this correctly)
134-
135-
Commands
136-
```````````
137-
cmd_vel_timeout [double] (default: "0.5s")
138-
Timeout after which input command on ``cmd_vel`` topic is considered staled.
139-
140-
publish_limited_velocity [double] (default: "false")
141-
Publish limited velocity value.
142-
143-
144-
use_stamped_vel [bool] (default: "true")
145-
Use stamp from input velocity message to calculate how old the command actually is.
75+
Note that the documentation on parameters for joint limits can be found in `their header file <https://github.com/ros-controls/ros2_control/blob/master/joint_limits/include/joint_limits/joint_limits_rosparam.hpp#L56-L75>`_.
76+
Those parameters are:
14677

14778
linear.x [JointLimits structure]
14879
Joint limits structure for the linear X-axis.
@@ -153,6 +84,3 @@ angular.z [JointLimits structure]
15384
Joint limits structure for the rotation about Z-axis.
15485
The limiter ignores position limits.
15586
For details see ``joint_limits`` package from ros2_control repository.
156-
157-
publish_rate [double] (default: "50.0")
158-
Publishing rate (Hz) of the odometry and TF messages.

diff_drive_controller/include/diff_drive_controller/diff_drive_controller.hpp

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include "realtime_tools/realtime_publisher.h"
4343
#include "tf2_msgs/msg/tf_message.hpp"
4444

45+
#include "diff_drive_controller_parameters.hpp"
46+
4547
namespace diff_drive_controller
4648
{
4749
class DiffDriveController : public controller_interface::ControllerInterface
@@ -101,35 +103,18 @@ class DiffDriveController : public controller_interface::ControllerInterface
101103
const std::string & side, const std::vector<std::string> & wheel_names,
102104
std::vector<WheelHandle> & registered_handles);
103105

104-
std::vector<std::string> left_wheel_names_;
105-
std::vector<std::string> right_wheel_names_;
106-
107106
std::vector<WheelHandle> registered_left_wheel_handles_;
108107
std::vector<WheelHandle> registered_right_wheel_handles_;
109108

110-
struct WheelParams
111-
{
112-
size_t wheels_per_side = 0;
113-
double separation = 0.0; // w.r.t. the midpoint of the wheel width
114-
double radius = 0.0; // Assumed to be the same for both wheels
115-
double separation_multiplier = 1.0;
116-
double left_radius_multiplier = 1.0;
117-
double right_radius_multiplier = 1.0;
118-
} wheel_params_;
119-
120-
struct OdometryParams
121-
{
122-
bool open_loop = false;
123-
bool position_feedback = true;
124-
bool enable_odom_tf = true;
125-
std::string base_frame_id = "base_link";
126-
std::string odom_frame_id = "odom";
127-
std::array<double, 6> pose_covariance_diagonal;
128-
std::array<double, 6> twist_covariance_diagonal;
129-
} odom_params_;
109+
// Parameters from ROS for diff_drive_controller
110+
std::shared_ptr<ParamListener> param_listener_;
111+
Params params_;
130112

131113
Odometry odometry_;
132114

115+
// Timeout to consider cmd_vel commands old
116+
std::chrono::milliseconds cmd_vel_timeout_{500};
117+
133118
std::shared_ptr<rclcpp::Publisher<nav_msgs::msg::Odometry>> odometry_publisher_ = nullptr;
134119
std::shared_ptr<realtime_tools::RealtimePublisher<nav_msgs::msg::Odometry>>
135120
realtime_odometry_publisher_ = nullptr;
@@ -139,9 +124,6 @@ class DiffDriveController : public controller_interface::ControllerInterface
139124
std::shared_ptr<realtime_tools::RealtimePublisher<tf2_msgs::msg::TFMessage>>
140125
realtime_odometry_transform_publisher_ = nullptr;
141126

142-
// Timeout to consider cmd_vel commands old
143-
std::chrono::milliseconds cmd_vel_timeout_{500};
144-
145127
bool subscriber_is_active_ = false;
146128
rclcpp::Subscription<Twist>::SharedPtr velocity_command_subscriber_ = nullptr;
147129
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr

diff_drive_controller/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<license>Apache License 2.0</license>
1010

1111
<buildtool_depend>ament_cmake</buildtool_depend>
12+
<build_depend>generate_parameter_library</build_depend>
1213

1314
<depend>controller_interface</depend>
1415
<depend>geometry_msgs</depend>

0 commit comments

Comments
 (0)