35 #include "dwb_critics/goal_dist.hpp"
37 #include "pluginlib/class_list_macros.hpp"
38 #include "nav_2d_utils/path_ops.hpp"
39 #include "nav2_costmap_2d/cost_values.hpp"
44 const geometry_msgs::msg::Pose &,
const nav_2d_msgs::msg::Twist2D &,
45 const geometry_msgs::msg::Pose &,
46 const nav_msgs::msg::Path & global_plan)
50 unsigned int local_goal_x, local_goal_y;
51 if (!getLastPoseOnCostmap(global_plan, local_goal_x, local_goal_y)) {
56 int index = costmap_->
getIndex(local_goal_x, local_goal_y);
57 cell_values_[index] = 0.0;
58 queue_->enqueueCell(local_goal_x, local_goal_y);
65 bool GoalDistCritic::getLastPoseOnCostmap(
66 const nav_msgs::msg::Path & global_plan,
67 unsigned int & x,
unsigned int & y)
69 nav_msgs::msg::Path adjusted_global_plan = nav_2d_utils::adjustPlanResolution(
72 bool started_path =
false;
75 for (
unsigned int i = 0; i < adjusted_global_plan.poses.size(); ++i) {
76 double g_x = adjusted_global_plan.poses[i].pose.position.x;
77 double g_y = adjusted_global_plan.poses[i].pose.position.y;
78 unsigned int map_x, map_y;
81 map_y) && costmap_->
getCost(map_x, map_y) != nav2_costmap_2d::NO_INFORMATION)
87 }
else if (started_path) {
99 "GoalDistCritic"),
"None of the points of the global plan were in the local costmap.");
Evaluates a Trajectory2D to produce a score.
Scores trajectories based on how far along the global path they end up.
bool prepare(const geometry_msgs::msg::Pose &pose, const nav_2d_msgs::msg::Twist2D &vel, const geometry_msgs::msg::Pose &goal, const nav_msgs::msg::Path &global_plan) override
Prior to evaluating any trajectories, look at contextual information constant across all trajectories...
void reset() override
Clear the queueDWB_CRITICS_MAP_GRID_He and set cell_values_ to the appropriate number of unreachableC...
void propagateManhattanDistances()
Go through the queue and set the cells to the Manhattan distance from their parents.
unsigned int getIndex(unsigned int mx, unsigned int my) const
Given two map coordinates... compute the associated index.
unsigned char getCost(unsigned int mx, unsigned int my) const
Get the cost of a cell in the costmap.
bool worldToMap(double wx, double wy, unsigned int &mx, unsigned int &my) const
Convert from world coordinates to map coordinates.
double getResolution() const
Accessor for the resolution of the costmap.