42 const geometry_msgs::Pose2D &goal,
43 const nav_2d_msgs::Path2D &global_plan) {
46 unsigned int local_goal_x, local_goal_y;
53 queue_->enqueueCell(local_goal_x, local_goal_y);
75 double position_score = MapGridCritic::scoreTrajectory(traj);
76 double heading_diff = fabs(remainder(traj.poses.back().theta -
desired_angle_, 2 * M_PI));
77 double heading_score = heading_diff * heading_diff;
83 unsigned int &x,
unsigned int &y,
double &desired_angle) {
87 if (global_plan.poses.empty()) {
95 unsigned int start_index = 0;
96 double distance_to_start = std::numeric_limits<double>::infinity();
97 bool started_path =
false;
98 for (
unsigned int i = 0; i < plan.size(); i++) {
99 double g_x = plan[i].x;
100 double g_y = plan[i].y;
101 unsigned int map_x, map_y;
106 if (distance_to_start > distance) {
108 distance_to_start = distance;
115 }
else if (started_path) {
123 ROS_ERROR_NAMED(
"PathProgressCritic",
"None of the points of the global plan were in the local costmap.");
128 unsigned int last_valid_index = start_index;
129 for (
unsigned int i = start_index + 1; i < plan.size(); i++) {
130 double g_x = plan[i].x;
131 double g_y = plan[i].y;
132 unsigned int map_x, map_y;
136 last_valid_index = i;
145 unsigned int goal_index = start_index;
147 while (goal_index < last_valid_index) {
148 goal_index =
getGoalIndex(plan, start_index, last_valid_index);
151 bool goal_already_reached =
false;
155 goal_already_reached =
true;
158 for (start_index = goal_index; start_index <= last_valid_index; ++start_index) {
167 if (!goal_already_reached) {
172 reached_intermediate_goals_.push_back(plan[goal_index]);
173 ROS_DEBUG_NAMED(
"PathProgressCritic",
"Number of reached_intermediate goals: %zu", reached_intermediate_goals_.size());
180 if (start_index > goal_index)
181 start_index = goal_index;
186 desired_angle = plan[start_index].theta;
191 unsigned int start_index,
192 unsigned int last_valid_index)
const {
193 if (start_index >= last_valid_index)
194 return last_valid_index;
196 unsigned int goal_index = start_index;
197 const double start_direction_x = plan[start_index + 1].x - plan[start_index].x;
198 const double start_direction_y = plan[start_index + 1].y - plan[start_index].y;
199 if (fabs(start_direction_x) > 1e-9 || fabs(start_direction_y) > 1e-9) {
200 double start_angle = atan2(start_direction_y, start_direction_x);
202 for (
unsigned int i = start_index + 1; i <= last_valid_index; ++i) {
203 const double current_direction_x = plan[i].x - plan[i - 1].x;
204 const double current_direction_y = plan[i].y - plan[i - 1].y;
205 if (fabs(current_direction_x) > 1e-9 || fabs(current_direction_y) > 1e-9) {
206 double current_angle = atan2(current_direction_y, current_direction_x);
209 if (fabs(remainder(start_angle - current_angle, 2 * M_PI)) >
angle_threshold_)
nav_core2::BasicCostmap costmap
void propogateManhattanDistances()
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
bool prepare(const geometry_msgs::Pose2D &pose, const nav_2d_msgs::Twist2D &vel, const geometry_msgs::Pose2D &goal, const nav_2d_msgs::Path2D &global_plan) override
unsigned int getGoalIndex(const std::vector< geometry_msgs::Pose2D > &plan, unsigned int start_index, unsigned int last_valid_index) const
static const unsigned char NO_INFORMATION
double scoreTrajectory(const dwb_msgs::Trajectory2D &traj) override
double getScale() const override
#define ROS_DEBUG_NAMED(name,...)
double xy_local_goal_tolerance_
double poseDistance(const geometry_msgs::Pose2D &pose0, const geometry_msgs::Pose2D &pose1)
ros::NodeHandle critic_nh_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
nav_core2::Costmap::Ptr costmap_
void setValue(const unsigned int x, const unsigned int y, const T &value) override
nav_2d_msgs::Path2D adjustPlanResolution(const nav_2d_msgs::Path2D &global_plan_in, double resolution)
bool getGoalPose(const geometry_msgs::Pose2D &robot_pose, const nav_2d_msgs::Path2D &global_plan, unsigned int &x, unsigned int &y, double &desired_angle)
#define ROS_ERROR_NAMED(name,...)
Calculates an intermediate goal along the global path and scores trajectories on the distance to that...
std::shared_ptr< MapGridQueue > queue_
nav_grid::VectorNavGrid< double > cell_values_
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
std::vector< geometry_msgs::Pose2D > reached_intermediate_goals_
bool worldToGridBounded(const NavGridInfo &info, double wx, double wy, unsigned int &mx, unsigned int &my)