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>
25namespace backward_global_planner
40 nav_msgs::Path planMsg;
41 planMsg.header.stamp = ros::Time::now();
57 planPub_ = nh.advertise<nav_msgs::Path>(
"backward_planner/global_plan", 1);
58 markersPub_ = nh.advertise<visualization_msgs::MarkerArray>(
"backward_planner/markers", 1);
68 double phi = tf::getYaw(pose.orientation);
69 visualization_msgs::Marker marker;
70 marker.header.frame_id = this->
costmap_ros_->getGlobalFrameID();
71 marker.header.stamp = ros::Time::now();
72 marker.ns =
"my_namespace2";
74 marker.type = visualization_msgs::Marker::ARROW;
75 marker.action = visualization_msgs::Marker::ADD;
84 geometry_msgs::Point start, end;
85 start.x = pose.position.x;
86 start.y = pose.position.y;
88 end.x = pose.position.x + 0.5 * cos(phi);
89 end.y = pose.position.y + 0.5 * sin(phi);
91 marker.points.push_back(start);
92 marker.points.push_back(end);
94 visualization_msgs::MarkerArray ma;
95 ma.markers.push_back(marker);
106 const geometry_msgs::PoseStamped &goal, std::vector<geometry_msgs::PoseStamped> &plan)
108 auto q = start.pose.orientation;
110 geometry_msgs::PoseStamped pose;
113 double dx = start.pose.position.x - goal.pose.position.x;
114 double dy = start.pose.position.y - goal.pose.position.y;
116 double length = sqrt(dx * dx + dy * dy);
118 geometry_msgs::PoseStamped prevState;
123 double heading_direction = atan2(dy, dx);
124 double startyaw = tf::getYaw(q);
125 double offset = angles::shortest_angular_distance(startyaw, heading_direction);
126 heading_direction = startyaw + offset;
138 ROS_WARN_STREAM(
"[BackwardGlobalPlanner ] backward global plan size: " <<plan.size());
148 const geometry_msgs::PoseStamped &goal, std::vector<geometry_msgs::PoseStamped> &plan)
168 nav_msgs::Path planMsg;
169 planMsg.poses = plan;
170 planMsg.header.frame_id = this->
costmap_ros_->getGlobalFrameID();
173 bool acceptedGlobalPlan =
true;
180 costmap_2d::Costmap2D *costmap2d = this->
costmap_ros_->getCostmap();
184 costmap2d->worldToMap(p.pose.position.x, p.pose.position.y, mx, my);
185 auto cost = costmap2d->getCost(mx, my);
187 if (cost >= costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
189 acceptedGlobalPlan =
false;
206 const geometry_msgs::PoseStamped &goal, std::vector<geometry_msgs::PoseStamped> &plan,
PLUGINLIB_EXPORT_CLASS(cl_move_base_z::backward_global_planner::BackwardGlobalPlanner, nav_core::BaseGlobalPlanner)
double skip_straight_motion_distance_
double puresSpinningRadStep_
virtual bool createDefaultBackwardPath(const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal, std::vector< geometry_msgs::PoseStamped > &plan)
virtual ~BackwardGlobalPlanner()
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)
ros::Publisher markersPub_
costmap_2d::Costmap2DROS * costmap_ros_
virtual void initialize(std::string name, costmap_2d::Costmap2DROS *costmap_ros_) override
geometry_msgs::PoseStamped makePureStraightSubPlan(const geometry_msgs::PoseStamped &startOrientedPose, const geometry_msgs::Point &goal, double length, std::vector< geometry_msgs::PoseStamped > &plan)
geometry_msgs::PoseStamped makePureSpinningSubPlan(const geometry_msgs::PoseStamped &start, double dstRads, std::vector< geometry_msgs::PoseStamped > &plan, double puresSpinningRadStep=1000)