Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions nav2_smac_planner/include/nav2_smac_planner/a_star.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ class AStarAlgorithm
*/
inline bool areInputsValid();

/**
* @brief Get the closest path within tolerance if available
* @param path Vector of coordinates to fill with path
* @return if a valid path was found within tolerance
*/
inline bool getClosestPathWithinTolerance(CoordinateVector & path);

/**
* @brief Clear heuristic queue of nodes to search
*/
Expand Down
22 changes: 15 additions & 7 deletions nav2_smac_planner/src/a_star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ bool AStarAlgorithm<NodeT>::areInputsValid()
return true;
}

template<typename NodeT>
bool AStarAlgorithm<NodeT>::getClosestPathWithinTolerance(CoordinateVector & path)
{
if (_best_heuristic_node.first < getToleranceHeuristic()) {
_graph.at(_best_heuristic_node.second).backtracePath(path);
return true;
}

return false;
}

template<typename NodeT>
bool AStarAlgorithm<NodeT>::createPath(
CoordinateVector & path, int & iterations,
Expand Down Expand Up @@ -381,7 +392,8 @@ bool AStarAlgorithm<NodeT>::createPath(
std::chrono::duration<double> planning_duration =
std::chrono::duration_cast<std::chrono::duration<double>>(steady_clock::now() - start_time);
if (static_cast<double>(planning_duration.count()) >= _max_planning_time) {
return false;
// In case of timeout, return the path that is closest, if within tolerance.
return getClosestPathWithinTolerance(path);
}
}

Expand Down Expand Up @@ -448,12 +460,8 @@ bool AStarAlgorithm<NodeT>::createPath(
}
}

if (_best_heuristic_node.first < getToleranceHeuristic()) {
// If we run out of search options, return the path that is closest, if within tolerance.
return _graph.at(_best_heuristic_node.second).backtracePath(path);
}

return false;
// If we run out of search options, return the path that is closest, if within tolerance.
return getClosestPathWithinTolerance(path);
}

template<typename NodeT>
Expand Down
Loading