Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
Language: Cpp
BasedOnStyle: Google

ColumnLimit: 100
IndentWidth: 4

AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AllowShortFunctionsOnASingleLine: Empty
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: NonAssignment
DerivePointerAlignment: false
IncludeBlocks: Preserve
IndentPPDirectives: BeforeHash
PenaltyBreakAssignment: 21

SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: false
AfterForeachMacros: false
AfterFunctionDeclarationName: false
AfterFunctionDefinitionName: false
AfterIfMacros: false
AfterOverloadedOperator: false
AfterPlacementOperator: true
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
6 changes: 6 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
with section("format"): # noqa F821
line_width = 100
tab_size = 2
command_case = "lower"
max_subgroups_hwrap = 2
max_pargs_hwrap = 4
28 changes: 27 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.5
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- id: ruff-format

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
- id: cmake-lint

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.7
hooks:
- id: clang-format
types_or: [c++, c]
args:
- --style=file

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: pretty-format-json
- id: trailing-whitespace
- id: check-yaml

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
Expand Down
61 changes: 22 additions & 39 deletions robotiq_hande_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,57 @@ cmake_minimum_required(VERSION 3.16)
project(robotiq_hande_driver)

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

set(HW_IF_INCLUDE_DEPENDS
fmt
hardware_interface
pluginlib
rclcpp
rclcpp_lifecycle
rcpputils
)
fmt
hardware_interface
pluginlib
rclcpp
rclcpp_lifecycle
rcpputils)

find_package(ament_cmake REQUIRED)
foreach(Dependency IN ITEMS ${HW_IF_INCLUDE_DEPENDS})
find_package(${Dependency} REQUIRED)
foreach(dependency IN ITEMS ${HW_IF_INCLUDE_DEPENDS})
find_package(${dependency} REQUIRED)
endforeach()

add_library(${PROJECT_NAME}
SHARED
hardware/src/hande_hardware_interface.cpp
)
add_library(${PROJECT_NAME} SHARED hardware/src/hande_hardware_interface.cpp)

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
target_include_directories(robotiq_hande_driver PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hardware/include>
$<INSTALL_INTERFACE:include>
)
ament_target_dependencies(
${PROJECT_NAME} PUBLIC
${HW_IF_INCLUDE_DEPENDS}
)
target_include_directories(
robotiq_hande_driver PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hardware/include>
$<INSTALL_INTERFACE:include>)
ament_target_dependencies(${PROJECT_NAME} PUBLIC ${HW_IF_INCLUDE_DEPENDS})

pluginlib_export_plugin_description_file(hardware_interface ros2_control_plugin.xml)

install(
DIRECTORY hardware/include/
DESTINATION include/
)
install(
DIRECTORY bringup
DESTINATION share/${PROJECT_NAME}
)
install(DIRECTORY hardware/include/ DESTINATION include/)
install(DIRECTORY bringup DESTINATION share/${PROJECT_NAME})


install(TARGETS ${PROJECT_NAME}
install(
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
RUNTIME DESTINATION bin)

if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)
# find_package(ament_cmake_pytest REQUIRED)
find_package(hardware_interface REQUIRED)

ament_add_gmock(test_load_hw_interface
test/test_load_hw_interface.cpp
)
ament_add_gmock(test_load_hw_interface test/test_load_hw_interface.cpp)
target_link_libraries(test_load_hw_interface ${PROJECT_NAME})

# TODO: investigate
# ament_add_pytest_test(example_7_urdf_xacro test/test_urdf_xacro.py)
# TODO: investigate ament_add_pytest_test(example_7_urdf_xacro test/test_urdf_xacro.py)
# ament_add_pytest_test(view_example_7_launch test/test_view_robot_launch.py)
# ament_add_pytest_test(run_example_7_launch test/test_r6bot_controller_launch.py)
endif()

## EXPORTS
# EXPORTS
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies(${HW_IF_INCLUDE_DEPENDS})
ament_package()
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ def generate_launch_description():


def launch_setup(context: LaunchContext) -> list[IncludeLaunchDescription]:

# tf_prefix is implicitly used in robot_state_publisher (in URDF substitution)
tf_prefix = LaunchConfiguration("tf_prefix", default="")
tf_prefix = LaunchConfiguration("tf_prefix", default="") # noqa: F841

return [
preapre_control_node(),
Expand Down Expand Up @@ -105,7 +104,8 @@ def preapre_control_node() -> Node:


def prepare_robot_state_publisher_node() -> Node:
tf_prefix = LaunchConfiguration("tf_prefix", default="")
# tf_prefix is implicitly used in ParameterValue()
tf_prefix = LaunchConfiguration("tf_prefix", default="") # noqa: F841
use_fake_hardware = LaunchConfiguration("use_fake_hardware")

robot_description_str = Command(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef ROBOTIQ_HANDE_DRIVER__HANDE_HARDWARE_INTERFACE_HPP_
#define ROBOTIQ_HANDE_DRIVER__HANDE_HARDWARE_INTERFACE_HPP_

#include <string>
#include <hardware_interface/system_interface.hpp>
#include <rclcpp/rclcpp.hpp>
#include <string>

namespace robotiq_hande_driver {

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

constexpr int LEFT_FINGER_JOINT_ID = 0;

class RobotiqHandeHardwareInterface : public HWI::SystemInterface
{
public:
class RobotiqHandeHardwareInterface : public HWI::SystemInterface {
public:
RobotiqHandeHardwareInterface();

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

rclcpp::Logger get_logger() const { return *logger_; }
rclcpp::Logger get_logger() const {
return *logger_;
}

private:
//TODO(modbus integration): composition of the modbus communication
private:
// TODO(modbus integration): composition of the modbus communication
std::shared_ptr<rclcpp::Logger> logger_;

std::string tty_port_;
Expand All @@ -44,5 +45,5 @@ class RobotiqHandeHardwareInterface : public HWI::SystemInterface
double cmd_position_;
};

} // namespace robotiq_hande_driver
} // namespace robotiq_hande_driver
#endif // ROBOTIQ_HANDE_DRIVER__HANDE_HARDWARE_INTERFACE_HPP_
67 changes: 40 additions & 27 deletions robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace robotiq_hande_driver {
RobotiqHandeHardwareInterface::RobotiqHandeHardwareInterface() {}

HWI::CallbackReturn RobotiqHandeHardwareInterface::on_init(const HWI::HardwareInfo& info) {
if (HWI::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) {
if(HWI::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) {
return HWI::CallbackReturn::ERROR;
}

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

logger_ = std::make_shared<rclcpp::Logger>(
rclcpp::get_logger("controller_manager.resource_manager.hardware_component.system.RobotiqHandeHardwareInterface"));
rclcpp::get_logger("controller_manager.resource_manager.hardware_"
"component.system.RobotiqHandeHardwareInterface"));

//TODO(modbus integration): Set parameters for the modbus communication
// TODO(modbus integration): Set parameters for the modbus communication

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

HWI::CallbackReturn RobotiqHandeHardwareInterface::on_configure(const rlccp_lc::State& /*previous_state*/){
//TODO(modbus integration): Initialize the ModbusRTU communication session
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_configure(
const rlccp_lc::State& /*previous_state*/) {
// TODO(modbus integration): Initialize the ModbusRTU communication session
RCLCPP_INFO(get_logger(), "configure()");
return HWI::CallbackReturn::SUCCESS;
}

HWI::CallbackReturn RobotiqHandeHardwareInterface::on_cleanup(const rlccp_lc::State& /*previous_state*/){
//TODO(modbus integration): Deinitalize the ModbusRTU session
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_cleanup(
const rlccp_lc::State& /*previous_state*/) {
// TODO(modbus integration): Deinitalize the ModbusRTU session
RCLCPP_INFO(get_logger(), "cleanup()");
return HWI::CallbackReturn::SUCCESS;
}
Expand All @@ -42,9 +45,13 @@ std::vector<HWI::StateInterface> RobotiqHandeHardwareInterface::export_state_int
std::vector<HWI::StateInterface> state_interfaces;

state_interfaces.emplace_back(hardware_interface::StateInterface(
info_.joints[LEFT_FINGER_JOINT_ID].name, hardware_interface::HW_IF_POSITION, &state_position_));
info_.joints[LEFT_FINGER_JOINT_ID].name,
hardware_interface::HW_IF_POSITION,
&state_position_));
state_interfaces.emplace_back(hardware_interface::StateInterface(
info_.joints[LEFT_FINGER_JOINT_ID].name, hardware_interface::HW_IF_VELOCITY, &state_velocity_));
info_.joints[LEFT_FINGER_JOINT_ID].name,
hardware_interface::HW_IF_VELOCITY,
&state_velocity_));

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

command_interfaces.emplace_back(hardware_interface::CommandInterface(
info_.joints[LEFT_FINGER_JOINT_ID].name, hardware_interface::HW_IF_POSITION, &cmd_position_));
info_.joints[LEFT_FINGER_JOINT_ID].name,
hardware_interface::HW_IF_POSITION,
&cmd_position_));

RCLCPP_INFO(get_logger(), "export_command_interfaces()");
return command_interfaces;
}

HWI::CallbackReturn RobotiqHandeHardwareInterface::on_activate(const rlccp_lc::State& /*previous_state*/){
//TODO(modbus integration): Power on the gripper (activation)
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_activate(
const rlccp_lc::State& /*previous_state*/) {
// TODO(modbus integration): Power on the gripper (activation)
RCLCPP_INFO(get_logger(), "activate()");
return HWI::CallbackReturn::SUCCESS;
}

HWI::CallbackReturn RobotiqHandeHardwareInterface::on_deactivate(const rlccp_lc::State& /*previous_state*/){
//TODO(modbus integration): Deactiavte the gripper (set the reset flag)
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_deactivate(
const rlccp_lc::State& /*previous_state*/) {
// TODO(modbus integration): Deactiavte the gripper (set the reset flag)
RCLCPP_INFO(get_logger(), "deactivate()");
return HWI::CallbackReturn::SUCCESS;
}

HWI::CallbackReturn RobotiqHandeHardwareInterface::on_shutdown(const rlccp_lc::State& /*previous_state*/){
//TODO(modbus integration): Deactivate the gripper, deinitalize the modbus RTU session,
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_shutdown(
const rlccp_lc::State& /*previous_state*/) {
// TODO(modbus integration): Deactivate the gripper, deinitalize the modbus
// RTU session,
RCLCPP_INFO(get_logger(), "shutdown()");
return HWI::CallbackReturn::SUCCESS;
}

HWI::CallbackReturn RobotiqHandeHardwareInterface::on_error(const rlccp_lc::State& /*previous_state*/){
//TODO(modbus integration): Placeholder for error handling
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_error(
const rlccp_lc::State& /*previous_state*/) {
// TODO(modbus integration): Placeholder for error handling
RCLCPP_INFO(get_logger(), "Handled error");
return HWI::CallbackReturn::SUCCESS;
}

HWI::return_type RobotiqHandeHardwareInterface::read(const rclcpp::Time& /*time*/,
const rclcpp::Duration& /*period*/) {
//TODO(modbus integration): data = driver_->receive_data();
HWI::return_type RobotiqHandeHardwareInterface::read(
const rclcpp::Time& /*time*/, const rclcpp::Duration& /*period*/) {
// TODO(modbus integration): data = driver_->receive_data();
return hardware_interface::return_type::OK;
}
HWI::return_type RobotiqHandeHardwareInterface::write(const rclcpp::Time& /*time*/,
const rclcpp::Duration& /*period*/) {
//TODO(modbus integration): driver_->send_data(cmd_position_);
HWI::return_type RobotiqHandeHardwareInterface::write(
const rclcpp::Time& /*time*/, const rclcpp::Duration& /*period*/) {
// TODO(modbus integration): driver_->send_data(cmd_position_);
return hardware_interface::return_type::OK;
}


} // namespace robotiq_hande_driver
} // namespace robotiq_hande_driver

#include "pluginlib/class_list_macros.hpp"
PLUGINLIB_EXPORT_CLASS(
robotiq_hande_driver::RobotiqHandeHardwareInterface, hardware_interface::SystemInterface)
robotiq_hande_driver::RobotiqHandeHardwareInterface, hardware_interface::SystemInterface)
Loading