Skip to content

Commit 0c6f9a3

Browse files
committed
Merge branch 'serial_communication_fixes' into serial_communication-devel
2 parents 7b139fc + 728e7ad commit 0c6f9a3

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

robotiq_hande_driver/hardware/include/robotiq_hande_driver/application.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class GripperApplication {
5252
* @return None.
5353
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
5454
*/
55-
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) {
55+
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) {
5656
gripper_position_min_ = gripper_position_min;
5757
gripper_position_max_ = gripper_position_max;
5858
gripper_postion_step_ = (gripper_position_max_ - gripper_position_min_) / 255.0;

robotiq_hande_driver/hardware/include/robotiq_hande_driver/communication.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class Communication{
6060
* @return None.
6161
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
6262
*/
63-
void initialize(std::string tty_port, int baudrate, char parity, int data_bits, int stop_bit, int slave_id) {
63+
void initialize(std::string& tty_port, int baudrate, char parity, int data_bits, int stop_bit, int slave_id) {
64+
6465
tty_port_ = tty_port.c_str();
6566
baudrate_ = baudrate;
6667
parity_ = parity;
@@ -79,6 +80,7 @@ class Communication{
7980
int configure() {
8081
int result;
8182

83+
printf("Connecting to: %s, %d, %c, %d, %d\n", tty_port_, baudrate_, parity_, data_bits_, stop_bit_);
8284
mb_ = modbus_new_rtu(tty_port_, baudrate_, parity_, data_bits_, stop_bit_);
8385
modbus_set_slave(mb_, slave_id_);
8486
modbus_set_debug(mb_, DEBUG_MODBUS);

robotiq_hande_driver/hardware/include/robotiq_hande_driver/protocol_logic.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ProtocolLogic{
106106
* @return None.
107107
* @note The status should be checked to verify successful execution. An exception is thrown if communication issues occur.
108108
*/
109-
void initialize(std::string tty_port, int baudrate, char parity, int data_bits, int stop_bit, int slave_id) {
109+
void initialize(std::string& tty_port, int baudrate, char parity, int data_bits, int stop_bit, int slave_id) {
110110
communication_.initialize(tty_port, baudrate, parity, data_bits, stop_bit, slave_id);
111111
};
112112

robotiq_hande_driver/hardware/src/communication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ int Communication::connect(){
2525
else
2626
printf("Couldn't connect: %d\n", result);
2727

28-
return result;
28+
return 1;
2929
}
3030
} // namespace robotiq_hande_driver

robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@ HWI::CallbackReturn RobotiqHandeHardwareInterface::on_init(const HWI::HardwareIn
1111
if(HWI::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) {
1212
return HWI::CallbackReturn::ERROR;
1313
}
14+
logger_ = std::make_shared<rclcpp::Logger>(
15+
rclcpp::get_logger("controller_manager.resource_manager.hardware_component.system.RobotiqHandeHardwareInterface"));
16+
17+
18+
RCLCPP_DEBUG(get_logger(), "grip_pos_min: %s", info_.hardware_parameters["grip_pos_min"].c_str());
19+
RCLCPP_DEBUG(get_logger(), "grip_pos_max: %s", info_.hardware_parameters["grip_pos_max"].c_str());
20+
RCLCPP_DEBUG(get_logger(), "tty: %s", info_.hardware_parameters["tty"].c_str());
21+
RCLCPP_DEBUG(get_logger(), "baudrate: %s", info_.hardware_parameters["baudrate"].c_str());
22+
RCLCPP_DEBUG(get_logger(), "parity: %s", info_.hardware_parameters["parity"].c_str());
23+
RCLCPP_DEBUG(get_logger(), "data_bits: %s", info_.hardware_parameters["data_bits"].c_str());
24+
RCLCPP_DEBUG(get_logger(), "stop_bit: %s", info_.hardware_parameters["stop_bit"].c_str());
25+
RCLCPP_DEBUG(get_logger(), "slave_id: %s", info_.hardware_parameters["slave_id"].c_str());
1426

1527
state_velocity_ = 0.0;
1628
cmd_force_ = 1.0;
17-
gripper_position_min_ = stod(info_.hardware_parameters["grip_pos_min"]);
18-
gripper_position_max_ = stod(info_.hardware_parameters["grip_pos_max"]);
29+
gripper_position_min_ = std::stod(info_.hardware_parameters["grip_pos_min"]);
30+
gripper_position_max_ = std::stod(info_.hardware_parameters["grip_pos_max"]);
1931
tty_port_ = info_.hardware_parameters["tty"];
20-
baudrate_ = stoi(info_.hardware_parameters["baudrate"]);
21-
parity_ = info_.hardware_parameters["parity"][0];
22-
data_bits_ = stoi(info_.hardware_parameters["data_bits"]);
23-
stop_bit_ = stoi(info_.hardware_parameters["stop_bit"]);
24-
slave_id_ = stoi(info_.hardware_parameters["slave_id"]);
32+
baudrate_ = std::stoi(info_.hardware_parameters["baudrate"]);
33+
parity_ = (info_.hardware_parameters["parity"].c_str())[0];
34+
data_bits_ = std::stoi(info_.hardware_parameters["data_bits"]);
35+
stop_bit_ = std::stoi(info_.hardware_parameters["stop_bit"]);
36+
slave_id_ = std::stoi(info_.hardware_parameters["slave_id"]);
2537

2638
cmd_position_ = gripper_position_max_;
2739
state_position_ = gripper_position_max_;
@@ -32,7 +44,7 @@ HWI::CallbackReturn RobotiqHandeHardwareInterface::on_init(const HWI::HardwareIn
3244

3345
application_layer_.initialize(gripper_position_min_, gripper_position_max_, tty_port_, baudrate_, parity_, data_bits_, stop_bit_, slave_id_);
3446

35-
RCLCPP_INFO(get_logger(), "Initialized ModbusRTU for %s", tty_port_.c_str());
47+
RCLCPP_INFO(get_logger(), "Initialized ModbusRTU for %s, %d, %c, %d, %d", tty_port_.c_str(), baudrate_, parity_, data_bits_, stop_bit_);
3648
return HWI::CallbackReturn::SUCCESS;
3749
}
3850

0 commit comments

Comments
 (0)