Skip to content

Commit 8733050

Browse files
authored
Merge pull request #4 from AGH-CEAI/feature/cpp_pre-commit
Pre-commit config - Ruff, cmake & clang formaters
2 parents 6edbf83 + 463294f commit 8733050

File tree

8 files changed

+157
-106
lines changed

8 files changed

+157
-106
lines changed

.clang-format

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google
4+
5+
ColumnLimit: 100
6+
IndentWidth: 4
7+
8+
AccessModifierOffset: -1
9+
AlignAfterOpenBracket: AlwaysBreak
10+
AllowShortFunctionsOnASingleLine: Empty
11+
BinPackArguments: false
12+
BinPackParameters: false
13+
BreakBeforeBinaryOperators: NonAssignment
14+
DerivePointerAlignment: false
15+
IncludeBlocks: Preserve
16+
IndentPPDirectives: BeforeHash
17+
PenaltyBreakAssignment: 21
18+
19+
SpaceBeforeParens: Custom
20+
SpaceBeforeParensOptions:
21+
AfterControlStatements: false
22+
AfterForeachMacros: false
23+
AfterFunctionDeclarationName: false
24+
AfterFunctionDefinitionName: false
25+
AfterIfMacros: false
26+
AfterOverloadedOperator: false
27+
AfterPlacementOperator: true
28+
AfterRequiresInClause: false
29+
AfterRequiresInExpression: false
30+
BeforeNonEmptyParentheses: false

.cmake-format.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
with section("format"): # noqa F821
2+
line_width = 100
3+
tab_size = 2
4+
command_case = "lower"
5+
max_subgroups_hwrap = 2
6+
max_pargs_hwrap = 4

.pre-commit-config.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
11
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.9.5
4+
hooks:
5+
- id: ruff
6+
args:
7+
- --fix
8+
- --exit-non-zero-on-fix
9+
- id: ruff-format
10+
11+
- repo: https://github.com/cheshirekow/cmake-format-precommit
12+
rev: v0.6.13
13+
hooks:
14+
- id: cmake-format
15+
- id: cmake-lint
16+
17+
- repo: https://github.com/pre-commit/mirrors-clang-format
18+
rev: v19.1.7
19+
hooks:
20+
- id: clang-format
21+
types_or: [c++, c]
22+
args:
23+
- --style=file
24+
225
- repo: https://github.com/pre-commit/pre-commit-hooks
326
rev: v5.0.0
427
hooks:
528
- id: check-added-large-files
29+
- id: check-ast
630
- id: check-case-conflict
31+
- id: check-executables-have-shebangs
732
- id: check-json
833
- id: check-merge-conflict
934
- id: check-symlinks
1035
- id: check-toml
1136
- id: check-xml
37+
- id: check-yaml
1238
- id: debug-statements
1339
- id: destroyed-symlinks
1440
- id: detect-private-key
1541
- id: end-of-file-fixer
42+
- id: fix-byte-order-marker
1643
- id: mixed-line-ending
1744
- id: pretty-format-json
1845
- id: trailing-whitespace
19-
- id: check-yaml
2046

2147
- repo: https://github.com/codespell-project/codespell
2248
rev: v2.2.6

robotiq_hande_driver/CMakeLists.txt

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,57 @@ cmake_minimum_required(VERSION 3.16)
22
project(robotiq_hande_driver)
33

44
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
5+
# TODO(issue#5) Fix warnings to enable the -Werror flag
56
add_compile_options(-Wall -Wextra -Wpedantic)
67
endif()
78

89
set(HW_IF_INCLUDE_DEPENDS
9-
fmt
10-
hardware_interface
11-
pluginlib
12-
rclcpp
13-
rclcpp_lifecycle
14-
rcpputils
15-
)
10+
fmt
11+
hardware_interface
12+
pluginlib
13+
rclcpp
14+
rclcpp_lifecycle
15+
rcpputils)
1616

1717
find_package(ament_cmake REQUIRED)
18-
foreach(Dependency IN ITEMS ${HW_IF_INCLUDE_DEPENDS})
19-
find_package(${Dependency} REQUIRED)
18+
foreach(dependency IN ITEMS ${HW_IF_INCLUDE_DEPENDS})
19+
find_package(${dependency} REQUIRED)
2020
endforeach()
2121

22-
add_library(${PROJECT_NAME}
23-
SHARED
24-
hardware/src/hande_hardware_interface.cpp
25-
)
22+
add_library(${PROJECT_NAME} SHARED hardware/src/hande_hardware_interface.cpp)
2623

2724
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
28-
target_include_directories(robotiq_hande_driver PUBLIC
29-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hardware/include>
30-
$<INSTALL_INTERFACE:include>
31-
)
32-
ament_target_dependencies(
33-
${PROJECT_NAME} PUBLIC
34-
${HW_IF_INCLUDE_DEPENDS}
35-
)
25+
target_include_directories(
26+
robotiq_hande_driver PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hardware/include>
27+
$<INSTALL_INTERFACE:include>)
28+
ament_target_dependencies(${PROJECT_NAME} PUBLIC ${HW_IF_INCLUDE_DEPENDS})
3629

3730
pluginlib_export_plugin_description_file(hardware_interface ros2_control_plugin.xml)
3831

39-
install(
40-
DIRECTORY hardware/include/
41-
DESTINATION include/
42-
)
43-
install(
44-
DIRECTORY bringup
45-
DESTINATION share/${PROJECT_NAME}
46-
)
32+
install(DIRECTORY hardware/include/ DESTINATION include/)
33+
install(DIRECTORY bringup DESTINATION share/${PROJECT_NAME})
4734

48-
49-
install(TARGETS ${PROJECT_NAME}
35+
install(
36+
TARGETS ${PROJECT_NAME}
5037
EXPORT export_${PROJECT_NAME}
5138
ARCHIVE DESTINATION lib
5239
LIBRARY DESTINATION lib
53-
RUNTIME DESTINATION bin
54-
)
40+
RUNTIME DESTINATION bin)
5541

5642
if(BUILD_TESTING)
5743
find_package(ament_cmake_gmock REQUIRED)
5844
# find_package(ament_cmake_pytest REQUIRED)
5945
find_package(hardware_interface REQUIRED)
6046

61-
ament_add_gmock(test_load_hw_interface
62-
test/test_load_hw_interface.cpp
63-
)
47+
ament_add_gmock(test_load_hw_interface test/test_load_hw_interface.cpp)
6448
target_link_libraries(test_load_hw_interface ${PROJECT_NAME})
6549

66-
# TODO: investigate
67-
# ament_add_pytest_test(example_7_urdf_xacro test/test_urdf_xacro.py)
50+
# TODO: investigate ament_add_pytest_test(example_7_urdf_xacro test/test_urdf_xacro.py)
6851
# ament_add_pytest_test(view_example_7_launch test/test_view_robot_launch.py)
6952
# ament_add_pytest_test(run_example_7_launch test/test_r6bot_controller_launch.py)
7053
endif()
7154

72-
## EXPORTS
55+
# EXPORTS
7356
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
7457
ament_export_dependencies(${HW_IF_INCLUDE_DEPENDS})
7558
ament_package()

robotiq_hande_driver/bringup/launch/gripper_controller_preview.launch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ def generate_launch_description():
4848

4949

5050
def launch_setup(context: LaunchContext) -> list[IncludeLaunchDescription]:
51-
5251
# tf_prefix is implicitly used in robot_state_publisher (in URDF substitution)
53-
tf_prefix = LaunchConfiguration("tf_prefix", default="")
52+
tf_prefix = LaunchConfiguration("tf_prefix", default="") # noqa: F841
5453

5554
return [
5655
preapre_control_node(),
@@ -105,7 +104,8 @@ def preapre_control_node() -> Node:
105104

106105

107106
def prepare_robot_state_publisher_node() -> Node:
108-
tf_prefix = LaunchConfiguration("tf_prefix", default="")
107+
# tf_prefix is implicitly used in ParameterValue()
108+
tf_prefix = LaunchConfiguration("tf_prefix", default="") # noqa: F841
109109
use_fake_hardware = LaunchConfiguration("use_fake_hardware")
110110

111111
robot_description_str = Command(

robotiq_hande_driver/hardware/include/robotiq_hande_driver/hande_hardware_interface.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef ROBOTIQ_HANDE_DRIVER__HANDE_HARDWARE_INTERFACE_HPP_
22
#define ROBOTIQ_HANDE_DRIVER__HANDE_HARDWARE_INTERFACE_HPP_
33

4-
#include <string>
54
#include <hardware_interface/system_interface.hpp>
65
#include <rclcpp/rclcpp.hpp>
6+
#include <string>
77

88
namespace robotiq_hande_driver {
99

@@ -12,9 +12,8 @@ namespace rlccp_lc = rclcpp_lifecycle;
1212

1313
constexpr int LEFT_FINGER_JOINT_ID = 0;
1414

15-
class RobotiqHandeHardwareInterface : public HWI::SystemInterface
16-
{
17-
public:
15+
class RobotiqHandeHardwareInterface : public HWI::SystemInterface {
16+
public:
1817
RobotiqHandeHardwareInterface();
1918

2019
HWI::CallbackReturn on_init(const HWI::HardwareInfo& info) override;
@@ -32,10 +31,12 @@ class RobotiqHandeHardwareInterface : public HWI::SystemInterface
3231
HWI::return_type read(const rclcpp::Time& time, const rclcpp::Duration& period) override;
3332
HWI::return_type write(const rclcpp::Time& time, const rclcpp::Duration& period) override;
3433

35-
rclcpp::Logger get_logger() const { return *logger_; }
34+
rclcpp::Logger get_logger() const {
35+
return *logger_;
36+
}
3637

37-
private:
38-
//TODO(modbus integration): composition of the modbus communication
38+
private:
39+
// TODO(modbus integration): composition of the modbus communication
3940
std::shared_ptr<rclcpp::Logger> logger_;
4041

4142
std::string tty_port_;
@@ -44,5 +45,5 @@ class RobotiqHandeHardwareInterface : public HWI::SystemInterface
4445
double cmd_position_;
4546
};
4647

47-
} // namespace robotiq_hande_driver
48+
} // namespace robotiq_hande_driver
4849
#endif // ROBOTIQ_HANDE_DRIVER__HANDE_HARDWARE_INTERFACE_HPP_

robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace robotiq_hande_driver {
88
RobotiqHandeHardwareInterface::RobotiqHandeHardwareInterface() {}
99

1010
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_init(const HWI::HardwareInfo& info) {
11-
if (HWI::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) {
11+
if(HWI::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) {
1212
return HWI::CallbackReturn::ERROR;
1313
}
1414

@@ -18,22 +18,25 @@ HWI::CallbackReturn RobotiqHandeHardwareInterface::on_init(const HWI::HardwareIn
1818
tty_port_ = info_.hardware_parameters["tty"];
1919

2020
logger_ = std::make_shared<rclcpp::Logger>(
21-
rclcpp::get_logger("controller_manager.resource_manager.hardware_component.system.RobotiqHandeHardwareInterface"));
21+
rclcpp::get_logger("controller_manager.resource_manager.hardware_"
22+
"component.system.RobotiqHandeHardwareInterface"));
2223

23-
//TODO(modbus integration): Set parameters for the modbus communication
24+
// TODO(modbus integration): Set parameters for the modbus communication
2425

2526
RCLCPP_INFO(get_logger(), "Initialized ModbusRTU for %s", tty_port_.c_str());
2627
return HWI::CallbackReturn::SUCCESS;
2728
}
2829

29-
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_configure(const rlccp_lc::State& /*previous_state*/){
30-
//TODO(modbus integration): Initialize the ModbusRTU communication session
30+
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_configure(
31+
const rlccp_lc::State& /*previous_state*/) {
32+
// TODO(modbus integration): Initialize the ModbusRTU communication session
3133
RCLCPP_INFO(get_logger(), "configure()");
3234
return HWI::CallbackReturn::SUCCESS;
3335
}
3436

35-
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_cleanup(const rlccp_lc::State& /*previous_state*/){
36-
//TODO(modbus integration): Deinitalize the ModbusRTU session
37+
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_cleanup(
38+
const rlccp_lc::State& /*previous_state*/) {
39+
// TODO(modbus integration): Deinitalize the ModbusRTU session
3740
RCLCPP_INFO(get_logger(), "cleanup()");
3841
return HWI::CallbackReturn::SUCCESS;
3942
}
@@ -42,9 +45,13 @@ std::vector<HWI::StateInterface> RobotiqHandeHardwareInterface::export_state_int
4245
std::vector<HWI::StateInterface> state_interfaces;
4346

4447
state_interfaces.emplace_back(hardware_interface::StateInterface(
45-
info_.joints[LEFT_FINGER_JOINT_ID].name, hardware_interface::HW_IF_POSITION, &state_position_));
48+
info_.joints[LEFT_FINGER_JOINT_ID].name,
49+
hardware_interface::HW_IF_POSITION,
50+
&state_position_));
4651
state_interfaces.emplace_back(hardware_interface::StateInterface(
47-
info_.joints[LEFT_FINGER_JOINT_ID].name, hardware_interface::HW_IF_VELOCITY, &state_velocity_));
52+
info_.joints[LEFT_FINGER_JOINT_ID].name,
53+
hardware_interface::HW_IF_VELOCITY,
54+
&state_velocity_));
4855

4956
RCLCPP_INFO(get_logger(), "export_state_interfaces()");
5057
return state_interfaces;
@@ -54,50 +61,56 @@ std::vector<HWI::CommandInterface> RobotiqHandeHardwareInterface::export_command
5461
std::vector<hardware_interface::CommandInterface> command_interfaces;
5562

5663
command_interfaces.emplace_back(hardware_interface::CommandInterface(
57-
info_.joints[LEFT_FINGER_JOINT_ID].name, hardware_interface::HW_IF_POSITION, &cmd_position_));
64+
info_.joints[LEFT_FINGER_JOINT_ID].name,
65+
hardware_interface::HW_IF_POSITION,
66+
&cmd_position_));
5867

5968
RCLCPP_INFO(get_logger(), "export_command_interfaces()");
6069
return command_interfaces;
6170
}
6271

63-
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_activate(const rlccp_lc::State& /*previous_state*/){
64-
//TODO(modbus integration): Power on the gripper (activation)
72+
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_activate(
73+
const rlccp_lc::State& /*previous_state*/) {
74+
// TODO(modbus integration): Power on the gripper (activation)
6575
RCLCPP_INFO(get_logger(), "activate()");
6676
return HWI::CallbackReturn::SUCCESS;
6777
}
6878

69-
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_deactivate(const rlccp_lc::State& /*previous_state*/){
70-
//TODO(modbus integration): Deactiavte the gripper (set the reset flag)
79+
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_deactivate(
80+
const rlccp_lc::State& /*previous_state*/) {
81+
// TODO(modbus integration): Deactiavte the gripper (set the reset flag)
7182
RCLCPP_INFO(get_logger(), "deactivate()");
7283
return HWI::CallbackReturn::SUCCESS;
7384
}
7485

75-
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_shutdown(const rlccp_lc::State& /*previous_state*/){
76-
//TODO(modbus integration): Deactivate the gripper, deinitalize the modbus RTU session,
86+
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_shutdown(
87+
const rlccp_lc::State& /*previous_state*/) {
88+
// TODO(modbus integration): Deactivate the gripper, deinitalize the modbus
89+
// RTU session,
7790
RCLCPP_INFO(get_logger(), "shutdown()");
7891
return HWI::CallbackReturn::SUCCESS;
7992
}
8093

81-
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_error(const rlccp_lc::State& /*previous_state*/){
82-
//TODO(modbus integration): Placeholder for error handling
94+
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_error(
95+
const rlccp_lc::State& /*previous_state*/) {
96+
// TODO(modbus integration): Placeholder for error handling
8397
RCLCPP_INFO(get_logger(), "Handled error");
8498
return HWI::CallbackReturn::SUCCESS;
8599
}
86100

87-
HWI::return_type RobotiqHandeHardwareInterface::read(const rclcpp::Time& /*time*/,
88-
const rclcpp::Duration& /*period*/) {
89-
//TODO(modbus integration): data = driver_->receive_data();
101+
HWI::return_type RobotiqHandeHardwareInterface::read(
102+
const rclcpp::Time& /*time*/, const rclcpp::Duration& /*period*/) {
103+
// TODO(modbus integration): data = driver_->receive_data();
90104
return hardware_interface::return_type::OK;
91105
}
92-
HWI::return_type RobotiqHandeHardwareInterface::write(const rclcpp::Time& /*time*/,
93-
const rclcpp::Duration& /*period*/) {
94-
//TODO(modbus integration): driver_->send_data(cmd_position_);
106+
HWI::return_type RobotiqHandeHardwareInterface::write(
107+
const rclcpp::Time& /*time*/, const rclcpp::Duration& /*period*/) {
108+
// TODO(modbus integration): driver_->send_data(cmd_position_);
95109
return hardware_interface::return_type::OK;
96110
}
97111

98-
99-
} // namespace robotiq_hande_driver
112+
} // namespace robotiq_hande_driver
100113

101114
#include "pluginlib/class_list_macros.hpp"
102115
PLUGINLIB_EXPORT_CLASS(
103-
robotiq_hande_driver::RobotiqHandeHardwareInterface, hardware_interface::SystemInterface)
116+
robotiq_hande_driver::RobotiqHandeHardwareInterface, hardware_interface::SystemInterface)

0 commit comments

Comments
 (0)