Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
cc6e6e0
Feature/serial communication (#2)
slimasziom Feb 12, 2025
043c45d
Merge humble
slimasziom Feb 12, 2025
79914b6
CHG: move file directories to fit ros2 control
slimasziom Feb 12, 2025
89ca01f
CHG: update cmakelists and config layer for modbus session
slimasziom Feb 12, 2025
cc8b848
ADD: parametrization
slimasziom Feb 13, 2025
409e9a3
ADD: parameters to test_load_hw_interface
slimasziom Feb 13, 2025
f0d1000
ADD: activation based on is_ready flag
slimasziom Feb 13, 2025
e12d630
FIX: pre-commit
slimasziom Feb 13, 2025
3561eaa
CHG: initialize cmd and state position to gripper position max
slimasziom Feb 18, 2025
cc5552e
FIX: unify namespace tag
slimasziom Feb 18, 2025
6680d0a
ADD: max iterations for activation
slimasziom Feb 19, 2025
891e5b0
ADD: return config result to hardware layer
slimasziom Feb 19, 2025
147bf36
FIX: string pointer pass to modbus
slimasziom Feb 20, 2025
7b139fc
FIX: merge issues
slimasziom Feb 20, 2025
728e7ad
FIX: issues just before successful run
slimasziom Feb 25, 2025
0c6f9a3
Merge branch 'serial_communication_fixes' into serial_communication-d…
slimasziom Feb 25, 2025
99d223f
CHG: precommit-fixes
slimasziom Feb 25, 2025
e05f1d7
Update robotiq_hande_driver/CHANGELOG.md
slimasziom Feb 25, 2025
77c94f9
Update README.md
slimasziom Feb 25, 2025
c8866ff
Update robotiq_hande_driver/CMakeLists.txt
slimasziom Feb 25, 2025
dfb1018
Update robotiq_hande_driver/CMakeLists.txt
slimasziom Feb 25, 2025
5ee887e
Update robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp
slimasziom Feb 25, 2025
05b24ce
Update robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp
slimasziom Feb 25, 2025
da6f590
Update robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp
slimasziom Feb 25, 2025
0a7378f
Update robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp
slimasziom Feb 25, 2025
e6c3eaf
Update robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp
slimasziom Feb 25, 2025
ce3e1ab
Update robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp
slimasziom Feb 25, 2025
c8a8a2c
Update robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp
slimasziom Feb 25, 2025
ec5e355
Update robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp
slimasziom Feb 25, 2025
7c78d81
CHG: review suggestions
slimasziom Feb 25, 2025
30dc08e
CHG: return connection status code to hardware info
slimasziom Feb 25, 2025
9e83533
ADD: modbus failure status code
slimasziom Feb 25, 2025
c386689
CHG: activation logic moved to hardware_interface
slimasziom Feb 25, 2025
c04b706
FIX: wait_100ms declaration
slimasziom Feb 25, 2025
a9bc501
CHG: print modbus config in hardware_interface
slimasziom Feb 25, 2025
08e8c54
CHG: remove obsolete logger_
slimasziom Feb 25, 2025
cf1e105
ADD: log throttled when activating
slimasziom Feb 25, 2025
af5be05
CHG: move clock init to on_init
slimasziom Feb 25, 2025
203ea01
CHG: replace constexpr with static constexpr
slimasziom Feb 26, 2025
8268493
ADD: ignore modbus connection check
slimasziom Feb 26, 2025
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ ros2 launch robotiq_hande_driver gripper_controller_preview.launch.py use_fake_h

### Test Serial Connection

Another terminal
There is an additional test tool with hardcoded parameters to test the connection with the Hand-E without any ROS dependencies.
Before build, change the hardcoded parameters in the beginning of the `robotiq_hande_driver/test/communication_test.cpp` file.

To run test:
```bash
cd cd ~/ceai_ws/src/robotiq_hande_driver/build/robotiq_hande_driver/
./communication_test
./hande_driver
```

---
Expand Down
2 changes: 2 additions & 0 deletions robotiq_hande_driver/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* [PR-7](https://github.com/AGH-CEAI/robotiq_hande_driver/pull/7) - Integration of ModbusRTU communication with ros2_control Hardware Interface
* [PR-2](https://github.com/AGH-CEAI/robotiq_hande_driver/pull/2) - ModbusRTU communication
* [PR-2](https://github.com/AGH-CEAI/robotiq_hande_driver/pull/2) - Protocol abstraction
* [PR-1](https://github.com/AGH-CEAI/robotiq_hande_driver/pull/1) - Prepared ros2_control Hardware Interface.

### Changed

Expand Down
39 changes: 10 additions & 29 deletions robotiq_hande_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ endif()
include(FindPkgConfig)
pkg_check_modules(LIBMODBUS REQUIRED libmodbus)

set(DEPENDS
modbus
)
set(DEPENDS modbus)

set(HW_IF_INCLUDE_DEPENDS
fmt
hardware_interface
pluginlib
rclcpp
Expand All @@ -23,23 +20,17 @@ set(HW_IF_INCLUDE_DEPENDS

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
hardware/src/application.cpp
hardware/src/communication.cpp
hardware/src/protocol_logic.cpp
)
add_library(
${PROJECT_NAME} SHARED hardware/src/hande_hardware_interface.cpp hardware/src/application.cpp
hardware/src/communication.cpp hardware/src/protocol_logic.cpp)

target_link_libraries(${PROJECT_NAME}
PUBLIC
modbus
)
target_link_libraries(${PROJECT_NAME} PUBLIC ${DEPENDS})

# TODO(issue#8) Build the communication_test only with BUILD_TESTING flag
add_executable(communication_test test/communication_test.cpp)
target_link_libraries(communication_test ${catkin_LIBRARIES} ${DEPENDS})

Expand All @@ -61,10 +52,6 @@ install(
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

# include_directories(hardware/include/robotiq_hande_driver)
# add_executable(application_test test/application_test.cpp hardware/src/application.cpp hardware/src/communication.cpp hardware/src/protocol_logic.cpp)
# target_link_libraries(application_test ${catkin_LIBRARIES} ${DEPENDS})

if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)
# find_package(ament_cmake_pytest REQUIRED)
Expand All @@ -73,15 +60,9 @@ if(BUILD_TESTING)
ament_add_gmock(test_load_hw_interface test/test_load_hw_interface.cpp)
target_link_libraries(test_load_hw_interface ${PROJECT_NAME})

# ament_add_gmock(application_test
# test/application_test.cpp
# )
# TODO(issue#8) Build the communication_test only with BUILD_TESTING flag
# ament_add_gmock(application_test test/application_test.cpp )
# target_link_libraries(application_test ${PROJECT_NAME})

# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

#include "protocol_logic.hpp"


namespace robotiq_hande_driver
{
namespace robotiq_hande_driver {

constexpr auto GRIPPER_CURRENT_SCALE = 0.01;
constexpr auto MAX_SPEED = 255;
Expand All @@ -18,8 +16,7 @@ constexpr auto MAX_FORCE = 255;
* @brief This class contains high-level gripper commands and status.
*/
class GripperApplication {
public:

public:
struct Status {
bool is_reset;
bool is_ready;
Expand Down Expand Up @@ -50,9 +47,18 @@ class GripperApplication {
* @param stop_bit Modbus serial stopbit.
* @param slave_id Modbus slave id.
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void initialize(double gripper_position_min, double gripper_position_max, std::string tty_port, int baudrate, char parity, int data_bits, int stop_bit, int slave_id) {
void initialize(
double gripper_position_min,
double gripper_position_max,
const std::string& tty_port,
int baudrate,
char parity,
int data_bits,
int stop_bit,
int slave_id) {
gripper_position_min_ = gripper_position_min;
gripper_position_max_ = gripper_position_max;
gripper_postion_step_ = (gripper_position_max_ - gripper_position_min_) / 255.0;
Expand All @@ -61,8 +67,9 @@ class GripperApplication {

/**
* @brief Configures driver session.
* @return int, when error <0.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @return int Connection status code.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
int configure() {
int result;
Expand All @@ -77,7 +84,8 @@ class GripperApplication {
*
* @param none
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void cleanup() {
protocol_logic_.cleanup();
Expand All @@ -88,7 +96,8 @@ class GripperApplication {
*
* @param none
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void stop() {
protocol_logic_.stop();
Expand All @@ -99,7 +108,8 @@ class GripperApplication {
*
* @param none
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void reset() {
protocol_logic_.reset();
Expand All @@ -110,7 +120,8 @@ class GripperApplication {
*
* @param none
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void auto_release() {
protocol_logic_.auto_release();
Expand All @@ -119,46 +130,33 @@ class GripperApplication {
/**
* @brief Activates the gripper, making it ready for use.
*
* @param blocking If true wait until the gripper is active.
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void activate(bool blocking=true) {
int iter = 0;
read();

if (status_.is_ready)
printf("Gripper already active\n");
else {
printf("Activation in progress\n");
protocol_logic_.activate();

while(!status_.is_ready && blocking) {
printf("Waiting another 100ms, attempt: %d\n", iter);
usleep(100 * 1000);
read();
if(iter++ > 100) break;
}
}
void activate() {
protocol_logic_.activate();
};

/**
* @brief Deactivates the gripper.
*
* @param none
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void deactivate() {
protocol_logic_.reset();
};

/**
/**
* @brief Deactivates the gripper.
*
* @param none
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void shutdown() {
deactivate();
Expand All @@ -170,7 +168,8 @@ class GripperApplication {
*
* @param none
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void open() {
set_position(gripper_position_max_);
Expand All @@ -181,7 +180,8 @@ class GripperApplication {
*
* @param none
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void close() {
set_position(gripper_position_min_);
Expand All @@ -192,7 +192,8 @@ class GripperApplication {
*
* @param none
* @return The current gripper status.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
Status get_status() {
return status_;
Expand All @@ -203,7 +204,8 @@ class GripperApplication {
*
* @param none
* @return The current gripper fault status.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
FaultStatus get_fault_status() {
return fault_status_;
Expand All @@ -214,18 +216,20 @@ class GripperApplication {
*
* @param none
* @return The requested gripper position in meters.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
double get_requested_position() {
return requested_position_;
return requested_position_;
};

/**
* @brief Retrieves the actual position of the gripper.
*
* @param none
* @return The actual gripper position in meters.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
double get_position() {
return position_;
Expand All @@ -236,20 +240,24 @@ class GripperApplication {
*
* @param position The target position in meters.
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void set_position(double position, double force=1.0) {
void set_position(double position, double force = 1.0) {
uint8_t scaled_force = static_cast<uint8_t>(force * MAX_FORCE);
protocol_logic_.go_to(
(uint8_t)((gripper_position_max_ - position) / gripper_postion_step_), MAX_SPEED, scaled_force);
(uint8_t)((gripper_position_max_ - position) / gripper_postion_step_),
MAX_SPEED,
scaled_force);
};

/**
* @brief Retrieves the electric current drawn by the gripper.
*
* @param none
* @return The electric current in amperes (range: 0–2.55 A)
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
double get_current() {
return current_;
Expand All @@ -260,7 +268,8 @@ class GripperApplication {
*
* @param none
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void read();

Expand All @@ -269,13 +278,14 @@ class GripperApplication {
*
* @param none
* @return None.
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
* @note The status should be checked to verify successful execution. An exception is thrown if
* communication issues occur.
*/
void write() {
protocol_logic_.refresh_registers();
};

private:
private:
/**
* Handles protocol logic for mid-level abstraction.
*/
Expand Down Expand Up @@ -309,7 +319,6 @@ class GripperApplication {
double gripper_position_min_;
double gripper_position_max_;
double gripper_postion_step_;

};
} // namespace robotiq_hande_driver
} // namespace robotiq_hande_driver
#endif // ROBOTIQ_HANDE_DRIVER__APPLICATION_HPP_
Loading