-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Path distance feature #5387
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
Open
silanus23
wants to merge
17
commits into
ros-navigation:main
Choose a base branch
from
silanus23:path_distance_feature
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.
Open
Path distance feature #5387
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8cae687
geometry utils
silanus23 0e4e0ae
fixed geometry utils adding 2d
silanus23 1e75eef
created path_utils
silanus23 312cdc1
added tests
silanus23 9655980
minor changes in tests
silanus23 62999b6
lint issue
silanus23 697de81
fixed reviews
silanus23 9d94751
doxygen fix
silanus23 60fa4cd
Last fixes.
silanus23 1424318
Last fixes cpp.
silanus23 60dc3fc
Update nav2_util/include/nav2_util/path_utils.hpp
silanus23 dacb457
Update nav2_util/include/nav2_util/path_utils.hpp
silanus23 f419292
Update nav2_util/test/test_path_utils.cpp
silanus23 c2dbd5d
Frame check fix
silanus23 abb1eea
Added TrackingError.msg
silanus23 9bd3527
Forgotten linting issues
silanus23 6b05659
copilot reviews
silanus23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Real-time tracking error for Nav2 controller | ||
|
||
std_msgs/Header header | ||
float32 tracking_error | ||
uint32 last_index | ||
float32 cross_product | ||
geometry_msgs/PoseStamped robot_pose | ||
float32 distance_to_goal |
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,60 @@ | ||
// Copyright (c) 2025 Berkan Tali | ||
// | ||
// 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_UTIL__PATH_UTILS_HPP_ | ||
#define NAV2_UTIL__PATH_UTILS_HPP_ | ||
|
||
#include <algorithm> | ||
#include <cmath> | ||
#include <limits> | ||
|
||
#include "geometry_msgs/msg/pose.hpp" | ||
#include "geometry_msgs/msg/pose_stamped.hpp" | ||
#include "geometry_msgs/msg/point.hpp" | ||
#include "geometry_msgs/msg/quaternion.hpp" | ||
#include "nav_msgs/msg/path.hpp" | ||
#include "nav2_util/geometry_utils.hpp" | ||
namespace nav2_util | ||
{ | ||
|
||
/** | ||
* @brief Result of searching for the closest segment on a path. | ||
*/ | ||
struct PathSearchResult | ||
{ | ||
double distance; | ||
size_t closest_segment_index; | ||
}; | ||
/** | ||
* @brief Finds the minimum distance from a robot pose to a path segment. | ||
* | ||
* This function searches for the closest segment on the given path to the robot's pose, | ||
* starting from a specified index and optionally limiting the search to a window length. | ||
* It returns the minimum distance found and the index of the closest segment. | ||
* | ||
* @param path The path to search (sequence of poses). | ||
* @param robot_pose The robot's current pose in pose form. | ||
* @param start_index The index in the path to start searching from. | ||
* @param search_window_length The maximum length (in meters) to search along the path. | ||
* @return PathSearchResult Struct containing the minimum distance and the index of the closest segment. | ||
*/ | ||
PathSearchResult distance_from_path( | ||
const nav_msgs::msg::Path & path, | ||
const geometry_msgs::msg::Pose & robot_pose, | ||
const size_t start_index = 0, | ||
const double search_window_length = std::numeric_limits<double>::max()); | ||
|
||
} // namespace nav2_util | ||
|
||
#endif // NAV2_UTIL__PATH_UTILS_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) 2025 Berkan Tali | ||
// | ||
// 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 "nav2_util/path_utils.hpp" | ||
|
||
#include <limits> | ||
#include <cmath> | ||
#include <stdexcept> | ||
|
||
#include "nav2_util/geometry_utils.hpp" | ||
namespace nav2_util | ||
{ | ||
|
||
PathSearchResult distance_from_path( | ||
const nav_msgs::msg::Path & path, | ||
const geometry_msgs::msg::Pose & robot_pose, | ||
const size_t start_index, | ||
const double search_window_length) | ||
{ | ||
PathSearchResult result; | ||
result.closest_segment_index = start_index; | ||
result.distance = std::numeric_limits<double>::max(); | ||
|
||
if (path.poses.empty()) { | ||
return result; | ||
} | ||
|
||
if (path.poses.size() == 1) { | ||
result.distance = nav2_util::geometry_utils::euclidean_distance( | ||
robot_pose, path.poses.front().pose); | ||
result.closest_segment_index = 0; | ||
return result; | ||
} | ||
|
||
if (start_index >= path.poses.size() - 1) { | ||
silanus23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw std::invalid_argument( | ||
"Invalid operation: requested start index (" + std::to_string(start_index) + | ||
") is greater than or equal to path size (" + std::to_string(path.poses.size()) + | ||
silanus23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"). Application is not properly managing state."); | ||
} | ||
|
||
silanus23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
double distance_traversed = 0.0; | ||
for (size_t i = start_index; i < path.poses.size() - 1; ++i) { | ||
if (distance_traversed > search_window_length) { | ||
break; | ||
} | ||
|
||
const double current_distance = geometry_utils::distance_to_segment( | ||
robot_pose.position, | ||
path.poses[i].pose, | ||
path.poses[i + 1].pose); | ||
|
||
if (current_distance < result.distance) { | ||
result.distance = current_distance; | ||
result.closest_segment_index = i; | ||
} | ||
|
||
distance_traversed += geometry_utils::euclidean_distance( | ||
path.poses[i], | ||
path.poses[i + 1]); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} // namespace nav2_util |
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.