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

Add the goal to NavFN tolerance region traversing algorithm #1734

Merged
Changes from all 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
68 changes: 42 additions & 26 deletions nav2_navfn_planner/src/navfn_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,35 @@ NavfnPlanner::makePlan(

double resolution = costmap_->getResolution();
geometry_msgs::msg::Pose p, best_pose;
p = goal;

bool found_legal = false;
double best_sdist = std::numeric_limits<double>::max();

p.position.y = goal.position.y - tolerance;

while (p.position.y <= goal.position.y + tolerance) {
p.position.x = goal.position.x - tolerance;
while (p.position.x <= goal.position.x + tolerance) {
double potential = getPointPotential(p.position);
double sdist = squared_distance(p, goal);
if (potential < POT_HIGH && sdist < best_sdist) {
best_sdist = sdist;
best_pose = p;
found_legal = true;

p = goal;
double potential = getPointPotential(p.position);
if (potential < POT_HIGH) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be taken care of from the while loop condition (p.position.y <= goal.position.y + tolerance)? In that case that its the goal, it meets that spec and it shouldn't even enter the while loop

// Goal is reachable by itself
best_pose = p;
found_legal = true;
} else {
// Goal is not reachable. Trying to find nearest to the goal
// reachable point within its tolerance region
double best_sdist = std::numeric_limits<double>::max();

p.position.y = goal.position.y - tolerance;
while (p.position.y <= goal.position.y + tolerance) {
p.position.x = goal.position.x - tolerance;
while (p.position.x <= goal.position.x + tolerance) {
potential = getPointPotential(p.position);
double sdist = squared_distance(p, goal);
if (potential < POT_HIGH && sdist < best_sdist) {
best_sdist = sdist;
best_pose = p;
found_legal = true;
}
p.position.x += resolution;
}
p.position.x += resolution;
p.position.y += resolution;
}
p.position.y += resolution;
}

if (found_legal) {
Expand Down Expand Up @@ -361,18 +370,25 @@ NavfnPlanner::validPointPotential(
const double resolution = costmap_->getResolution();

geometry_msgs::msg::Point p = world_point;
p.y = world_point.y - tolerance;

while (p.y <= world_point.y + tolerance) {
p.x = world_point.x - tolerance;
while (p.x <= world_point.x + tolerance) {
double potential = getPointPotential(p);
if (potential < POT_HIGH) {
return true;
double potential = getPointPotential(p);
if (potential < POT_HIGH) {
// world_point is reachable by itself
return true;
} else {
// world_point, is not reachable. Trying to find any
// reachable point within its tolerance region
p.y = world_point.y - tolerance;
while (p.y <= world_point.y + tolerance) {
p.x = world_point.x - tolerance;
while (p.x <= world_point.x + tolerance) {
potential = getPointPotential(p);
if (potential < POT_HIGH) {
return true;
}
p.x += resolution;
}
p.x += resolution;
p.y += resolution;
}
p.y += resolution;
}

return false;
Expand Down