Skip to content

Commit fa69500

Browse files
committed
add pre-commit
1 parent 4573524 commit fa69500

File tree

11 files changed

+227
-142
lines changed

11 files changed

+227
-142
lines changed

.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/odometry.hpp

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,22 @@ class Odometry
3939
public:
4040
explicit Odometry(size_t velocity_rolling_window_size = 10);
4141

42-
void init(const rclcpp::Time& time);
43-
bool update(double front_left_pos, double front_right_pos, double rear_left_pos, double rear_right_pos,
44-
const rclcpp::Time& time);
45-
bool updateFromVelocity(double front_left_vel, double front_right_vel, double rear_left_vel, double rear_right_vel,
46-
const rclcpp::Time& time);
47-
void updateOpenLoop(double linear_x, double linear_y, double angular, const rclcpp::Time& time);
42+
void init(const rclcpp::Time & time);
43+
bool update(
44+
double front_left_pos, double front_right_pos, double rear_left_pos, double rear_right_pos,
45+
const rclcpp::Time & time);
46+
bool updateFromVelocity(
47+
double front_left_vel, double front_right_vel, double rear_left_vel, double rear_right_vel,
48+
const rclcpp::Time & time);
49+
void updateOpenLoop(double linear_x, double linear_y, double angular, const rclcpp::Time & time);
4850
void resetOdometry();
4951

50-
double getX() const
51-
{
52-
return x_;
53-
}
54-
double getY() const
55-
{
56-
return y_;
57-
}
58-
double getHeading() const
59-
{
60-
return heading_;
61-
}
62-
double getLinearX() const
63-
{
64-
return linear_x_;
65-
}
66-
double getLinearY() const
67-
{
68-
return linear_y_;
69-
}
70-
double getAngular() const
71-
{
72-
return angular_;
73-
}
52+
double getX() const { return x_; }
53+
double getY() const { return y_; }
54+
double getHeading() const { return heading_; }
55+
double getLinearX() const { return linear_x_; }
56+
double getLinearY() const { return linear_y_; }
57+
double getAngular() const { return angular_; }
7458

7559
void setWheelParams(double wheel_separation_x, double wheel_separation_y, double wheel_radius);
7660
void setVelocityRollingWindowSize(size_t velocity_rolling_window_size);

mecanum_drive_controller/include/mecanum_drive_controller/speed_limiter.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ class SpeedLimiter
4242
* \param [in] min_jerk Minimum jerk [m/s^3], usually <= 0
4343
* \param [in] max_jerk Maximum jerk [m/s^3], usually >= 0
4444
*/
45-
SpeedLimiter(bool has_velocity_limits = false, bool has_acceleration_limits = false, bool has_jerk_limits = false,
46-
double min_velocity = NAN, double max_velocity = NAN, double min_acceleration = NAN,
47-
double max_acceleration = NAN, double min_jerk = NAN, double max_jerk = NAN);
45+
SpeedLimiter(
46+
bool has_velocity_limits = false, bool has_acceleration_limits = false,
47+
bool has_jerk_limits = false, double min_velocity = NAN, double max_velocity = NAN,
48+
double min_acceleration = NAN, double max_acceleration = NAN, double min_jerk = NAN,
49+
double max_jerk = NAN);
4850

4951
/**
5052
* \brief Limit the velocity and acceleration
@@ -54,14 +56,14 @@ class SpeedLimiter
5456
* \param [in] dt Time step [s]
5557
* \return Limiting factor (1.0 if none)
5658
*/
57-
double limit(double& v, double v0, double v1, double dt);
59+
double limit(double & v, double v0, double v1, double dt);
5860

5961
/**
6062
* \brief Limit the velocity
6163
* \param [in, out] v Velocity [m/s]
6264
* \return Limiting factor (1.0 if none)
6365
*/
64-
double limit_velocity(double& v);
66+
double limit_velocity(double & v);
6567

6668
/**
6769
* \brief Limit the acceleration
@@ -70,7 +72,7 @@ class SpeedLimiter
7072
* \param [in] dt Time step [s]
7173
* \return Limiting factor (1.0 if none)
7274
*/
73-
double limit_acceleration(double& v, double v0, double dt);
75+
double limit_acceleration(double & v, double v0, double dt);
7476

7577
/**
7678
* \brief Limit the jerk
@@ -81,7 +83,7 @@ class SpeedLimiter
8183
* \return Limiting factor (1.0 if none)
8284
* \see http://en.wikipedia.org/wiki/Jerk_%28physics%29#Motion_control
8385
*/
84-
double limit_jerk(double& v, double v0, double v1, double dt);
86+
double limit_jerk(double & v, double v0, double v1, double dt);
8587

8688
private:
8789
// Enable/Disable velocity/acceleration/jerk limits:

mecanum_drive_controller/src/mecanum_drive_controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ controller_interface::CallbackReturn MecanumDriveController::on_configure(
404404
received_velocity_msg_ptr_.writeFromNonRT(std::move(msg));
405405
});
406406

407-
// initialize odometry publisher and messasge
407+
// initialize odometry publisher and message
408408
odometry_publisher_ = get_node()->create_publisher<nav_msgs::msg::Odometry>(
409409
DEFAULT_ODOMETRY_TOPIC, rclcpp::SystemDefaultsQoS());
410410
realtime_odometry_publisher_ =

0 commit comments

Comments
 (0)