Skip to content

Commit ff2b156

Browse files
authored
update mecanum controller (#12)
* update mecanum controller * add pre-commit
1 parent 632a4d2 commit ff2b156

File tree

13 files changed

+543
-416
lines changed

13 files changed

+543
-416
lines changed

.clang-format

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Language: Cpp
2+
BasedOnStyle: Google
3+
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: AlwaysBreak
6+
BraceWrapping:
7+
AfterClass: true
8+
AfterFunction: true
9+
AfterNamespace: true
10+
AfterStruct: true
11+
BreakBeforeBraces: Custom
12+
ColumnLimit: 100
13+
ConstructorInitializerIndentWidth: 0
14+
ContinuationIndentWidth: 2
15+
DerivePointerAlignment: false
16+
PointerAlignment: Middle
17+
ReflowComments: true
18+
IncludeBlocks: Preserve
19+
AlignOperands: true
20+
PenaltyBreakAssignment: 21
21+
PenaltyBreakBeforeFirstCallParameter: 1

.github/workflows/pre-commit.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
name: Pre-commit
3+
4+
on:
5+
push:
6+
7+
jobs:
8+
pre-commit:
9+
uses: ros-controls/ros2_control_ci/.github/workflows/reusable-pre-commit.yml@master
10+
with:
11+
ros_distro: jazzy

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.vscode/*
1+
.vscode/*

.pre-commit-config.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-added-large-files
6+
# mesh files has to be taken into account
7+
args: ["--maxkb=3000"]
8+
- id: check-ast
9+
- id: check-json
10+
# vscode .json files do not follow the standard JSON format
11+
exclude: ^.vscode/
12+
- id: check-merge-conflict
13+
- id: check-symlinks
14+
- id: check-xml
15+
- id: check-yaml
16+
- id: debug-statements
17+
- id: destroyed-symlinks
18+
- id: detect-private-key
19+
- id: end-of-file-fixer
20+
- id: fix-byte-order-marker
21+
- id: name-tests-test
22+
- id: mixed-line-ending
23+
- id: trailing-whitespace
24+
25+
- repo: https://github.com/PyCQA/isort
26+
rev: 5.13.2
27+
hooks:
28+
- id: isort
29+
args: ["--profile", "black"]
30+
31+
- repo: https://github.com/cheshirekow/cmake-format-precommit
32+
rev: v0.6.13
33+
hooks:
34+
- id: cmake-format
35+
36+
- repo: https://github.com/pre-commit/mirrors-clang-format
37+
rev: v19.1.3
38+
hooks:
39+
- id: clang-format
40+
41+
- repo: https://github.com/codespell-project/codespell
42+
rev: v2.3.0
43+
hooks:
44+
- id: codespell
45+
name: codespell
46+
description: Checks for common misspellings in text files.
47+
entry: codespell
48+
args:
49+
[
50+
"--ignore-words-list",
51+
"ned" # north, east, down (NED)
52+
]
53+
exclude_types: [rst, svg]
54+
language: python
55+
types: [text]
56+
57+
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
58+
rev: 0.2.3
59+
hooks:
60+
- id: yamlfmt
61+
files: ^.github|./\.yaml
62+
args: [--mapping, '2', --sequence, '4', --offset, '2', --width, '100']
63+
64+
- repo: https://github.com/psf/black
65+
rev: 24.10.0
66+
hooks:
67+
- id: black
68+
args: ["--line-length=99"]
69+
70+
- repo: https://github.com/PyCQA/flake8
71+
rev: 7.1.1
72+
hooks:
73+
- id: flake8
74+
args:
75+
["--ignore=E501,W503"] # ignore too long line and line break before binary operator,
76+
# black checks it
77+
78+
- repo: local
79+
hooks:
80+
- id: ament_copyright
81+
name: ament_copyright
82+
description: Check if copyright notice is available in all files.
83+
entry: ament_copyright
84+
language: system
85+
86+
# Docs - RestructuredText hooks
87+
- repo: https://github.com/PyCQA/doc8
88+
rev: v1.1.2
89+
hooks:
90+
- id: doc8
91+
args: ["--max-line-length=100", "--ignore=D001"]
92+
exclude: ^.*\/CHANGELOG\.rst$
93+
94+
- repo: https://github.com/tier4/pre-commit-hooks-ros
95+
rev: v0.10.0
96+
hooks:
97+
- id: prettier-package-xml
98+
- id: sort-package-xml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# husarion_controllers
2+
23
Robotic controllers to accompany ros2_control for Husarion robots.

mecanum_drive_controller/CMakeLists.txt

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Copied and adapted from diff_drive_controller (https://github.com/ros-controls/ros2_controllers)
1+
# Copied and adapted from diff_drive_controller
2+
# (https://github.com/ros-controls/ros2_controllers)
23

34
cmake_minimum_required(VERSION 3.11)
45
project(mecanum_drive_controller)
@@ -25,45 +26,42 @@ set(THIS_PACKAGE_INCLUDE_DEPENDS
2526
rcpputils
2627
realtime_tools
2728
tf2
28-
tf2_msgs
29-
)
29+
tf2_msgs)
3030

3131
find_package(ament_cmake REQUIRED)
3232
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
3333
find_package(${Dependency} REQUIRED)
3434
endforeach()
3535

3636
generate_parameter_library(mecanum_drive_controller_parameters
37-
src/mecanum_drive_controller_parameter.yaml
38-
)
37+
src/mecanum_drive_controller_parameter.yaml)
3938

40-
add_library(mecanum_drive_controller SHARED
41-
src/mecanum_drive_controller.cpp
42-
src/odometry.cpp
43-
src/speed_limiter.cpp
44-
)
45-
target_include_directories(mecanum_drive_controller PUBLIC
46-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
47-
$<INSTALL_INTERFACE:include/mecanum_drive_controller>
48-
)
49-
target_link_libraries(mecanum_drive_controller PUBLIC mecanum_drive_controller_parameters)
50-
ament_target_dependencies(mecanum_drive_controller PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
51-
# Causes the visibility macros to use dllexport rather than dllimport,
52-
# which is appropriate when building the dll but not consuming it.
53-
target_compile_definitions(mecanum_drive_controller PRIVATE "MECANUM_DRIVE_CONTROLLER_BUILDING_DLL")
54-
pluginlib_export_plugin_description_file(controller_interface mecanum_drive_plugin.xml)
39+
add_library(
40+
mecanum_drive_controller SHARED src/mecanum_drive_controller.cpp
41+
src/odometry.cpp src/speed_limiter.cpp)
42+
target_include_directories(
43+
mecanum_drive_controller
44+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
45+
$<INSTALL_INTERFACE:include/mecanum_drive_controller>)
46+
target_link_libraries(mecanum_drive_controller
47+
PUBLIC mecanum_drive_controller_parameters)
48+
ament_target_dependencies(mecanum_drive_controller PUBLIC
49+
${THIS_PACKAGE_INCLUDE_DEPENDS})
50+
# Causes the visibility macros to use dllexport rather than dllimport, which is
51+
# appropriate when building the dll but not consuming it.
52+
target_compile_definitions(mecanum_drive_controller
53+
PRIVATE "MECANUM_DRIVE_CONTROLLER_BUILDING_DLL")
54+
pluginlib_export_plugin_description_file(controller_interface
55+
mecanum_drive_plugin.xml)
5556

56-
install(
57-
DIRECTORY include/
58-
DESTINATION include/mecanum_drive_controller
59-
)
57+
install(DIRECTORY include/ DESTINATION include/mecanum_drive_controller)
6058

61-
install(TARGETS mecanum_drive_controller mecanum_drive_controller_parameters
59+
install(
60+
TARGETS mecanum_drive_controller mecanum_drive_controller_parameters
6261
EXPORT export_mecanum_drive_controller
6362
RUNTIME DESTINATION bin
6463
ARCHIVE DESTINATION lib
65-
LIBRARY DESTINATION lib
66-
)
64+
LIBRARY DESTINATION lib)
6765

6866
ament_export_targets(export_mecanum_drive_controller HAS_LIBRARY_TARGET)
6967
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})

mecanum_drive_controller/doc/userdoc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.. Copied and adapted from diff_drive_controller (https://github.com/ros-controls/ros2_controllers)
44
55
mecanum_drive_controller
6-
=====================
6+
========================
77

88
Controller for mobile robots with mecanum drive based on diff_drive_controller (https://github.com/ros-controls/ros2_controllers).
99
Input for control are robot body velocity commands which are translated to wheel commands for the mecanum drive base.

mecanum_drive_controller/include/mecanum_drive_controller/mecanum_drive_controller.hpp

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,30 @@
3131
#include <string>
3232
#include <vector>
3333

34-
#include "controller_interface/controller_interface.hpp"
34+
#include <controller_interface/controller_interface.hpp>
35+
#include <hardware_interface/handle.hpp>
36+
#include <rclcpp/rclcpp.hpp>
37+
#include <rclcpp_lifecycle/state.hpp>
38+
#include <realtime_tools/realtime_box.hpp>
39+
#include <realtime_tools/realtime_buffer.hpp>
40+
#include <realtime_tools/realtime_publisher.hpp>
41+
42+
#include <geometry_msgs/msg/twist.hpp>
43+
#include <geometry_msgs/msg/twist_stamped.hpp>
44+
#include <nav_msgs/msg/odometry.hpp>
45+
#include <tf2_msgs/msg/tf_message.hpp>
46+
47+
#include "mecanum_drive_controller/mecanum_drive_controller_parameters.hpp"
3548
#include "mecanum_drive_controller/odometry.hpp"
3649
#include "mecanum_drive_controller/speed_limiter.hpp"
3750
#include "mecanum_drive_controller/visibility_control.h"
38-
#include "geometry_msgs/msg/twist.hpp"
39-
#include "geometry_msgs/msg/twist_stamped.hpp"
40-
#include "hardware_interface/handle.hpp"
41-
#include "nav_msgs/msg/odometry.hpp"
4251
#include "odometry.hpp"
43-
#include "rclcpp/rclcpp.hpp"
44-
#include "rclcpp_lifecycle/state.hpp"
45-
#include "realtime_tools/realtime_box.hpp"
46-
#include "realtime_tools/realtime_buffer.hpp"
47-
#include "realtime_tools/realtime_publisher.hpp"
48-
#include "tf2_msgs/msg/tf_message.hpp"
49-
50-
#include <mecanum_drive_controller/mecanum_drive_controller_parameters.hpp>
5152

5253
namespace mecanum_drive_controller
5354
{
5455
class MecanumDriveController : public controller_interface::ControllerInterface
5556
{
56-
using Twist = geometry_msgs::msg::TwistStamped;
57+
using TwistStamped = geometry_msgs::msg::TwistStamped;
5758

5859
public:
5960
MECANUM_DRIVE_CONTROLLER_PUBLIC
@@ -66,28 +67,35 @@ class MecanumDriveController : public controller_interface::ControllerInterface
6667
controller_interface::InterfaceConfiguration state_interface_configuration() const override;
6768

6869
MECANUM_DRIVE_CONTROLLER_PUBLIC
69-
controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override;
70+
controller_interface::return_type update(
71+
const rclcpp::Time & time, const rclcpp::Duration & period) override;
7072

7173
MECANUM_DRIVE_CONTROLLER_PUBLIC
7274
controller_interface::CallbackReturn on_init() override;
7375

7476
MECANUM_DRIVE_CONTROLLER_PUBLIC
75-
controller_interface::CallbackReturn on_configure(const rclcpp_lifecycle::State& previous_state) override;
77+
controller_interface::CallbackReturn on_configure(
78+
const rclcpp_lifecycle::State & previous_state) override;
7679

7780
MECANUM_DRIVE_CONTROLLER_PUBLIC
78-
controller_interface::CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override;
81+
controller_interface::CallbackReturn on_activate(
82+
const rclcpp_lifecycle::State & previous_state) override;
7983

8084
MECANUM_DRIVE_CONTROLLER_PUBLIC
81-
controller_interface::CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override;
85+
controller_interface::CallbackReturn on_deactivate(
86+
const rclcpp_lifecycle::State & previous_state) override;
8287

8388
MECANUM_DRIVE_CONTROLLER_PUBLIC
84-
controller_interface::CallbackReturn on_cleanup(const rclcpp_lifecycle::State& previous_state) override;
89+
controller_interface::CallbackReturn on_cleanup(
90+
const rclcpp_lifecycle::State & previous_state) override;
8591

8692
MECANUM_DRIVE_CONTROLLER_PUBLIC
87-
controller_interface::CallbackReturn on_error(const rclcpp_lifecycle::State& previous_state) override;
93+
controller_interface::CallbackReturn on_error(
94+
const rclcpp_lifecycle::State & previous_state) override;
8895

8996
MECANUM_DRIVE_CONTROLLER_PUBLIC
90-
controller_interface::CallbackReturn on_shutdown(const rclcpp_lifecycle::State& previous_state) override;
97+
controller_interface::CallbackReturn on_shutdown(
98+
const rclcpp_lifecycle::State & previous_state) override;
9199

92100
protected:
93101
struct WheelHandle
@@ -96,9 +104,9 @@ class MecanumDriveController : public controller_interface::ControllerInterface
96104
std::reference_wrapper<hardware_interface::LoanedCommandInterface> velocity;
97105
};
98106

99-
const char* feedback_type() const;
100-
controller_interface::CallbackReturn configure_wheel(const std::string& wheel_name,
101-
std::unique_ptr<WheelHandle>& registered_handle);
107+
const char * feedback_type() const;
108+
controller_interface::CallbackReturn configure_wheel(
109+
const std::string & wheel_name, std::unique_ptr<WheelHandle> & registered_handle);
102110

103111
std::string front_left_wheel_name_;
104112
std::string front_right_wheel_name_;
@@ -117,42 +125,48 @@ class MecanumDriveController : public controller_interface::ControllerInterface
117125
Odometry odometry_;
118126

119127
std::shared_ptr<rclcpp::Publisher<nav_msgs::msg::Odometry>> odometry_publisher_ = nullptr;
120-
std::shared_ptr<realtime_tools::RealtimePublisher<nav_msgs::msg::Odometry>> realtime_odometry_publisher_ = nullptr;
128+
std::shared_ptr<realtime_tools::RealtimePublisher<nav_msgs::msg::Odometry>>
129+
realtime_odometry_publisher_ = nullptr;
121130

122-
std::shared_ptr<rclcpp::Publisher<tf2_msgs::msg::TFMessage>> odometry_transform_publisher_ = nullptr;
123-
std::shared_ptr<realtime_tools::RealtimePublisher<tf2_msgs::msg::TFMessage>> realtime_odometry_transform_publisher_ =
124-
nullptr;
131+
std::shared_ptr<rclcpp::Publisher<tf2_msgs::msg::TFMessage>> odometry_transform_publisher_ =
132+
nullptr;
133+
std::shared_ptr<realtime_tools::RealtimePublisher<tf2_msgs::msg::TFMessage>>
134+
realtime_odometry_transform_publisher_ = nullptr;
125135

126136
// Timeout to consider cmd_vel commands old
127-
std::chrono::milliseconds cmd_vel_timeout_{ 500 };
137+
std::chrono::milliseconds cmd_vel_timeout_{500};
128138

129139
bool subscriber_is_active_ = false;
130-
rclcpp::Subscription<Twist>::SharedPtr velocity_command_subscriber_ = nullptr;
140+
rclcpp::Subscription<TwistStamped>::SharedPtr velocity_command_subscriber_ = nullptr;
131141

132-
realtime_tools::RealtimeBox<std::shared_ptr<Twist>> received_velocity_msg_ptr_{ nullptr };
142+
realtime_tools::RealtimeBuffer<std::shared_ptr<TwistStamped>> received_velocity_msg_ptr_{nullptr};
133143

134-
std::queue<Twist> previous_commands_; // last two commands
144+
std::queue<TwistStamped> previous_commands_; // last two commands
135145

136146
// speed limiters
137147
SpeedLimiter limiter_linear_x_;
138148
SpeedLimiter limiter_linear_y_;
139149
SpeedLimiter limiter_angular_;
140150

141151
bool publish_limited_velocity_ = false;
142-
std::shared_ptr<rclcpp::Publisher<Twist>> limited_velocity_publisher_ = nullptr;
143-
std::shared_ptr<realtime_tools::RealtimePublisher<Twist>> realtime_limited_velocity_publisher_ = nullptr;
152+
std::shared_ptr<rclcpp::Publisher<TwistStamped>> limited_velocity_publisher_ = nullptr;
153+
std::shared_ptr<realtime_tools::RealtimePublisher<TwistStamped>>
154+
realtime_limited_velocity_publisher_ = nullptr;
144155

145-
rclcpp::Time previous_update_timestamp_{ 0 };
156+
rclcpp::Time previous_update_timestamp_{0};
146157

147158
// publish rate limiter
148159
double publish_rate_ = 50.0;
149160
rclcpp::Duration publish_period_ = rclcpp::Duration::from_nanoseconds(0);
150-
rclcpp::Time previous_publish_timestamp_{ 0 };
161+
rclcpp::Time previous_publish_timestamp_{0};
151162

152163
bool is_halted = false;
153164

154165
bool reset();
155166
void halt();
167+
168+
private:
169+
void reset_buffers();
156170
};
157171
} // namespace mecanum_drive_controller
158172
#endif // MECANUM_DRIVE_CONTROLLER__MECANUM_DRIVE_CONTROLLER_HPP_

0 commit comments

Comments
 (0)