15 #ifndef NAV2_SMAC_PLANNER__UTILS_HPP_
16 #define NAV2_SMAC_PLANNER__UTILS_HPP_
22 #include "geometry_msgs/msg/quaternion.hpp"
23 #include "geometry_msgs/msg/pose.hpp"
24 #include "tf2/utils.h"
25 #include "nav2_costmap_2d/costmap_2d_ros.hpp"
26 #include "nav2_costmap_2d/inflation_layer.hpp"
28 namespace nav2_smac_planner
38 inline geometry_msgs::msg::Pose getWorldCoords(
41 geometry_msgs::msg::Pose msg;
54 inline geometry_msgs::msg::Quaternion getWorldOrientation(
59 q.setEuler(0.0, 0.0, theta);
70 inline double findCircumscribedCost(std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap)
73 bool inflation_layer_found =
false;
74 std::vector<std::shared_ptr<nav2_costmap_2d::Layer>>::iterator layer;
77 for (layer = costmap->getLayeredCostmap()->getPlugins()->begin();
78 layer != costmap->getLayeredCostmap()->getPlugins()->end();
81 std::shared_ptr<nav2_costmap_2d::InflationLayer> inflation_layer =
82 std::dynamic_pointer_cast<nav2_costmap_2d::InflationLayer>(*layer);
83 if (!inflation_layer) {
87 inflation_layer_found =
true;
88 double circum_radius = costmap->getLayeredCostmap()->getCircumscribedRadius();
89 double resolution = costmap->getCostmap()->getResolution();
90 result =
static_cast<double>(inflation_layer->computeCost(circum_radius / resolution));
93 if (!inflation_layer_found) {
95 rclcpp::get_logger(
"computeCircumscribedCost"),
96 "No inflation layer found in costmap configuration. "
97 "If this is an SE2-collision checking plugin, it cannot use costmap potential "
98 "field to speed up collision checking by only checking the full footprint "
99 "when robot is within possibly-inscribed radius of an obstacle. This may "
100 "significantly slow down planning times!");
111 inline void fromJsonToMetaData(
const nlohmann::json & json, LatticeMetadata & lattice_metadata)
113 json.at(
"turning_radius").get_to(lattice_metadata.min_turning_radius);
114 json.at(
"grid_resolution").get_to(lattice_metadata.grid_resolution);
115 json.at(
"num_of_headings").get_to(lattice_metadata.number_of_headings);
116 json.at(
"heading_angles").get_to(lattice_metadata.heading_angles);
117 json.at(
"number_of_trajectories").get_to(lattice_metadata.number_of_trajectories);
118 json.at(
"motion_model").get_to(lattice_metadata.motion_model);
126 inline void fromJsonToPose(
const nlohmann::json & json, MotionPose & pose)
130 pose._theta = json[2];
138 inline void fromJsonToMotionPrimitive(
139 const nlohmann::json & json, MotionPrimitive & motion_primitive)
141 json.at(
"trajectory_id").get_to(motion_primitive.trajectory_id);
142 json.at(
"start_angle_index").get_to(motion_primitive.start_angle);
143 json.at(
"end_angle_index").get_to(motion_primitive.end_angle);
144 json.at(
"trajectory_radius").get_to(motion_primitive.turning_radius);
145 json.at(
"trajectory_length").get_to(motion_primitive.trajectory_length);
146 json.at(
"arc_length").get_to(motion_primitive.arc_length);
147 json.at(
"straight_length").get_to(motion_primitive.straight_length);
148 json.at(
"left_turn").get_to(motion_primitive.left_turn);
150 for (
unsigned int i = 0; i < json[
"poses"].size(); i++) {
152 fromJsonToPose(json[
"poses"][i], pose);
153 motion_primitive.poses.push_back(pose);
A 2D costmap provides a mapping between points in the world and their associated "costs".
double getResolution() const
Accessor for the resolution of the costmap.
double getOriginY() const
Accessor for the y origin of the costmap.
double getOriginX() const
Accessor for the x origin of the costmap.