Skip to content

Commit 956c464

Browse files
committed
Add interface to conditionally enable torque
1 parent 8f180f8 commit 956c464

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

dynamixel_hardware/include/dynamixel_hardware/dynamixel_hardware.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ class DynamixelHardware : public hardware_interface::SystemInterface
101101
std::map<const char * const, const ControlItem *> control_items_;
102102
std::vector<Joint> joints_;
103103
std::vector<uint8_t> joint_ids_;
104-
bool torque_enabled_{false};
104+
bool should_enable_torque_{false}; // True if torque should be enabled. False otherwise.
105+
bool torque_enabled_{false}; // True if torque is enabled. False otherwise.
105106
ControlMode control_mode_{ControlMode::Position};
106107
bool mode_changed_{false};
107108
bool use_dummy_{false};

dynamixel_hardware/src/dynamixel_hardware.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ CallbackReturn DynamixelHardware::on_init(
8282
return CallbackReturn::SUCCESS;
8383
}
8484

85+
if (
86+
info_.hardware_parameters.find("enable_torque") != info_.hardware_parameters.end() &&
87+
info_.hardware_parameters.at("enable_torque") == "false")
88+
{
89+
should_enable_torque_ = false;
90+
} else {
91+
should_enable_torque_ = true;
92+
}
93+
8594
auto usb_port = info_.hardware_parameters.at("usb_port");
8695
auto baud_rate = std::stoi(info_.hardware_parameters.at("baud_rate"));
8796
const char * log = nullptr;
@@ -105,7 +114,9 @@ CallbackReturn DynamixelHardware::on_init(
105114
enable_torque(false);
106115
set_control_mode(ControlMode::Position, true);
107116
set_joint_params();
108-
enable_torque(true);
117+
if (should_enable_torque_) {
118+
enable_torque(true);
119+
}
109120

110121
const ControlItem * goal_position =
111122
dynamixel_workbench_.getItemInfo(joint_ids_[0], kGoalPositionItem);
@@ -411,7 +422,7 @@ return_type DynamixelHardware::set_control_mode(const ControlMode & mode, const
411422
control_mode_ = ControlMode::Velocity;
412423
}
413424

414-
if (torque_enabled) {
425+
if (torque_enabled && should_enable_torque_) {
415426
enable_torque(true);
416427
}
417428
return return_type::OK;
@@ -435,7 +446,7 @@ return_type DynamixelHardware::set_control_mode(const ControlMode & mode, const
435446
control_mode_ = ControlMode::Position;
436447
}
437448

438-
if (torque_enabled) {
449+
if (torque_enabled && should_enable_torque_) {
439450
enable_torque(true);
440451
}
441452
return return_type::OK;

0 commit comments

Comments
 (0)