15 #ifndef NAV2_SMAC_PLANNER__NODE_LATTICE_HPP_
16 #define NAV2_SMAC_PLANNER__NODE_LATTICE_HPP_
23 #include "ompl/base/StateSpace.h"
25 #include "nav2_smac_planner/constants.hpp"
26 #include "nav2_smac_planner/types.hpp"
27 #include "nav2_smac_planner/collision_checker.hpp"
28 #include "nav2_smac_planner/obstacle_heuristic.hpp"
29 #include "nav2_smac_planner/distance_heuristic.hpp"
30 #include "nav2_smac_planner/node_hybrid.hpp"
31 #include "nav2_smac_planner/utils.hpp"
33 namespace nav2_smac_planner
57 unsigned int & size_x_in,
68 unsigned int & direction_change_index);
98 double getAngle(
const double & theta);
101 unsigned int num_angle_quantization;
102 float change_penalty;
103 float non_straight_penalty;
105 float reverse_penalty;
106 float travel_distance_reward;
107 float rotation_penalty;
108 float min_turning_radius;
109 bool allow_reverse_expansion;
110 bool downsample_obstacle_heuristic;
111 bool use_quadratic_cost_penalty;
112 std::vector<std::vector<MotionPrimitive>> motion_primitives;
113 ompl::base::StateSpacePtr state_space;
114 std::vector<TrigValues> trig_values;
115 std::string current_lattice_filepath;
117 MotionModel motion_model = MotionModel::UNKNOWN;
128 typedef std::unique_ptr<std::vector<NodeLattice>> Graph;
129 typedef std::vector<NodePtr> NodeVector;
131 typedef NodeHybrid::CoordinateVector CoordinateVector;
140 obstacle_heuristic = std::make_unique<ObstacleHeuristic>();
141 distance_heuristic = std::make_unique<DistanceHeuristic<NodeLattice>>();
145 std::unique_ptr<ObstacleHeuristic> obstacle_heuristic;
146 std::unique_ptr<DistanceHeuristic<NodeLattice>> distance_heuristic;
153 explicit NodeLattice(
const uint64_t index, NodeContext * ctx);
167 return this->_index == rhs._index;
190 _motion_primitive = prim;
199 return _motion_primitive;
208 return _accumulated_cost;
217 _accumulated_cost = cost_in;
283 const bool & traverse_unknown,
286 bool is_backwards =
false);
305 const unsigned int & x,
const unsigned int & y,
const unsigned int & angle,
306 const unsigned int & width,
const unsigned int & angle_quantization)
320 const uint64_t & index,
321 const unsigned int & width,
const unsigned int & angle_quantization)
325 (index / angle_quantization) % width,
326 index / (angle_quantization * width),
327 index % angle_quantization);
338 const CoordinateVector & goals_coords);
350 const MotionModel & motion_model,
351 unsigned int & size_x,
352 unsigned int & size_y,
353 unsigned int & angle_quantization,
364 std::function<
bool(
const uint64_t &,
367 const bool & traverse_unknown,
368 NodeVector & neighbors);
381 void addNodeToPath(NodePtr current_node, CoordinateVector & path);
388 float _accumulated_cost;
393 bool _is_node_valid{
false};
394 NodeContext * _ctx =
nullptr;
A costmap grid collision checker.
uint64_t getIndex()
Gets cell index.
NodeLattice implementation for graph, Hybrid-A*.
void getNeighbors(std::function< bool(const uint64_t &, nav2_smac_planner::NodeLattice *&)> &validity_checker, GridCollisionChecker *collision_checker, const bool &traverse_unknown, NodeVector &neighbors)
Retrieve all valid neighbors of a node.
void backwards(bool back=true)
Sets that this primitive is moving in reverse.
static Coordinates getCoords(const uint64_t &index, const unsigned int &width, const unsigned int &angle_quantization)
Get coordinates at index.
void setAccumulatedCost(const float &cost_in)
Sets the accumulated cost at this node.
bool operator==(const NodeLattice &rhs) const
operator== for comparisons
uint64_t getIndex()
Gets cell index.
static void initMotionModel(NodeContext *ctx, const MotionModel &motion_model, unsigned int &size_x, unsigned int &size_y, unsigned int &angle_quantization, SearchInfo &search_info)
Initialize motion models.
~NodeLattice()
A destructor for nav2_smac_planner::NodeLattice.
float getCost()
Gets the costmap cost at this node.
void reset()
Reset method for new search.
NodeLattice(const uint64_t index, NodeContext *ctx)
A constructor for nav2_smac_planner::NodeLattice.
bool backtracePath(CoordinateVector &path)
Set the starting pose for planning, as a node index.
float getTraversalCost(const NodePtr &child)
Get traversal cost of parent node to child node.
void visited()
Sets if cell has been visited in search.
bool isNodeValid(const bool &traverse_unknown, GridCollisionChecker *collision_checker, MotionPrimitive *primitive=nullptr, bool is_backwards=false)
Check if this node is valid.
float getHeuristicCost(const Coordinates &node_coords, const CoordinateVector &goals_coords)
Get cost of heuristic of node.
void addNodeToPath(NodePtr current_node, CoordinateVector &path)
add node to the path
bool isBackward()
Gets if this primitive is moving in reverse.
bool wasVisited()
Gets if cell has been visited in search.
MotionPrimitive *& getMotionPrimitive()
Gets the motion primitive used to achieve node in search.
static uint64_t getIndex(const unsigned int &x, const unsigned int &y, const unsigned int &angle, const unsigned int &width, const unsigned int &angle_quantization)
Get index at coordinates.
void setMotionPrimitive(MotionPrimitive *prim)
Sets the motion primitive used to achieve node in search.
float getAccumulatedCost()
Gets the accumulated cost at this node.
void setPose(const Coordinates &pose_in)
setting continuous coordinate search poses (in partial-cells)
Implementation of coordinate2d structure.
A table of motion primitives and related functions.
static LatticeMetadata getLatticeMetadata(const std::string &lattice_filepath)
Get file metadata needed.
unsigned int getClosestAngularBin(const double &theta)
Get the angular bin to use from a raw orientation.
void initMotionModel(unsigned int &size_x_in, SearchInfo &search_info)
Initializing state lattice planner's motion model.
MotionPrimitivePtrs getMotionPrimitives(const NodeLattice *node, unsigned int &direction_change_index)
Get projections of motion models.
float & getAngleFromBin(const unsigned int &bin_idx)
Get the raw orientation from an angular bin.
double getAngle(const double &theta)
Get the angular bin to use from a raw orientation.
LatticeMotionTable()
A constructor for nav2_smac_planner::LatticeMotionTable.
A struct of all motion primitive data.
NodeContext()
A constructor for nav2_smac_planner::NodeContext.
Search properties and penalties.