Skip to content

Commit 89ca01f

Browse files
committed
CHG: update cmakelists and config layer for modbus session
1 parent 79914b6 commit 89ca01f

File tree

8 files changed

+190
-45
lines changed

8 files changed

+190
-45
lines changed

robotiq_hande_driver/CMakeLists.txt

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
55
add_compile_options(-Wall -Wextra -Wpedantic)
66
endif()
77

8+
include(FindPkgConfig)
9+
pkg_check_modules(LIBMODBUS REQUIRED libmodbus)
10+
11+
set(DEPENDS
12+
modbus
13+
)
14+
815
set(HW_IF_INCLUDE_DEPENDS
916
fmt
1017
hardware_interface
@@ -25,28 +32,9 @@ add_library(${PROJECT_NAME}
2532
hardware/src/hande_hardware_interface.cpp
2633
)
2734

28-
include(FindPkgConfig)
29-
pkg_check_modules(LIBMODBUS REQUIRED libmodbus)
30-
31-
set(DEPENDS
32-
modbus
33-
)
34-
35-
include_directories(
36-
"include"
37-
"src"
38-
)
39-
40-
add_executable(hande_driver src/hande_driver.cpp src/application.cpp src/protocol_logic.cpp src/communication.cpp)
41-
target_link_libraries(hande_driver ${catkin_LIBRARIES} ${DEPENDS})
42-
43-
add_executable(communication_test src/communication_test.cpp)
35+
add_executable(communication_test test/communication_test.cpp)
4436
target_link_libraries(communication_test ${catkin_LIBRARIES} ${DEPENDS})
4537

46-
target_include_directories(hande_driver PUBLIC
47-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
48-
$<INSTALL_INTERFACE:include>)
49-
5038
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
5139
target_include_directories(robotiq_hande_driver PUBLIC
5240
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hardware/include>

robotiq_hande_driver/hardware/include/robotiq_hande_driver/application.hpp

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "protocol_logic.hpp"
77

88

9-
namespace hande_driver
9+
namespace robotiq_hande_driver
1010
{
1111

1212
constexpr auto GRIPPER_POSITION_MIN = 0.0;
@@ -19,7 +19,7 @@ constexpr auto MAX_FORCE = 255;
1919
/**
2020
* @brief This class contains high-level gripper commands and status.
2121
*/
22-
class ApplicationLayer {
22+
class GripperApplication {
2323
public:
2424

2525
struct Status {
@@ -36,9 +36,40 @@ class ApplicationLayer {
3636
bool is_error;
3737
};
3838

39-
ApplicationLayer();
39+
GripperApplication();
4040

41-
~ApplicationLayer() {};
41+
~GripperApplication() {};
42+
43+
/**
44+
* @brief Initializes driver parameters.
45+
*
46+
* @param tty_port modbus virtual port
47+
* @return None.
48+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
49+
*/
50+
void initialize(std::string tty_port) {
51+
protocol_logic_.initialize(tty_port);
52+
};
53+
54+
/**
55+
* @brief Configures driver session.
56+
* @return None.
57+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
58+
*/
59+
void configure() {
60+
protocol_logic_.configure();
61+
};
62+
63+
/**
64+
* @brief Deinitializes driver.
65+
*
66+
* @param none
67+
* @return None.
68+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
69+
*/
70+
void cleanup() {
71+
protocol_logic_.cleanup();
72+
};
4273

4374
/**
4475
* @brief Stops the gripper movement.
@@ -84,6 +115,29 @@ class ApplicationLayer {
84115
protocol_logic_.activate();
85116
};
86117

118+
/**
119+
* @brief Deactivates the gripper.
120+
*
121+
* @param none
122+
* @return None.
123+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
124+
*/
125+
void deactivate() {
126+
protocol_logic_.reset();
127+
};
128+
129+
/**
130+
* @brief Deactivates the gripper.
131+
*
132+
* @param none
133+
* @return None.
134+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
135+
*/
136+
void shutdown() {
137+
deactivate();
138+
cleanup();
139+
};
140+
87141
/**
88142
* @brief Opens the gripper.
89143
*
@@ -225,5 +279,5 @@ class ApplicationLayer {
225279
double current_;
226280

227281
};
228-
} // namespace hande_driver
282+
} // namespace robotiq_hande_driver
229283
#endif // APPLICATION_HPP_

robotiq_hande_driver/hardware/include/robotiq_hande_driver/communication.hpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
#include <modbus/modbus.h>
55
#include <cstring>
6+
#include <string>
67

78

8-
namespace hande_driver
9+
namespace robotiq_hande_driver
910
{
1011

1112
constexpr auto DEVICE_NAME = "/tmp/ttyUR";
@@ -50,6 +51,42 @@ class Communication{
5051
Communication();
5152

5253
~Communication() {
54+
cleanup();
55+
};
56+
57+
/**
58+
* @brief Initializes driver parameters.
59+
*
60+
* @param none
61+
* @return None.
62+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
63+
*/
64+
void initialize(std::string tty_port) {
65+
tty_port_ = tty_port.c_str();
66+
};
67+
68+
/**
69+
* @brief Initializes communication layer.
70+
*
71+
* @param none
72+
* @return None.
73+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
74+
*/
75+
void configure() {
76+
mb_ = modbus_new_rtu(tty_port_, BAUDRATE, PARITY, DATA_BITS, STOP_BIT);
77+
modbus_set_slave(mb_, SLAVE_ID);
78+
modbus_set_debug(mb_, DEBUG_MODBUS);
79+
connect();
80+
};
81+
82+
/**
83+
* @brief Deinitializes communication layer.
84+
*
85+
* @param none
86+
* @return None.
87+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
88+
*/
89+
void cleanup() {
5390
disconnect();
5491
modbus_free(mb_);
5592
};
@@ -165,11 +202,12 @@ class Communication{
165202
};
166203

167204
private:
205+
const char* tty_port_;
168206
modbus_t *mb_;
169207

170208
uint8_t input_bytes_[static_cast<size_t>(InputBytes::BYTES_MAX)];
171209
uint8_t output_bytes_[static_cast<size_t>(OutputBytes::BYTES_MAX)];
172210

173211
};
174-
} // namespace hande_driver
212+
} // namespace robotiq_hande_driver
175213
#endif // COMMUNICATION_HPP_

robotiq_hande_driver/hardware/include/robotiq_hande_driver/hande_hardware_interface.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <hardware_interface/system_interface.hpp>
66
#include <rclcpp/rclcpp.hpp>
77

8+
#include "application.hpp"
9+
810
namespace robotiq_hande_driver {
911

1012
namespace HWI = hardware_interface;
@@ -35,7 +37,8 @@ class RobotiqHandeHardwareInterface : public HWI::SystemInterface
3537
rclcpp::Logger get_logger() const { return *logger_; }
3638

3739
private:
38-
//TODO(modbus integration): composition of the modbus communication
40+
//--TODO(modbus integration): composition of the modbus communication
41+
GripperApplication application_layer_;
3942
std::shared_ptr<rclcpp::Logger> logger_;
4043

4144
std::string tty_port_;

robotiq_hande_driver/hardware/include/robotiq_hande_driver/protocol_logic.hpp

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#ifndef PROTOCOL_LOGIC_HPP_
22
#define PROTOCOL_LOGIC_HPP_
33

4-
#include <communication.hpp>
4+
#include <string>
55

6+
#include "communication.hpp"
67

7-
namespace hande_driver
8+
9+
namespace robotiq_hande_driver
810
{
911

1012
/* Register mapping done based on Hand-E documentation:
@@ -92,6 +94,48 @@ class ProtocolLogic{
9294

9395
~ProtocolLogic() {};
9496

97+
/**
98+
* @brief Initializes driver parameters.
99+
*
100+
* @param tty_port modbus virtual port
101+
* @return None.
102+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
103+
*/
104+
void initialize(std::string tty_port) {
105+
communication_.initialize(tty_port);
106+
// communication_.configure();
107+
};
108+
109+
/**
110+
* @brief Configures protocol layer.
111+
*
112+
* @param none
113+
* @return None.
114+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
115+
*/
116+
void configure() {
117+
activation_status_ = ActivationStatus::GRIPPER_RESET;
118+
action_status_ = ActionStatus::STOPPED;
119+
gripper_status_ = GripperStatus::NOT_USED;
120+
object_detection_status_ = ObjectDetectionStatus::REQ_POS_NO_OBJECT;
121+
fault_status_ = 0;
122+
position_request_echo_ = 0;
123+
position_ = 0;
124+
current_ = 0;
125+
communication_.configure();
126+
};
127+
128+
/**
129+
* @brief Deinitializes protocol layer.
130+
*
131+
* @param none
132+
* @return None.
133+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
134+
*/
135+
void cleanup() {
136+
communication_.cleanup();
137+
};
138+
95139
/**
96140
* @brief Resets the gripper.
97141
*
@@ -145,6 +189,17 @@ class ProtocolLogic{
145189
set();
146190
};
147191

192+
/**
193+
* @brief Deactivates the gripper.
194+
*
195+
* @param none
196+
* @return None.
197+
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
198+
*/
199+
void deactivate() {
200+
reset();
201+
};
202+
148203
/**
149204
* @brief Moves the gripper to the requested position with specified velocity and force.
150205
*
@@ -304,5 +359,5 @@ class ProtocolLogic{
304359

305360
Communication communication_;
306361
};
307-
} // namespace hande_driver
362+
} // namespace robotiq_hande_driver
308363
#endif // PROTOCOL_LOGIC_HPP_

robotiq_hande_driver/hardware/src/application.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
namespace hande_driver {
77

8-
ApplicationLayer::ApplicationLayer()
8+
GripperApplication::GripperApplication()
99
: requested_position_()
1010
, position_()
1111
, current_()
1212
{
1313
}
1414

15-
void ApplicationLayer::read(){
15+
void GripperApplication::read(){
1616
protocol_logic_.refresh_registers();
1717

1818
status_.is_reset = protocol_logic_.is_reset();

robotiq_hande_driver/hardware/src/communication.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ Communication::Communication()
99
: input_bytes_{}
1010
, output_bytes_{}
1111
{
12-
mb_ = modbus_new_rtu(DEVICE_NAME, BAUDRATE, PARITY, DATA_BITS, STOP_BIT);
13-
modbus_set_slave(mb_, SLAVE_ID);
14-
modbus_set_debug(mb_, DEBUG_MODBUS);
15-
connect();
12+
1613
}
1714

1815
void Communication::connect(){

0 commit comments

Comments
 (0)