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

[RPP] Jerk limited trajectory generation #2816

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
4 changes: 3 additions & 1 deletion nav2_regulated_pure_pursuit_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(pluginlib REQUIRED)
find_package(tf2 REQUIRED)
find_package(ruckig REQUIRED)

nav2_package()
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -28,13 +29,14 @@ set(dependencies
nav2_util
nav2_core
tf2
ruckig
)

set(library_name nav2_regulated_pure_pursuit_controller)

add_library(${library_name} SHARED
src/regulated_pure_pursuit_controller.cpp)

target_link_libraries(${library_name} ruckig::ruckig)
ament_target_dependencies(${library_name}
${dependencies}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "nav2_util/odometry_utils.hpp"
#include "nav2_util/geometry_utils.hpp"
#include "geometry_msgs/msg/pose2_d.hpp"
#include "ruckig/ruckig.hpp"

namespace nav2_regulated_pure_pursuit_controller
{
Expand Down Expand Up @@ -157,9 +158,11 @@ class RegulatedPurePursuitController : public nav2_core::Controller
/**
* @brief Whether robot should rotate to final goal orientation
* @param carrot_pose current lookahead point
* @param lookahead_dist current lookahead distance
* @return Whether should rotate to goal heading
*/
bool shouldRotateToGoalHeading(const geometry_msgs::msg::PoseStamped & carrot_pose);
bool shouldRotateToGoalHeading(
const geometry_msgs::msg::PoseStamped & carrot_pose, const double & lookahead_dist);

/**
* @brief Create a smooth and kinematically smoothed rotation command
Expand Down Expand Up @@ -223,9 +226,11 @@ class RegulatedPurePursuitController : public nav2_core::Controller
* @brief Get lookahead point
* @param lookahead_dist Optimal lookahead distance
* @param path Current global path
* @param remaining_path_length path length from lookahead point to the end of pruned path
* @return Lookahead point
*/
geometry_msgs::msg::PoseStamped getLookAheadPoint(const double &, const nav_msgs::msg::Path &);
geometry_msgs::msg::PoseStamped getLookAheadPoint(
const double &, const nav_msgs::msg::Path &, double & remaining_path_length);

/**
* @brief checks for the cusp position
Expand All @@ -234,6 +239,13 @@ class RegulatedPurePursuitController : public nav2_core::Controller
*/
double findDirectionChange(const geometry_msgs::msg::PoseStamped & pose);

/**
* @brief Normalizes angle in range [-pi, pi]
* @param angle Angle to normalize
* @return Normalized angle
*/
double angleNormalize(double angle);
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Callback executed when a parameter change is detected
* @param event ParameterEvent message
Expand All @@ -250,6 +262,8 @@ class RegulatedPurePursuitController : public nav2_core::Controller
rclcpp::Clock::SharedPtr clock_;

double desired_linear_vel_, base_desired_linear_vel_;
double max_linear_accel_;
double max_linear_decel_;
double lookahead_dist_;
double rotate_to_heading_angular_vel_;
double max_lookahead_dist_;
Expand All @@ -272,6 +286,12 @@ class RegulatedPurePursuitController : public nav2_core::Controller
double rotate_to_heading_min_angle_;
double goal_dist_tol_;
bool allow_reversing_;
double robot_angle_;
bool rotating_;
double kp_angle_;
double max_linear_jerk_;
double max_angular_jerk_;
rclcpp::Time system_time_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is reliably run at the controller_frequency rate, may that be substituted instead of keeping timers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it is run at mentioned frequency. I am not using timers, just tracking system time. The problem is, I need to reset some internal states in case goal has been cancelled or goal checker stopped calling computeVelocityCommands. There is no such callback that allows me to do that, so my solution is to check if computeVelocityCommands has not been called for 4 control loop durations. If that's true, we have to reset internal states since controller has been idle for a while. You can look at the logic here:
https://github.com/memristor/navigation2/blob/03cf93ce88499222ed5e599f1a5dad8e8572c50d/nav2_regulated_pure_pursuit_controller/src/regulated_pure_pursuit_controller.cpp#L324-L344

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should break that logic out into a separate function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would setPlan do that? E.g. its a new plan given. The 2 cases is that there's that delay you mention or its a replan during robot execution.

The state reset if the time is too long seems like a better fit to be executed in setPlan than in this function


nav_msgs::msg::Path global_plan_;
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::Path>> global_path_pub_;
Expand All @@ -281,6 +301,16 @@ class RegulatedPurePursuitController : public nav2_core::Controller
std::unique_ptr<nav2_costmap_2d::FootprintCollisionChecker<nav2_costmap_2d::Costmap2D *>>
collision_checker_;

ruckig::Ruckig<1> * distance_profile_;
ruckig::InputParameter<1> distance_profile_input_;
ruckig::OutputParameter<1> distance_profile_output_;
ruckig::Result distance_profile_result_;

ruckig::Ruckig<1> * angle_profile_;
ruckig::InputParameter<1> angle_profile_input_;
ruckig::OutputParameter<1> angle_profile_output_;
ruckig::Result angle_profile_result_;

// Dynamic parameters handler
std::mutex mutex_;
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_;
Expand Down
1 change: 1 addition & 0 deletions nav2_regulated_pure_pursuit_controller/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<depend>nav2_msgs</depend>
<depend>pluginlib</depend>
<depend>tf2</depend>
<depend>ruckig</depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
Loading