-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add acceleration limits to DriveOnHeading and BackUp behaviors #4810
Open
RBT22
wants to merge
10
commits into
ros-navigation:main
Choose a base branch
from
EnjoyRobotics:rolling/acc-drive-on-heading
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−1
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2a921f8
Add acceleration constraints
RBT22 22980c2
Cleanup code
RBT22 cd280c8
Format code
RBT22 3691936
Add <limits> header to drive_on_heading.hpp
RBT22 f999511
Remove vel pointer
RBT22 bb11ff9
Use the limits only if both of them is set
RBT22 9b9a6ce
Fix onActionCompletion params
RBT22 1098962
Add default acc params and change decel sign
RBT22 4a544d5
Add minimum speed parameter
RBT22 f1a87f8
WIP test
RBT22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,6 +19,7 @@ | |||||
#include <chrono> | ||||||
#include <memory> | ||||||
#include <utility> | ||||||
#include <limits> | ||||||
|
||||||
#include "nav2_behaviors/timed_behavior.hpp" | ||||||
#include "nav2_msgs/action/drive_on_heading.hpp" | ||||||
|
@@ -133,7 +134,35 @@ class DriveOnHeading : public TimedBehavior<ActionT> | |||||
cmd_vel->header.frame_id = this->robot_base_frame_; | ||||||
cmd_vel->twist.linear.y = 0.0; | ||||||
cmd_vel->twist.angular.z = 0.0; | ||||||
cmd_vel->twist.linear.x = command_speed_; | ||||||
if (acceleration_limit_ <= 0.0 || deceleration_limit_ >= 0.0) { | ||||||
cmd_vel->twist.linear.x = command_speed_; | ||||||
} else { | ||||||
double current_speed = last_vel_ == std::numeric_limits<double>::max() ? 0.0 : last_vel_; | ||||||
|
||||||
double min_feasible_speed = current_speed + deceleration_limit_ / this->cycle_frequency_; | ||||||
double max_feasible_speed = current_speed + acceleration_limit_ / this->cycle_frequency_; | ||||||
cmd_vel->twist.linear.x = std::clamp(command_speed_, min_feasible_speed, max_feasible_speed); | ||||||
|
||||||
// Check if we need to slow down to avoid overshooting | ||||||
auto remaining_distance = std::fabs(command_x_) - distance; | ||||||
bool forward = command_speed_ > 0.0; | ||||||
if (forward) { | ||||||
double max_vel_to_stop = std::sqrt(-2.0 * deceleration_limit_ * remaining_distance); | ||||||
if (max_vel_to_stop < cmd_vel->twist.linear.x) { | ||||||
cmd_vel->twist.linear.x = max_vel_to_stop; | ||||||
} | ||||||
} else { | ||||||
double max_vel_to_stop = -std::sqrt(2.0 * acceleration_limit_ * remaining_distance); | ||||||
if (max_vel_to_stop > cmd_vel->twist.linear.x) { | ||||||
cmd_vel->twist.linear.x = max_vel_to_stop; | ||||||
} | ||||||
} | ||||||
|
||||||
// Ensure we don't go below minimum speed | ||||||
if (std::fabs(cmd_vel->twist.linear.x) < minimum_speed_) { | ||||||
cmd_vel->twist.linear.x = forward ? minimum_speed_ : -minimum_speed_; | ||||||
} | ||||||
} | ||||||
|
||||||
geometry_msgs::msg::Pose2D pose2d; | ||||||
pose2d.x = current_pose.pose.position.x; | ||||||
|
@@ -146,6 +175,7 @@ class DriveOnHeading : public TimedBehavior<ActionT> | |||||
return ResultStatus{Status::FAILED, ActionT::Result::COLLISION_AHEAD}; | ||||||
} | ||||||
|
||||||
last_vel_ = cmd_vel->twist.linear.x; | ||||||
this->vel_pub_->publish(std::move(cmd_vel)); | ||||||
|
||||||
return ResultStatus{Status::RUNNING, ActionT::Result::NONE}; | ||||||
|
@@ -157,6 +187,14 @@ class DriveOnHeading : public TimedBehavior<ActionT> | |||||
*/ | ||||||
CostmapInfoType getResourceInfo() override {return CostmapInfoType::LOCAL;} | ||||||
|
||||||
void onCleanup() override {last_vel_ = std::numeric_limits<double>::max();} | ||||||
|
||||||
void onActionCompletion(std::shared_ptr<typename ActionT::Result>/*result*/) | ||||||
override | ||||||
{ | ||||||
last_vel_ = std::numeric_limits<double>::max(); | ||||||
} | ||||||
|
||||||
protected: | ||||||
/** | ||||||
* @brief Check if pose is collision free | ||||||
|
@@ -214,6 +252,19 @@ class DriveOnHeading : public TimedBehavior<ActionT> | |||||
node, | ||||||
"simulate_ahead_time", rclcpp::ParameterValue(2.0)); | ||||||
node->get_parameter("simulate_ahead_time", simulate_ahead_time_); | ||||||
|
||||||
nav2_util::declare_parameter_if_not_declared( | ||||||
node, this->behavior_name_ + ".acceleration_limit", | ||||||
rclcpp::ParameterValue(2.5)); | ||||||
nav2_util::declare_parameter_if_not_declared( | ||||||
node, this->behavior_name_ + ".deceleration_limit", | ||||||
rclcpp::ParameterValue(-2.5)); | ||||||
nav2_util::declare_parameter_if_not_declared( | ||||||
node, this->behavior_name_ + ".minimum_speed", | ||||||
rclcpp::ParameterValue(0.01)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
More realistic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also for the nav2_params.yaml |
||||||
node->get_parameter(this->behavior_name_ + ".acceleration_limit", acceleration_limit_); | ||||||
node->get_parameter(this->behavior_name_ + ".deceleration_limit", deceleration_limit_); | ||||||
node->get_parameter(this->behavior_name_ + ".minimum_speed", minimum_speed_); | ||||||
} | ||||||
|
||||||
typename ActionT::Feedback::SharedPtr feedback_; | ||||||
|
@@ -225,6 +276,10 @@ class DriveOnHeading : public TimedBehavior<ActionT> | |||||
rclcpp::Duration command_time_allowance_{0, 0}; | ||||||
rclcpp::Time end_time_; | ||||||
double simulate_ahead_time_; | ||||||
double acceleration_limit_; | ||||||
double deceleration_limit_; | ||||||
double minimum_speed_; | ||||||
double last_vel_ = std::numeric_limits<double>::max(); | ||||||
}; | ||||||
|
||||||
} // namespace nav2_behaviors | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you may also need to set a minimum velocity parameter. Most robots can't go 1mm/s or have stalling velocities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speaking of this -- an aside. Do you use the rotation shim controller? Right now, we don't do the deceleration as a function of its target orientation and this would be great to add in there too if you happened to also use it & be open to submitting the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveMacenski I can add the limits for the shim controller after this, but I’m kinda stuck on the tests—can’t get the subscriber to run its callback. Any tips?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It generally looks right ot me, but I'd look at other subscription-based BT node tests for reference :-)
I'd also try:
rclcpp::spin_some(node_);
after the while loop