Skip to content

Commit 9b25da6

Browse files
committed
refactor: Replace std::cout with RCLCPP logging for torque state changes in DynamixelHardware
1 parent 89ad779 commit 9b25da6

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/dynamixel/dynamixel.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,11 @@ DxlError Dynamixel::WriteItem(uint8_t id, uint16_t addr, uint8_t size, uint32_t
555555
} else if (dxl_error != 0) {
556556
fprintf(
557557
stderr,
558-
"[WriteItem][ID:%03d][comm_id:%03d] RX_PACKET_ERROR : %s (retry %d/%d)\n",
558+
"[WriteItem][ID:%03d][comm_id:%03d] RX_PACKET_ERROR : %s\n",
559559
id,
560560
comm_id,
561-
packet_handler_->getRxPacketError(dxl_error),
562-
i + 1,
563-
MAX_COMM_RETRIES);
564-
if (i == MAX_COMM_RETRIES - 1) {
565-
return DxlError::ITEM_WRITE_FAIL;
566-
}
561+
packet_handler_->getRxPacketError(dxl_error));
562+
return DxlError::ITEM_WRITE_FAIL;
567563
} else {
568564
return DxlError::OK;
569565
}

src/dynamixel_hardware_interface.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,15 +1300,16 @@ void DynamixelHardware::ChangeDxlTorqueState()
13001300
}
13011301

13021302
if (dxl_torque_status_ == REQUESTED_TO_ENABLE) {
1303-
std::cout << "Requested to enable torque, Enabling torque for all Dynamixels" << std::endl;
1303+
RCLCPP_WARN_STREAM(logger_, "Requested to enable torque, Enabling torque for all Dynamixels");
13041304
dxl_comm_->DynamixelEnable(torque_enabled_ids_);
13051305
SyncJointCommandWithStates();
13061306
} else if (dxl_torque_status_ == REQUESTED_TO_DISABLE) {
1307-
std::cout << "Requested to disable torque, Disabling torque for all Dynamixels" << std::endl;
1307+
RCLCPP_WARN_STREAM(logger_, "Requested to disable torque, Disabling torque for all Dynamixels");
13081308
dxl_comm_->DynamixelDisable(torque_enabled_ids_);
13091309
SyncJointCommandWithStates();
13101310
}
13111311

1312+
dxl_torque_state_ = dxl_comm_->GetDxlTorqueState();
13121313
for (auto single_torque_state : dxl_torque_state_) {
13131314
if (single_torque_state.second == TORQUE_OFF) {
13141315
dxl_torque_status_ = TORQUE_DISABLED;
@@ -1384,6 +1385,7 @@ void DynamixelHardware::set_dxl_torque_srv_callback(
13841385
if (dxl_torque_status_ == TORQUE_ENABLED) {
13851386
response->success = true;
13861387
response->message = "Already enabled.";
1388+
RCLCPP_INFO_STREAM(logger_, "Requested to enable torque, but already enabled.");
13871389
return;
13881390
} else {
13891391
dxl_torque_status_ = REQUESTED_TO_ENABLE;
@@ -1392,6 +1394,7 @@ void DynamixelHardware::set_dxl_torque_srv_callback(
13921394
if (dxl_torque_status_ == TORQUE_DISABLED) {
13931395
response->success = true;
13941396
response->message = "Already disabled.";
1397+
RCLCPP_INFO_STREAM(logger_, "Requested to disable torque, but already disabled.");
13951398
return;
13961399
} else {
13971400
dxl_torque_status_ = REQUESTED_TO_DISABLE;

0 commit comments

Comments
 (0)