16 #include "nav2_smac_planner/node_2d.hpp"
21 namespace nav2_smac_planner
25 std::vector<int> Node2D::_neighbors_grid_offsets;
26 float Node2D::cost_travel_multiplier = 2.0;
30 _cell_cost(std::numeric_limits<float>::quiet_NaN()),
31 _accumulated_cost(std::numeric_limits<float>::max()),
46 _cell_cost = std::numeric_limits<float>::quiet_NaN();
47 _accumulated_cost = std::numeric_limits<float>::max();
53 const bool & traverse_unknown,
56 if (collision_checker->
inCollision(this->getIndex(), traverse_unknown)) {
60 _cell_cost = collision_checker->
getCost();
66 float normalized_cost = child->
getCost() / 252.0;
69 const float & dx = A.x - B.x;
70 const float & dy = A.y - B.y;
71 static float sqrt_2 = sqrt(2);
74 if ((dx * dx + dy * dy) > 1.05) {
75 return sqrt_2 * (1.0 + cost_travel_multiplier * normalized_cost);
79 return 1.0 + cost_travel_multiplier * normalized_cost;
89 auto dx = goal_coordinates.x - node_coords.x;
90 auto dy = goal_coordinates.y - node_coords.y;
91 return std::sqrt(dx * dx + dy * dy);
95 const MotionModel & motion_model,
96 unsigned int & x_size_uint,
101 if (motion_model != MotionModel::TWOD) {
102 throw std::runtime_error(
"Invalid motion model for 2D node.");
105 int x_size =
static_cast<int>(x_size_uint);
106 cost_travel_multiplier = search_info.cost_penalty;
107 _neighbors_grid_offsets = {-1, +1, -x_size, +x_size, -x_size - 1,
108 -x_size + 1, +x_size - 1, +x_size + 1};
114 const bool & traverse_unknown,
115 NodeVector & neighbors)
134 for (
unsigned int i = 0; i != _neighbors_grid_offsets.size(); ++i) {
135 index = node_i + _neighbors_grid_offsets[i];
139 if (fabs(parent.x - child.x) > 1 || fabs(parent.y - child.y) > 1) {
143 if (NeighborGetter(index, neighbor)) {
145 neighbors.push_back(neighbor);
159 while (current_node->parent) {
162 current_node = current_node->parent;
A 2D costmap provides a mapping between points in the world and their associated "costs".
A costmap grid collision checker.
bool inCollision(const float &x, const float &y, const float &theta, const bool &traverse_unknown)
Check if in collision with costmap and footprint at pose.
float getCost()
Get cost at footprint pose in costmap.
Node2D implementation for graph.
bool isNodeValid(const bool &traverse_unknown, GridCollisionChecker *collision_checker)
Check if this node is valid.
bool backtracePath(CoordinateVector &path)
Set the starting pose for planning, as a node index.
float getTraversalCost(const NodePtr &child)
get traversal cost from this node to child node
static Coordinates getCoords(const unsigned int &index, const unsigned int &width, const unsigned int &angles)
Get index.
void getNeighbors(std::function< bool(const unsigned int &, nav2_smac_planner::Node2D *&)> &validity_checker, GridCollisionChecker *collision_checker, const bool &traverse_unknown, NodeVector &neighbors)
Retrieve all valid neighbors of a node.
unsigned int & getIndex()
Gets cell index.
~Node2D()
A destructor for nav2_smac_planner::Node2D.
bool & wasVisited()
Gets if cell has been visited in search.
float & getCost()
Gets the costmap cost at this node.
static float getHeuristicCost(const Coordinates &node_coords, const Coordinates &goal_coordinates, const nav2_costmap_2d::Costmap2D *costmap)
Get cost of heuristic of node.
void reset()
Reset method for new search.
Node2D(const unsigned int index)
A constructor for nav2_smac_planner::Node2D.
static void initMotionModel(const MotionModel &motion_model, unsigned int &size_x, unsigned int &size_y, unsigned int &num_angle_quantization, SearchInfo &search_info)
Initialize the neighborhood to be used in A* We support 4-connect (VON_NEUMANN) and 8-connect (MOORE)
Node2D implementation of coordinate structure.
Search properties and penalties.