Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delayed Read Write Calls till after on_activate() is completed #89

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
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
15 changes: 14 additions & 1 deletion dynamixel_hardware/src/dynamixel_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,16 @@ CallbackReturn DynamixelHardware::on_activate(const rclcpp_lifecycle::State & /*
reset_command();
write(rclcpp::Time{}, rclcpp::Duration(0, 0));

activated_ = true;

return CallbackReturn::SUCCESS;
}

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 +247,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 +299,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