Skip to content

Commit

Permalink
fix(timeout): do not reset steer wheel to 0. on timeout
Browse files Browse the repository at this point in the history
Instead of setting the incoming twist command velocity to zero, we should
only set the wheel commands to zero without altering the steering angles
in order to avoid in-place steering of the wheels.
  • Loading branch information
reinzor committed Sep 13, 2024
1 parent 57c50e5 commit 8a9658e
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions steering_controllers_library/src/steering_controllers_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,26 +355,11 @@ controller_interface::return_type SteeringControllersLibrary::update_reference_f
const rclcpp::Time & time, const rclcpp::Duration & /*period*/)
{
auto current_ref = *(input_ref_.readFromRT());
const auto age_of_last_command = time - (current_ref)->header.stamp;

// send message only if there is no timeout
if (age_of_last_command <= ref_timeout_ || ref_timeout_ == rclcpp::Duration::from_seconds(0))
if (!std::isnan(current_ref->twist.linear.x) && !std::isnan(current_ref->twist.angular.z))
{
if (!std::isnan(current_ref->twist.linear.x) && !std::isnan(current_ref->twist.angular.z))
{
reference_interfaces_[0] = current_ref->twist.linear.x;
reference_interfaces_[1] = current_ref->twist.angular.z;
}
}
else
{
if (!std::isnan(current_ref->twist.linear.x) && !std::isnan(current_ref->twist.angular.z))
{
reference_interfaces_[0] = 0.0;
reference_interfaces_[1] = 0.0;
current_ref->twist.linear.x = std::numeric_limits<double>::quiet_NaN();
current_ref->twist.angular.z = std::numeric_limits<double>::quiet_NaN();
}
reference_interfaces_[0] = current_ref->twist.linear.x;
reference_interfaces_[1] = current_ref->twist.angular.z;
}

return controller_interface::return_type::OK;
Expand All @@ -396,13 +381,17 @@ controller_interface::return_type SteeringControllersLibrary::update_and_write_c
last_linear_velocity_ = reference_interfaces_[0];
last_angular_velocity_ = reference_interfaces_[1];

const auto age_of_last_command = time - (*(input_ref_.readFromRT()))->header.stamp;
const auto timeout =
age_of_last_command > ref_timeout_ && ref_timeout_ != rclcpp::Duration::from_seconds(0);

auto [traction_commands, steering_commands] =
odometry_.get_commands(last_linear_velocity_, last_angular_velocity_, params_.open_loop);
if (params_.front_steering)
{
for (size_t i = 0; i < params_.rear_wheels_names.size(); i++)
{
command_interfaces_[i].set_value(traction_commands[i]);
command_interfaces_[i].set_value(timeout ? 0. : traction_commands[i]);
}
for (size_t i = 0; i < params_.front_wheels_names.size(); i++)
{
Expand Down

0 comments on commit 8a9658e

Please sign in to comment.