SMACC
Loading...
Searching...
No Matches
forward_global_planner.cpp
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
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>
12#include <fstream>
13#include <streambuf>
14#include <nav_msgs/Path.h>
15#include <angles/angles.h>
16#include <tf/tf.h>
17#include <tf/transform_datatypes.h>
18
19namespace cl_move_base_z
20{
21namespace forward_global_planner
22{
24 : nh_("~/ForwardGlobalPlanner")
25{
26 skip_straight_motion_distance_ = 0.2; //meters
27 puresSpinningRadStep_ = 1000; // rads
28}
29
30void ForwardGlobalPlanner::initialize(std::string name, costmap_2d::Costmap2DROS *costmap_ros)
31{
32 ROS_INFO("[Forward Global Planner] initializing");
33 planPub_ = nh_.advertise<nav_msgs::Path>("global_plan", 1);
34 skip_straight_motion_distance_ = 0.2; //meters
35 puresSpinningRadStep_ = 1000; // rads
36 this->costmap_ros_ = costmap_ros;
37}
38
39bool ForwardGlobalPlanner::makePlan(const geometry_msgs::PoseStamped &start,
40 const geometry_msgs::PoseStamped &goal, std::vector<geometry_msgs::PoseStamped> &plan,
41 double &cost)
42{
43 ROS_INFO("[Forward Global Planner] planning");
44 cost = 0;
45 return makePlan(start, goal, plan);
46}
47
48bool ForwardGlobalPlanner::makePlan(const geometry_msgs::PoseStamped &start,
49 const geometry_msgs::PoseStamped &goal, std::vector<geometry_msgs::PoseStamped> &plan)
50{
51 //ROS_WARN_STREAM("Forward global plan goal: " << goal);
52
53 //three stages: 1 - heading to goal position, 2 - going forward keep orientation, 3 - heading to goal orientation
54
55 // 1 - heading to goal position
56 // orientation direction
57
58 double dx = goal.pose.position.x - start.pose.position.x;
59 double dy = goal.pose.position.y - start.pose.position.y;
60
61 double length = sqrt(dx * dx + dy * dy);
62
63 geometry_msgs::PoseStamped prevState;
65 {
66 // skip initial pure spinning and initial straight motion
67 //ROS_INFO("1 - heading to goal position pure spinning");
68 double heading_direction = atan2(dy, dx);
69 prevState = cl_move_base_z::makePureSpinningSubPlan(start, heading_direction, plan, puresSpinningRadStep_);
70 //ROS_INFO("2 - going forward keep orientation pure straight");
71 prevState = cl_move_base_z::makePureStraightSubPlan(prevState, goal.pose.position, length, plan);
72 }
73 else
74 {
75 prevState = start;
76 }
77
78 //ROS_INFO("3 - heading to goal orientation");
79 double goalOrientation = angles::normalize_angle(tf::getYaw(goal.pose.orientation));
80 cl_move_base_z::makePureSpinningSubPlan(prevState, goalOrientation, plan, puresSpinningRadStep_);
81
82 nav_msgs::Path planMsg;
83 planMsg.poses = plan;
84 planMsg.header.stamp = ros::Time::now();
85
86 planMsg.header.frame_id = this->costmap_ros_->getGlobalFrameID();
87
88 // check plan rejection
89 bool acceptedGlobalPlan = true;
90
91 // static const unsigned char NO_INFORMATION = 255;
92 // static const unsigned char LETHAL_OBSTACLE = 254;
93 // static const unsigned char INSCRIBED_INFLATED_OBSTACLE = 253;
94 // static const unsigned char FREE_SPACE = 0;
95
96 costmap_2d::Costmap2D *costmap2d = this->costmap_ros_->getCostmap();
97 for (auto &p : plan)
98 {
99 uint32_t mx, my;
100 costmap2d->worldToMap(p.pose.position.x, p.pose.position.y, mx, my);
101 auto cost = costmap2d->getCost(mx, my);
102
103 if (cost >= costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
104 {
105 acceptedGlobalPlan = false;
106 break;
107 }
108 }
109
110 if (acceptedGlobalPlan)
111 {
112 planPub_.publish(planMsg);
113 //ROS_INFO_STREAM("global forward plan: " << planMsg);
114 return true;
115 }
116 else
117 {
118 return false;
119 }
120}
121
122}; // namespace forward_global_planner
123} // namespace cl_move_base_z
124
125//register this planner as a BaseGlobalPlanner plugin
void initialize(std::string name, costmap_2d::Costmap2DROS *costmap_ros_)
costmap_2d::Costmap2DROS * costmap_ros_
stored but almost not used
bool makePlan(const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal, std::vector< geometry_msgs::PoseStamped > &plan)
PLUGINLIB_EXPORT_CLASS(cl_move_base_z::forward_global_planner::ForwardGlobalPlanner, nav_core::BaseGlobalPlanner)
geometry_msgs::PoseStamped makePureStraightSubPlan(const geometry_msgs::PoseStamped &startOrientedPose, const geometry_msgs::Point &goal, double length, std::vector< geometry_msgs::PoseStamped > &plan)
Definition: path_tools.cpp:61
geometry_msgs::PoseStamped makePureSpinningSubPlan(const geometry_msgs::PoseStamped &start, double dstRads, std::vector< geometry_msgs::PoseStamped > &plan, double puresSpinningRadStep=1000)
Definition: path_tools.cpp:13