-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Nav2 route server goal orientation scorer #4866
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
Merged
SteveMacenski
merged 11 commits into
ros-navigation:nav2_route_server
from
alexanderjyuen:nav2_route_server_goal_orientation_scorer
Jan 22, 2025
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ff6af68
added goal pose and bool to check for last edge for all scorers
alexanderjyuen 822da78
added goal_orientation scorer
alexanderjyuen 29ee71e
added test for GoalOrientationScorer
alexanderjyuen b83594c
changed goal pose to a const ref, and moved score to end as implicit …
alexanderjyuen 3ed9bc4
changed goal arguments to const ref
alexanderjyuen 054a556
using const ref for goal pose, rearranged total_score to match header
alexanderjyuen 205d81d
linting on goal_orientation_scorer.hpp
alexanderjyuen 606b9b4
using M_PI as default threshold, fixed angle wrapping by using angles…
alexanderjyuen b09a6c7
changed arguments to use const refs, changed argument order in score …
alexanderjyuen aa62ddf
changed calling of score to match argument sequence, changed GoalOrie…
alexanderjyuen e782c89
switched cost edge pairs to imply return of cost, default orientation…
alexanderjyuen 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
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
83 changes: 83 additions & 0 deletions
83
nav2_route/include/nav2_route/plugins/edge_cost_functions/goal_orientation_scorer.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,83 @@ | ||
| // Copyright (c) 2024, Polymath Robotics Inc. | ||
| // | ||
| // 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_ROUTE__PLUGINS__EDGE_COST_FUNCTIONS__GOAl_ORIENTATION_SCORER_HPP_ | ||
| #define NAV2_ROUTE__PLUGINS__EDGE_COST_FUNCTIONS__GOAL_ORIENTATION_SCORER_HPP_ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "rclcpp/rclcpp.hpp" | ||
| #include "rclcpp_lifecycle/lifecycle_node.hpp" | ||
| #include "nav2_route/interfaces/edge_cost_function.hpp" | ||
| #include "nav2_util/line_iterator.hpp" | ||
| #include "nav2_util/node_utils.hpp" | ||
| #include "nav2_costmap_2d/costmap_subscriber.hpp" | ||
| #include "tf2_geometry_msgs/tf2_geometry_msgs.hpp" | ||
| #include "tf2/utils.h" | ||
| #include "angles/angles.h" | ||
|
|
||
| namespace nav2_route | ||
| { | ||
|
|
||
| /** | ||
| * @class GoalOrientationScorer | ||
| * @brief Scores final edge by comparing the | ||
| */ | ||
| class GoalOrientationScorer : public EdgeCostFunction | ||
| { | ||
| public: | ||
| /** | ||
| * @brief Constructor | ||
| */ | ||
| GoalOrientationScorer() = default; | ||
|
|
||
| /** | ||
| * @brief destructor | ||
| */ | ||
| virtual ~GoalOrientationScorer() = default; | ||
|
|
||
| /** | ||
| * @brief Configure | ||
| */ | ||
| void configure( | ||
| const rclcpp_lifecycle::LifecycleNode::SharedPtr node, | ||
| const std::string & name) override; | ||
|
|
||
| /** | ||
| * @brief Main scoring plugin API | ||
| * @param edge The edge pointer to score, which has access to the | ||
| * start/end nodes and their associated metadata and actions | ||
| * @param cost of the edge scored | ||
| * @return bool if this edge is open valid to traverse | ||
| */ | ||
| bool score( | ||
| const EdgePtr edge, const geometry_msgs::msg::PoseStamped goal_pose, float & cost, | ||
| bool final_edge) override; | ||
|
|
||
| /** | ||
| * @brief Get name of the plugin for parameter scope mapping | ||
| * @return Name | ||
| */ | ||
| std::string getName() override; | ||
|
|
||
| protected: | ||
| rclcpp::Logger logger_{rclcpp::get_logger("GoalOrientationScorer")}; | ||
| std::string name_; | ||
| double orientation_tolerance_; | ||
| }; | ||
|
|
||
| } // namespace nav2_route | ||
|
|
||
| #endif // NAV2_ROUTE__PLUGINS__EDGE_COST_FUNCTIONS__GOAL_ORIENTATION_SCORER_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
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
63 changes: 63 additions & 0 deletions
63
nav2_route/src/plugins/edge_cost_functions/goal_orientation_scorer.cpp
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,63 @@ | ||
| // Copyright (c) 2024, Polymath Robotics Inc. | ||
| // | ||
| // 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 <memory> | ||
| #include <string> | ||
|
|
||
| #include "nav2_route/plugins/edge_cost_functions/goal_orientation_scorer.hpp" | ||
|
|
||
| namespace nav2_route | ||
| { | ||
|
|
||
| void GoalOrientationScorer::configure( | ||
| const rclcpp_lifecycle::LifecycleNode::SharedPtr node, | ||
| const std::string & name) | ||
| { | ||
| RCLCPP_INFO(node->get_logger(), "Configuring goal orientation scorer."); | ||
| name_ = name; | ||
| logger_ = node->get_logger(); | ||
|
|
||
| nav2_util::declare_parameter_if_not_declared( | ||
| node, getName() + ".orientation_tolerance", rclcpp::ParameterValue(M_PI)); | ||
| orientation_tolerance_ = node->get_parameter(getName() + ".orientation_tolerance").as_double(); | ||
| } | ||
|
|
||
| bool GoalOrientationScorer::score( | ||
| const EdgePtr edge, | ||
| const geometry_msgs::msg::PoseStamped goal_pose, float & /*cost*/, | ||
| bool final_edge) | ||
| { | ||
| if (final_edge) { | ||
| double edge_orientation = std::atan2( | ||
| edge->end->coords.y - edge->start->coords.y, | ||
| edge->end->coords.x - edge->start->coords.x); | ||
| double goal_orientation = tf2::getYaw(goal_pose.pose.orientation); | ||
| double d_yaw = std::abs(angles::shortest_angular_distance(edge_orientation, goal_orientation)); | ||
|
|
||
| if (d_yaw > orientation_tolerance_) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| std::string GoalOrientationScorer::getName() | ||
| { | ||
| return name_; | ||
| } | ||
|
|
||
| } // namespace nav2_route | ||
|
|
||
| #include "pluginlib/class_list_macros.hpp" | ||
| PLUGINLIB_EXPORT_CLASS(nav2_route::GoalOrientationScorer, nav2_route::EdgeCostFunction) | ||
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.
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.