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()),
47 _cell_cost = std::numeric_limits<float>::quiet_NaN();
48 _accumulated_cost = std::numeric_limits<float>::max();
51 _in_collision =
false;
55 const bool & traverse_unknown,
59 if (!std::isnan(_cell_cost)) {
60 return !_in_collision;
64 _cell_cost = collision_checker->
getCost();
65 return !_in_collision;
70 float normalized_cost = child->
getCost() / 252.0;
73 const float & dx =
A.x - B.x;
74 const float & dy =
A.y - B.y;
75 static float sqrt_2 = sqrt(2);
78 if ((dx * dx + dy * dy) > 1.05) {
79 return sqrt_2 * (1.0 + cost_travel_multiplier * normalized_cost);
83 return 1.0 + cost_travel_multiplier * normalized_cost;
92 auto dx = goal_coordinates.x - node_coords.x;
93 auto dy = goal_coordinates.y - node_coords.y;
94 return std::sqrt(dx * dx + dy * dy);
98 const MotionModel & motion_model,
99 unsigned int & x_size_uint,
104 if (motion_model != MotionModel::TWOD) {
105 throw std::runtime_error(
"Invalid motion model for 2D node.");
108 int x_size =
static_cast<int>(x_size_uint);
109 cost_travel_multiplier = search_info.cost_penalty;
110 _neighbors_grid_offsets = {-1, +1, -x_size, +x_size, -x_size - 1,
111 -x_size + 1, +x_size - 1, +x_size + 1};
115 std::function<
bool(
const uint64_t &,
118 const bool & traverse_unknown,
119 NodeVector & neighbors)
138 for (
unsigned int i = 0; i != _neighbors_grid_offsets.size(); ++i) {
139 index = node_i + _neighbors_grid_offsets[i];
143 if (fabs(parent.x - child.x) > 1 || fabs(parent.y - child.y) > 1) {
147 if (NeighborGetter(index, neighbor)) {
149 neighbors.push_back(neighbor);
163 while (current_node->parent) {
166 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.
Node2D(const uint64_t index)
A constructor for nav2_smac_planner::Node2D.
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.
static float getHeuristicCost(const Coordinates &node_coords, const Coordinates &goal_coordinates)
Get cost of heuristic of node.
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.
void reset()
Reset method for new search.
float getCost()
Gets the costmap cost at this node.
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.