6#include <boost/assign.hpp>
7#include <boost/range/adaptor/reversed.hpp>
8#include <boost/range/algorithm/copy.hpp>
9#include <pluginlib/class_list_macros.h>
13#include <nav_msgs/Path.h>
14#include <visualization_msgs/MarkerArray.h>
16#include <tf/transform_datatypes.h>
17#include <angles/angles.h>
25 namespace undo_path_global_planner
40 nav_msgs::Path planMsg;
41 planMsg.header.stamp = ros::Time::now();
59 planPub_ = nh.advertise<nav_msgs::Path>(
"undo_path_planner/global_plan", 1);
60 markersPub_ = nh.advertise<visualization_msgs::MarkerArray>(
"undo_path_planner/markers", 1);
71 ROS_DEBUG_STREAM(
"[UndoPathGlobalPlanner] received backward path msg poses [" <<
lastForwardPathMsg_.poses.size() <<
"]");
81 double phi = tf::getYaw(pose.orientation);
82 visualization_msgs::Marker marker;
83 marker.header.frame_id = this->
costmap_ros_->getGlobalFrameID();
84 marker.header.stamp = ros::Time::now();
85 marker.ns =
"my_namespace2";
87 marker.type = visualization_msgs::Marker::ARROW;
88 marker.action = visualization_msgs::Marker::ADD;
97 geometry_msgs::Point start, end;
98 start.x = pose.position.x;
99 start.y = pose.position.y;
101 end.x = pose.position.x + 0.5 * cos(phi);
102 end.y = pose.position.y + 0.5 * sin(phi);
104 marker.points.push_back(start);
105 marker.points.push_back(end);
107 visualization_msgs::MarkerArray ma;
108 ma.markers.push_back(marker);
119 const geometry_msgs::PoseStamped &goal,
120 std::vector<geometry_msgs::PoseStamped> &plan)
124 double linear_mindist = std::numeric_limits<double>::max();
125 int mindistindex = -1;
126 double startPoseAngle = tf::getYaw(start.pose.orientation);
127 geometry_msgs::Pose startPositionProjected;
135 geometry_msgs::PoseStamped pose = p;
136 pose.header.frame_id =
costmap_ros_->getGlobalFrameID();
137 pose.header.stamp = ros::Time::now();
139 double dx = pose.pose.position.x - start.pose.position.x;
140 double dy = pose.pose.position.y - start.pose.position.y;
142 double dist = sqrt(dx * dx + dy * dy);
143 double angleOrientation = tf::getYaw(pose.pose.orientation);
144 double angleError = fabs(angles::shortest_angular_distance(angleOrientation, startPoseAngle));
145 if (dist <= linear_mindist)
148 linear_mindist = dist;
149 startPositionProjected = pose.pose;
151 ROS_DEBUG_STREAM(
"[UndoPathGlobalPlanner] initial start point search, NEWBEST_LINEAR= " << i <<
". error, linear: " << linear_mindist <<
", angular: " << angleError);
155 ROS_DEBUG_STREAM(
"[UndoPathGlobalPlanner] initial start point search, skipped= " << i <<
". best linear error: " << linear_mindist <<
". current error, linear: " << dist <<
" angular: " << angleError);
161 double const ERROR_DISTANCE_PURE_SPINNING_FACTOR = 1.5;
164 ROS_DEBUG(
"[UndoPathGlobalPlanner] second angular pass");
165 double angularMinDist = std::numeric_limits<double>::max();
172 ROS_WARN_STREAM(
"[UndoPathGlobalPlanner] Warning possible bug");
175 ROS_DEBUG_STREAM(
"[UndoPathGlobalPlanner] second pass loop");
176 for (
int i = mindistindex; i >= 0; i--)
180 ROS_DEBUG_STREAM(
"[UndoPathGlobalPlanner] " << i <<
"/" <<
lastForwardPathMsg_.poses.size());
184 ROS_WARN_STREAM(
"[UndoPathGlobalPlanner] this should not happen. Check implementation.");
189 ROS_DEBUG_STREAM(
"[UndoPathGlobalPlanner] global frame");
190 pose.header.frame_id =
costmap_ros_->getGlobalFrameID();
191 pose.header.stamp = ros::Time::now();
193 double dx = pose.pose.position.x - start.pose.position.x;
194 double dy = pose.pose.position.y - start.pose.position.y;
196 double dist = sqrt(dx * dx + dy * dy);
197 if (dist <= linear_mindist * ERROR_DISTANCE_PURE_SPINNING_FACTOR)
199 double angleOrientation = tf::getYaw(pose.pose.orientation);
200 double angleError = fabs(angles::shortest_angular_distance(angleOrientation, startPoseAngle));
201 if (angleError < angularMinDist)
203 angularMinDist = angleError;
205 ROS_DEBUG_STREAM(
"[UndoPathGlobalPlanner] initial start point search (angular update), NEWBEST_ANGULAR= " << i <<
". error, linear: "<< dist <<
"(" << linear_mindist <<
")" <<
", angular: " << angleError <<
"(" << angularMinDist <<
")");
209 ROS_DEBUG_STREAM(
"[UndoPathGlobalPlanner] initial start point search (angular update), skipped= " << i <<
". error, linear: "<< dist <<
"(" << linear_mindist <<
")" <<
", angular: " << angleError <<
"(" << angularMinDist <<
")");
214 ROS_DEBUG_STREAM(
"[UndoPathGlobalPlanner] initial start point search (angular update) not in linear range, skipped= " << i <<
" linear error: " << dist <<
"(" << linear_mindist <<
")");
219 if (mindistindex != -1)
223 ROS_WARN_STREAM(
"[UndoPathGlobalPlanner] Creating the backwards plan from odom tracker path (" <<
lastForwardPathMsg_.poses.size() <<
") poses");
224 ROS_WARN_STREAM(
"[UndoPathGlobalPlanner] closer point to goal i=" << mindistindex <<
" (linear min dist " << linear_mindist <<
")");
229 ROS_DEBUG_STREAM(
"[UndoPathGlobalPlanner] adding to plan i = " << i);
230 plan.push_back(pose);
232 ROS_WARN_STREAM(
"[UndoPathGlobalPlanner] refined plan has " << plan.size() <<
" points");
236 ROS_ERROR_STREAM(
"[UndoPathGlobalPlanner ] backward global plan size: " << plan.size());
248 const geometry_msgs::PoseStamped &goal, std::vector<geometry_msgs::PoseStamped> &plan)
274 nav_msgs::Path planMsg;
275 planMsg.poses = plan;
276 planMsg.header.frame_id = this->
costmap_ros_->getGlobalFrameID();
279 bool acceptedGlobalPlan =
true;
286 costmap_2d::Costmap2D *costmap2d = this->
costmap_ros_->getCostmap();
290 costmap2d->worldToMap(p.pose.position.x, p.pose.position.y, mx, my);
291 auto cost = costmap2d->getCost(mx, my);
293 if (cost >= costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
295 acceptedGlobalPlan =
false;
312 const geometry_msgs::PoseStamped &goal, std::vector<geometry_msgs::PoseStamped> &plan,
ros::Subscriber forwardPathSub_
void publishGoalMarker(const geometry_msgs::Pose &pose, double r, double g, double b)
bool makePlan(const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal, std::vector< geometry_msgs::PoseStamped > &plan)
virtual bool createDefaultUndoPathPlan(const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal, std::vector< geometry_msgs::PoseStamped > &plan)
virtual void initialize(std::string name, costmap_2d::Costmap2DROS *costmap_ros_) override
nav_msgs::Path lastForwardPathMsg_
double skip_straight_motion_distance_
virtual ~UndoPathGlobalPlanner()
costmap_2d::Costmap2DROS * costmap_ros_
stored but almost not used
ros::Publisher markersPub_
void onForwardTrailMsg(const nav_msgs::Path::ConstPtr &trailMessage)
PLUGINLIB_EXPORT_CLASS(cl_move_base_z::undo_path_global_planner::UndoPathGlobalPlanner, nav_core::BaseGlobalPlanner)