Skip to content

Commit e4b0803

Browse files
committed
CHG: move most definitions to header files
1 parent 3e24a13 commit e4b0803

File tree

6 files changed

+174
-274
lines changed

6 files changed

+174
-274
lines changed

robotiq_hande_driver/include/application.hpp

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
namespace hande_driver
1010
{
1111

12+
constexpr auto kGripperPositionMin = 0.0;
13+
constexpr auto kGripperPositionMax = 0.05;
14+
constexpr auto kGripperPositionStep = (kGripperPositionMax - kGripperPositionMin) / 255.0;
15+
constexpr auto kGripperCurrentScale = 0.01;
16+
constexpr auto kMaxSpeed = 255;
17+
constexpr auto kMaxForce = 255;
1218

1319
/**
1420
* @brief This class contains high level gripper commands and status
@@ -32,7 +38,7 @@ class ApplicationLayer{
3238

3339
ApplicationLayer();
3440

35-
~ApplicationLayer();
41+
~ApplicationLayer() {};
3642

3743
/**
3844
* @brief Stops movement of the gripper
@@ -41,7 +47,9 @@ class ApplicationLayer{
4147
* @return none
4248
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
4349
*/
44-
void stop();
50+
void stop() {
51+
protocol_logic_.stop();
52+
};
4553

4654
/**
4755
* @brief Resets the gripper: deactivate and activate again
@@ -50,7 +58,9 @@ class ApplicationLayer{
5058
* @return none
5159
* @note see status on success, exception thrown if communicatoin issues
5260
*/
53-
void reset();
61+
void reset() {
62+
protocol_logic_.reset();
63+
};
5464

5565
/**
5666
* Emergency auto-release, gripper fingers are slowly opened, reactivation necessary
@@ -59,7 +69,9 @@ class ApplicationLayer{
5969
* @return none
6070
* @note see status on success, exception thrown if communicatoin issues
6171
*/
62-
void auto_release();
72+
void auto_release() {
73+
protocol_logic_.auto_release();
74+
};
6375

6476
/**
6577
* @brief Activates the gripper, after that it can be used
@@ -68,7 +80,9 @@ class ApplicationLayer{
6880
* @return none
6981
* @note see status on success, exception thrown if communicatoin issues
7082
*/
71-
void activate();
83+
void activate() {
84+
protocol_logic_.activate();
85+
};
7286

7387
/**
7488
* @brief Opens the gripper
@@ -77,7 +91,9 @@ class ApplicationLayer{
7791
* @return none
7892
* @note see status on success, exception thrown if communicatoin issues
7993
*/
80-
void open();
94+
void open() {
95+
set_position(kGripperPositionMax);
96+
};
8197

8298
/**
8399
* @brief Closes the gripper
@@ -86,7 +102,9 @@ class ApplicationLayer{
86102
* @return none
87103
* @note see status on success, exception thrown if communicatoin issues
88104
*/
89-
void close();
105+
void close() {
106+
set_position(kGripperPositionMin);
107+
};
90108

91109
/**
92110
* @brief Returns the gripper status
@@ -95,7 +113,9 @@ class ApplicationLayer{
95113
* @return Gripper status
96114
* @note see status on success, exception thrown if communicatoin issues
97115
*/
98-
Status get_status();
116+
Status get_status() {
117+
return status_;
118+
};
99119

100120
/**
101121
* @brief Returns the gripper fault status
@@ -104,7 +124,9 @@ class ApplicationLayer{
104124
* @return Fault Status
105125
* @note see status on success, exception thrown if communicatoin issues
106126
*/
107-
FaultStatus get_fault_status();
127+
FaultStatus get_fault_status() {
128+
return fault_status_;
129+
};
108130

109131
/**
110132
* @brief Returns the gripper requested position
@@ -113,7 +135,9 @@ class ApplicationLayer{
113135
* @return Gripper requested position
114136
* @note see status on success, exception thrown if communicatoin issues
115137
*/
116-
double get_requested_position();
138+
double get_requested_position() {
139+
return requested_position_;
140+
};
117141

118142
/**
119143
* @brief Returns the gripper position
@@ -122,7 +146,9 @@ class ApplicationLayer{
122146
* @return Gripper position in [m]
123147
* @note see status on success, exception thrown if communicatoin issues
124148
*/
125-
double get_position();
149+
double get_position() {
150+
return position_;
151+
};
126152

127153
/**
128154
* @brief Moves the gripper to requested position
@@ -131,7 +157,10 @@ class ApplicationLayer{
131157
* @return none
132158
* @note see status on success, exception thrown if communicatoin issues
133159
*/
134-
void set_position(double position);
160+
void set_position(double position) {
161+
protocol_logic_.go_to(
162+
(uint8_t)((kGripperPositionMax - position) / kGripperPositionStep), kMaxSpeed, kMaxForce);
163+
};
135164

136165
/**
137166
* @brief Returns the gripper current
@@ -140,12 +169,15 @@ class ApplicationLayer{
140169
* @return Gripper current in [A] (range: 0-2.55A)
141170
* @note see status on success, exception thrown if communicatoin issues
142171
*/
143-
double get_current();
144-
172+
double get_current() {
173+
return current_;
174+
};
145175

146176
void read();
147177

148-
void write();
178+
void write() {
179+
protocol_logic_.refresh_registers();
180+
};
149181

150182
private:
151183
/**

robotiq_hande_driver/include/communication.hpp

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@
22
#define COMMUNICATION_HPP_
33

44
#include <modbus/modbus.h>
5+
#include <string.h>
56

67

7-
namespace hande_driver
8+
namespace hande_driver
89
{
10+
11+
constexpr auto kDeviceName = "/tmp/ttyUR";
12+
constexpr auto kBaudrate = 115200;
13+
constexpr auto kParity = 'N';
14+
constexpr auto kDataBits = 8;
15+
constexpr auto kStopBit = 1;
16+
constexpr auto kDebugModbus = true;
17+
constexpr uint8_t kSlaveID = 0x09;
18+
19+
constexpr uint16_t kGripperOutputFirstReg = 0x07D0;
20+
constexpr uint16_t kGripperInputFirstReg = 0x03E8;
21+
922
constexpr auto kRegisterWordLength = 3;
1023
enum class OutputBytes : uint8_t {
1124
RESERVED_1 = 0u,
@@ -35,7 +48,10 @@ class Communication{
3548
public:
3649
Communication();
3750

38-
~Communication();
51+
~Communication() {
52+
disconnect();
53+
modbus_free(mb_);
54+
};
3955

4056
/**
4157
* @brief Connect to gripper using modbus rtu and virtual socket
@@ -53,7 +69,9 @@ class Communication{
5369
* @return none
5470
* @note see status on success, exception thrown in case of communication issues
5571
*/
56-
void disconnect();
72+
void disconnect() {
73+
modbus_close(mb_);
74+
};
5775

5876
/**
5977
* @brief Read and write input.output registers at once
@@ -62,7 +80,28 @@ class Communication{
6280
* @return none
6381
* @note see status on success, exception thrown in case of communication issues
6482
*/
65-
void read_write_registers();
83+
void read_write_registers() {
84+
/**
85+
* @brief Read and write modbus registers at once
86+
*
87+
* @param modbus_t *ctx
88+
* @param int write_addr
89+
* @param int write_nb
90+
* @param uint16_t *src
91+
* @param int read_addr
92+
* @param int read_nb
93+
* @param uint16_t *dest
94+
* @return int >0 on success
95+
* @note see status on success, exception thrown in case of communication issues
96+
*/
97+
modbus_write_and_read_registers(mb_,
98+
kGripperInputFirstReg,
99+
kRegisterWordLength,
100+
(uint16_t *)output_bytes_,
101+
kGripperOutputFirstReg,
102+
kRegisterWordLength,
103+
(uint16_t *)input_bytes_);
104+
};
66105

67106
/**
68107
* @brief Set output bytes to zeros
@@ -71,7 +110,9 @@ class Communication{
71110
* @return none
72111
* @note see status on success, exception thrown in case of communication issues
73112
*/
74-
void clear_output_bytes();
113+
void clear_output_bytes() {
114+
memset(output_bytes_, 0, sizeof(output_bytes_));
115+
};
75116

76117
/**
77118
* @brief Get input byte value
@@ -80,7 +121,9 @@ class Communication{
80121
* @return requested byte value
81122
* @note see status on success, exception thrown in case of communication issues
82123
*/
83-
uint8_t get_input_byte(InputBytes index);
124+
uint8_t get_input_byte(InputBytes index) {
125+
return input_bytes_[(uint)index];
126+
};
84127

85128
/**
86129
* @brief Set output byte value
@@ -90,7 +133,9 @@ class Communication{
90133
* @return none
91134
* @note see status on success, exception thrown in case of communication issues
92135
*/
93-
void set_output_byte(OutputBytes index, uint8_t value);
136+
void set_output_byte(OutputBytes index, uint8_t value) {
137+
output_bytes_[(uint)index] = value;
138+
};
94139

95140
/**
96141
* @brief Set n-th bit to action request byte
@@ -99,7 +144,10 @@ class Communication{
99144
* @param value bool value
100145
* @return none
101146
*/
102-
void write_action_bit(uint8_t position_bit, bool value);
147+
void write_action_bit(uint8_t position_bit, bool value) {
148+
output_bytes_[(uint)OutputBytes::ACTION_REQUEST] = bit_set_to(
149+
output_bytes_[(uint)OutputBytes::ACTION_REQUEST], position_bit, value);
150+
};
103151

104152
/**
105153
* @brief Set n-th bit to x value
@@ -109,7 +157,9 @@ class Communication{
109157
* @param x bool value
110158
* @return uint number with n-th bit set to x
111159
*/
112-
uint bit_set_to(uint number, uint n, bool x);
160+
uint bit_set_to(uint number, uint n, bool x) {
161+
return (number & ~((uint)1 << n)) | ((uint)x << n);
162+
};
113163

114164
private:
115165
modbus_t *mb_;

0 commit comments

Comments
 (0)