path_angle.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2019, DFKI GmbH
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
37 #include <nav_2d_utils/path_ops.h>
39 #include <vector>
40 
41 namespace mir_dwb_critics {
42 
43 bool PathAngleCritic::prepare(const geometry_msgs::Pose2D &pose, const nav_2d_msgs::Twist2D &vel,
44  const geometry_msgs::Pose2D &goal, const nav_2d_msgs::Path2D &global_plan) {
46  const nav_grid::NavGridInfo &info = costmap.getInfo();
47  nav_2d_msgs::Path2D adjusted_global_plan = nav_2d_utils::adjustPlanResolution(global_plan, info.resolution);
48 
49  if (global_plan.poses.empty()) {
50  ROS_ERROR_NAMED("PathAngleCritic", "The global plan was empty.");
51  return false;
52  }
53 
54  // find the angle of the plan at the pose on the plan closest to the robot
55  double distance_min = std::numeric_limits<double>::infinity();
56  bool started_path = false;
57  for (unsigned int i = 0; i < adjusted_global_plan.poses.size(); i++) {
58  double g_x = adjusted_global_plan.poses[i].x;
59  double g_y = adjusted_global_plan.poses[i].y;
60  unsigned int map_x, map_y;
61  if (worldToGridBounded(info, g_x, g_y, map_x, map_y) && costmap(map_x, map_y) != costmap.NO_INFORMATION) {
62  double distance = nav_2d_utils::poseDistance(adjusted_global_plan.poses[i], pose);
63  if (distance_min > distance) {
64  // still getting closer
65  desired_angle_ = adjusted_global_plan.poses[i].theta;
66  distance_min = distance;
67  started_path = true;
68  } else {
69  // plan is going away from the robot again
70  break;
71  }
72  } else if (started_path) {
73  // Off the costmap after being on the costmap.
74  break;
75  }
76  // else, we have not yet found a point on the costmap, so we just continue
77  }
78 
79  if (!started_path) {
80  ROS_ERROR_NAMED("PathAngleCritic", "None of the points of the global plan were in the local costmap.");
81  return false;
82  }
83  return true;
84 }
85 
86 double PathAngleCritic::scoreTrajectory(const dwb_msgs::Trajectory2D &traj) {
87  double diff = fabs(remainder(traj.poses.back().theta - desired_angle_, 2 * M_PI));
88  return diff * diff;
89 }
90 
91 } // namespace mir_dwb_critics
92 
Scores trajectories based on the difference between the path&#39;s current angle and the trajectory&#39;s ang...
Definition: path_angle.h:57
nav_core2::BasicCostmap costmap
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
static const unsigned char NO_INFORMATION
double poseDistance(const geometry_msgs::Pose2D &pose0, const geometry_msgs::Pose2D &pose1)
nav_core2::Costmap::Ptr costmap_
nav_2d_msgs::Path2D adjustPlanResolution(const nav_2d_msgs::Path2D &global_plan_in, double resolution)
virtual double scoreTrajectory(const dwb_msgs::Trajectory2D &traj) override
Definition: path_angle.cpp:86
#define ROS_ERROR_NAMED(name,...)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
virtual 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
Definition: path_angle.cpp:43
bool worldToGridBounded(const NavGridInfo &info, double wx, double wy, unsigned int &mx, unsigned int &my)


mir_dwb_critics
Author(s): Martin Günther
autogenerated on Sun Feb 14 2021 03:40:12