-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New Goal checker: AxisGoalChecker #5746
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
Draft
doisyg
wants to merge
7
commits into
ros-navigation:main
Choose a base branch
from
botsandus:axis_goal_checker
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.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5af690f
add before_goal_pose to goal checker
79538e4
AxisGoalChecker
988a4d2
pose stamp workaround
af1cbe9
Merge remote-tracking branch 'ros-navigation/main' into axis_goal_che…
04bd6ad
rename param to goal_tolerance
4235e4a
Apache License
04c29af
format
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 hidden or 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 hidden or 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
72 changes: 72 additions & 0 deletions
72
nav2_controller/include/nav2_controller/plugins/axis_goal_checker.hpp
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Copyright (c) 2025 Dexory | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef NAV2_CONTROLLER__PLUGINS__AXIS_GOAL_CHECKER_HPP_ | ||
| #define NAV2_CONTROLLER__PLUGINS__AXIS_GOAL_CHECKER_HPP_ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "rclcpp/rclcpp.hpp" | ||
| #include "nav2_ros_common/lifecycle_node.hpp" | ||
| #include "nav2_core/goal_checker.hpp" | ||
| #include "rcl_interfaces/msg/set_parameters_result.hpp" | ||
|
|
||
| namespace nav2_controller | ||
| { | ||
|
|
||
| /** * @class AxisGoalChecker | ||
| * @brief Goal Checker plugin that checks progress along the axis defined by the | ||
| * 2 last poses of the pathalong the axis defined by the last segment of the path to the goal. | ||
| * | ||
| * This class can be configured to allow overshoot past the goal if the is_overshoot_valid | ||
| * parameter is set to true (which it is false by default). | ||
| */ | ||
| class AxisGoalChecker : public nav2_core::GoalChecker | ||
| { | ||
| public: | ||
| AxisGoalChecker(); | ||
| // Standard GoalChecker Interface | ||
| void initialize( | ||
| const nav2::LifecycleNode::WeakPtr & parent, | ||
| const std::string & plugin_name, | ||
| const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros) override; | ||
| void reset() override; | ||
| bool isGoalReached( | ||
| const geometry_msgs::msg::Pose & query_pose, const geometry_msgs::msg::Pose & goal_pose, | ||
| const std::optional<geometry_msgs::msg::Pose> & before_goal_pose, | ||
| const geometry_msgs::msg::Twist & velocity) override; | ||
| bool getTolerances( | ||
| geometry_msgs::msg::Pose & pose_tolerance, | ||
| geometry_msgs::msg::Twist & vel_tolerance) override; | ||
|
|
||
| protected: | ||
| double goal_tolerance_; | ||
| bool is_overshoot_valid_; | ||
| // Dynamic parameters handler | ||
| rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_; | ||
| std::string plugin_name_; | ||
|
|
||
| /** | ||
| * @brief Callback executed when a parameter change is detected | ||
| * @param parameters list of changed parameters | ||
| */ | ||
| rcl_interfaces::msg::SetParametersResult | ||
| dynamicParametersCallback(std::vector<rclcpp::Parameter> parameters); | ||
| }; | ||
|
|
||
| } // namespace nav2_controller | ||
|
|
||
| #endif // NAV2_CONTROLLER__PLUGINS__AXIS_GOAL_CHECKER_HPP_ | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| // Copyright (c) 2025 Dexory | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <tf2/utils.h> | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <limits> | ||
| #include <vector> | ||
|
|
||
| #include "angles/angles.h" | ||
| #include "nav2_controller/plugins/axis_goal_checker.hpp" | ||
| #include "pluginlib/class_list_macros.hpp" | ||
| #include "nav2_ros_common/node_utils.hpp" | ||
| #include "nav2_util/geometry_utils.hpp" | ||
|
|
||
|
|
||
| using rcl_interfaces::msg::ParameterType; | ||
| using std::placeholders::_1; | ||
|
|
||
| namespace nav2_controller | ||
| { | ||
|
|
||
| AxisGoalChecker::AxisGoalChecker() | ||
| : goal_tolerance_(0.25) | ||
| { | ||
| } | ||
|
|
||
| void AxisGoalChecker::initialize( | ||
| const nav2::LifecycleNode::WeakPtr & parent, | ||
| const std::string & plugin_name, | ||
| const std::shared_ptr<nav2_costmap_2d::Costmap2DROS>/*costmap_ros*/) | ||
| { | ||
| plugin_name_ = plugin_name; | ||
| auto node = parent.lock(); | ||
|
|
||
| nav2::declare_parameter_if_not_declared( | ||
| node, | ||
| plugin_name + ".goal_tolerance", rclcpp::ParameterValue(0.25)); | ||
| node->get_parameter(plugin_name + ".goal_tolerance", goal_tolerance_); | ||
|
|
||
| nav2::declare_parameter_if_not_declared( | ||
| node, | ||
| plugin_name + ".is_overshoot_valid", rclcpp::ParameterValue(false)); | ||
| node->get_parameter(plugin_name + ".is_overshoot_valid", is_overshoot_valid_); | ||
|
|
||
| // Add callback for dynamic parameters | ||
| dyn_params_handler_ = node->add_on_set_parameters_callback( | ||
| std::bind(&AxisGoalChecker::dynamicParametersCallback, this, _1)); | ||
| } | ||
|
|
||
| void AxisGoalChecker::reset() | ||
| { | ||
| } | ||
|
|
||
| bool AxisGoalChecker::isGoalReached( | ||
| const geometry_msgs::msg::Pose & query_pose, const geometry_msgs::msg::Pose & goal_pose, | ||
| const std::optional<geometry_msgs::msg::Pose> & before_goal_pose, | ||
| const geometry_msgs::msg::Twist &) | ||
| { | ||
| if (before_goal_pose.has_value()) { | ||
| // end of path direction | ||
| double end_of_path_yaw = atan2( | ||
| goal_pose.position.y - before_goal_pose->position.y, | ||
| goal_pose.position.x - before_goal_pose->position.x); | ||
|
|
||
| double robot_to_goal_yaw = atan2( | ||
| goal_pose.position.y - query_pose.position.y, | ||
| goal_pose.position.x - query_pose.position.x); | ||
|
|
||
| double projection_angle = angles::shortest_angular_distance( | ||
| robot_to_goal_yaw, end_of_path_yaw); | ||
|
|
||
| double projected_distance_to_goal = std::hypot( | ||
| goal_pose.position.x - query_pose.position.x, | ||
| goal_pose.position.y - query_pose.position.y) * | ||
| cos(projection_angle); | ||
|
|
||
| if (is_overshoot_valid_) { | ||
| return projected_distance_to_goal < goal_tolerance_; | ||
| } else { | ||
| return fabs(projected_distance_to_goal) < goal_tolerance_; | ||
| } | ||
| } else { | ||
| // handle path with only 1 point, in that case reverting to single distance check | ||
| double distance_to_goal = std::hypot( | ||
| goal_pose.position.x - query_pose.position.x, | ||
| goal_pose.position.y - query_pose.position.y); | ||
| return fabs(distance_to_goal) < goal_tolerance_; | ||
| } | ||
| } | ||
|
|
||
| bool AxisGoalChecker::getTolerances( | ||
| geometry_msgs::msg::Pose & pose_tolerance, | ||
| geometry_msgs::msg::Twist & vel_tolerance) | ||
| { | ||
| double invalid_field = std::numeric_limits<double>::lowest(); | ||
|
|
||
| pose_tolerance.position.x = goal_tolerance_; | ||
| pose_tolerance.position.y = goal_tolerance_; | ||
| pose_tolerance.position.z = invalid_field; | ||
| pose_tolerance.orientation = | ||
| nav2_util::geometry_utils::orientationAroundZAxis(M_PI_2); | ||
|
|
||
| vel_tolerance.linear.x = invalid_field; | ||
| vel_tolerance.linear.y = invalid_field; | ||
| vel_tolerance.linear.z = invalid_field; | ||
|
|
||
| vel_tolerance.angular.x = invalid_field; | ||
| vel_tolerance.angular.y = invalid_field; | ||
| vel_tolerance.angular.z = invalid_field; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| rcl_interfaces::msg::SetParametersResult | ||
| AxisGoalChecker::dynamicParametersCallback(std::vector<rclcpp::Parameter> parameters) | ||
| { | ||
| rcl_interfaces::msg::SetParametersResult result; | ||
| for (auto & parameter : parameters) { | ||
| const auto & type = parameter.get_type(); | ||
| const auto & name = parameter.get_name(); | ||
|
|
||
| if (type == ParameterType::PARAMETER_DOUBLE) { | ||
| if (name == plugin_name_ + ".segment_axis_goal_tolerance") { | ||
| goal_tolerance_ = parameter.as_double(); | ||
| } | ||
| } else if (type == ParameterType::PARAMETER_BOOL) { | ||
| if (name == plugin_name_ + ".is_overshoot_valid") { | ||
| is_overshoot_valid_ = parameter.as_bool(); | ||
| } | ||
| } | ||
| } | ||
| result.successful = true; | ||
| return result; | ||
| } | ||
|
|
||
| } // namespace nav2_controller | ||
|
|
||
| PLUGINLIB_EXPORT_CLASS(nav2_controller::AxisGoalChecker, nav2_core::GoalChecker) |
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.