16 #include "nav2_smac_planner/node_2d.hpp"
21 namespace nav2_smac_planner
26 _cell_cost(std::numeric_limits<float>::quiet_NaN()),
27 _accumulated_cost(std::numeric_limits<float>::max()),
44 _cell_cost = std::numeric_limits<float>::quiet_NaN();
45 _accumulated_cost = std::numeric_limits<float>::max();
48 _in_collision =
false;
52 const bool & traverse_unknown,
56 if (!std::isnan(_cell_cost)) {
57 return !_in_collision;
61 _cell_cost = collision_checker->
getCost();
62 return !_in_collision;
67 float normalized_cost = child->
getCost() / 252.0;
70 const float & dx =
A.x - B.x;
71 const float & dy =
A.y - B.y;
72 static float sqrt_2 = sqrt(2);
75 if ((dx * dx + dy * dy) > 1.05) {
76 return sqrt_2 * (1.0 + _ctx->cost_travel_multiplier * normalized_cost);
80 return 1.0 + _ctx->cost_travel_multiplier * normalized_cost;
85 const CoordinateVector & goals_coords)
89 auto dx = goals_coords[0].x - node_coords.x;
90 auto dy = goals_coords[0].y - node_coords.y;
91 return std::sqrt(dx * dx + dy * dy);
96 const MotionModel & motion_model,
97 unsigned int & x_size_uint,
102 if (motion_model != MotionModel::TWOD) {
103 throw std::runtime_error(
"Invalid motion model for 2D node.");
106 int x_size =
static_cast<int>(x_size_uint);
107 ctx->cost_travel_multiplier = search_info.cost_penalty;
108 ctx->neighbors_grid_offsets = {-1, +1, -x_size, +x_size, -x_size - 1,
109 -x_size + 1, +x_size - 1, +x_size + 1};
113 std::function<
bool(
const uint64_t &,
116 const bool & traverse_unknown,
117 NodeVector & neighbors)
136 for (
unsigned int i = 0; i != _ctx->neighbors_grid_offsets.size(); ++i) {
137 index = node_i + _ctx->neighbors_grid_offsets[i];
141 if (fabs(coord_parent.x - child.x) > 1 || fabs(coord_parent.y - child.y) > 1) {
145 if (NeighborGetter(index, neighbor)) {
147 neighbors.push_back(neighbor);
161 while (current_node->parent) {
164 current_node = current_node->parent;
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 wasVisited()
Gets if cell has been visited in search.
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 uint64_t &index, const unsigned int &width, const unsigned int &angles)
Get index.
uint64_t getIndex()
Gets cell index.
void getNeighbors(std::function< bool(const uint64_t &, nav2_smac_planner::Node2D *&)> &validity_checker, GridCollisionChecker *collision_checker, const bool &traverse_unknown, NodeVector &neighbors)
Retrieve all valid neighbors of a node.
~Node2D()
A destructor for nav2_smac_planner::Node2D.
static void initMotionModel(NodeContext *ctx, 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)
float getHeuristicCost(const Coordinates &node_coords, const CoordinateVector &goals_coords)
Get cost of heuristic of node.
Node2D(const uint64_t index, NodeContext *ctx)
A constructor for nav2_smac_planner::Node2D.
void reset()
Reset method for new search.
float getCost()
Gets the costmap cost at this node.
Search properties and penalties.