Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class DynamixelHardware : public hardware_interface::SystemInterface
ControlMode control_mode_{ControlMode::Position};
bool mode_changed_{false};
bool use_dummy_{false};
bool activated_{false};
};
} // namespace dynamixel_hardware

Expand Down
16 changes: 15 additions & 1 deletion dynamixel_hardware/src/dynamixel_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ CallbackReturn DynamixelHardware::on_activate(const rclcpp_lifecycle::State & /*
joints_[i].state.effort = 0.0;
}
}

activated_ = true;

read(rclcpp::Time{}, rclcpp::Duration(0, 0));
reset_command();
write(rclcpp::Time{}, rclcpp::Duration(0, 0));
Expand All @@ -235,6 +238,8 @@ CallbackReturn DynamixelHardware::on_activate(const rclcpp_lifecycle::State & /*
CallbackReturn DynamixelHardware::on_deactivate(
const rclcpp_lifecycle::State & /* previous_state */)
{
activated_ = false;

RCLCPP_DEBUG(rclcpp::get_logger(kDynamixelHardware), "stop");
return CallbackReturn::SUCCESS;
}
Expand All @@ -243,6 +248,11 @@ return_type DynamixelHardware::read(
const rclcpp::Time & /* time */,
const rclcpp::Duration & /* period */)
{
if(!activated_)
{
return return_type::OK;
}

if (use_dummy_) {
return return_type::OK;
}
Expand Down Expand Up @@ -290,14 +300,18 @@ return_type DynamixelHardware::read(
joints_[i].state.velocity = dynamixel_workbench_.convertValue2Velocity(ids[i], velocities[i]);
joints_[i].state.effort = dynamixel_workbench_.convertValue2Current(currents[i]);
}

return return_type::OK;
}

return_type DynamixelHardware::write(
const rclcpp::Time & /* time */,
const rclcpp::Duration & /* period */)
{
if(!activated_)
{
return return_type::OK;
}

if (use_dummy_) {
for (auto & joint : joints_) {
joint.prev_command.position = joint.command.position;
Expand Down