Skip to content

Commit 673aeb2

Browse files
committed
ADD: connection confirmation and remove bit shift in communication
1 parent bd70dfb commit 673aeb2

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

robotiq_hande_driver/include/communication.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ class Communication{
9494
*/
9595
void set_output_byte(OutputBytes index, uint8_t value);
9696

97-
// uint16_t input_registers_[kRegisterWordLength];
98-
// uint16_t output_registers_[kRegisterWordLength];
99-
10097
/**
10198
* @brief Set n-th bit to action request byte
10299
*

robotiq_hande_driver/src/communication.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ constexpr uint16_t kGripperOutputFirstReg = 0x07D0;
1919
constexpr uint16_t kGripperInputFirstReg = 0x03E8;
2020

2121
Communication::Communication()
22-
// : input_registers_{0, 0, 0}
23-
// , output_registers_{0, 0, 0}
2422
: input_bytes_{0, 0, 0, 0, 0, 0}
2523
, output_bytes_{0, 0, 0, 0, 0, 0}
2624
{
@@ -38,17 +36,35 @@ Communication::~Communication(){
3836
}
3937

4038
void Communication::connect(){
39+
uint16_t activation_status[1] = {0x0000};
40+
4141
modbus_connect(mb_);
4242

43-
//TODO: send read/write and verify gripper is responding
43+
if (modbus_read_registers(mb_, kGripperOutputFirstReg, 1, activation_status) > 0) {
44+
printf("Connected successfully");
45+
} else {
46+
printf("Couldn't connect");
47+
}
4448
}
4549

4650
void Communication::disconnect(){
4751
modbus_close(mb_);
4852
}
4953

5054
void Communication::read_write_registers(){
51-
// TODO: add description
55+
/**
56+
* @brief Read and write modbus registers at once
57+
*
58+
* @param modbus_t *ctx
59+
* @param int write_addr
60+
* @param int write_nb
61+
* @param uint16_t *src
62+
* @param int read_addr
63+
* @param int read_nb
64+
* @param uint16_t *dest
65+
* @return int >0 on success
66+
* @note see status on success, exception thrown in case of communication issues
67+
*/
5268
modbus_write_and_read_registers(mb_,
5369
kGripperInputFirstReg,
5470
kRegisterWordLength,
@@ -72,7 +88,7 @@ void Communication::set_output_byte(OutputBytes index, uint8_t value){
7288

7389
void Communication::write_action_bit(uint8_t position_bit, bool value){
7490
output_bytes_[OUTPUT_BYTES_ACTION_REQUEST] = bit_set_to(
75-
output_bytes_[OUTPUT_BYTES_ACTION_REQUEST], 8 + position_bit, value);
91+
output_bytes_[OUTPUT_BYTES_ACTION_REQUEST], position_bit, value);
7692
}
7793

7894
inline uint Communication::bit_set_to(uint number, uint n, bool x) {

0 commit comments

Comments
 (0)