SMACC
Loading...
Searching...
No Matches
pure_spinning_local_planner.cpp
Go to the documentation of this file.
1
2#include <angles/angles.h>
4#include <pluginlib/class_list_macros.h>
5
7
8namespace cl_move_base_z
9{
10namespace pure_spinning_local_planner
11{
12// MELODIC
13#if ROS_VERSION_MINIMUM(1, 13, 0)
14tf::Stamped<tf::Pose> optionalRobotPose(costmap_2d::Costmap2DROS *costmapRos)
15{
16 geometry_msgs::PoseStamped paux;
17 costmapRos->getRobotPose(paux);
18 tf::Stamped<tf::Pose> tfpose;
19 tf::poseStampedMsgToTF(paux, tfpose);
20 return tfpose;
21}
22#else
23// INDIGO AND PREVIOUS
24tf::Stamped<tf::Pose> optionalRobotPose(costmap_2d::Costmap2DROS *costmapRos)
25{
26 tf::Stamped<tf::Pose> tfpose;
27 costmapRos->getRobotPose(tfpose);
28 return tfpose;
29}
30#endif
31
33 : paramServer_(ros::NodeHandle("~PureSpinningLocalPlanner"))
34{
35 ROS_INFO_STREAM("[PureSpinningLocalPlanner] pure spinning planner already created");
36}
37
39{
40}
41
42void PureSpinningLocalPlanner::initialize(std::string name, tf2_ros::Buffer *tf, costmap_2d::Costmap2DROS *costmapRos)
43{
44 costmapRos_ = costmapRos;
45 this->initialize();
46}
47
48void PureSpinningLocalPlanner::initialize(std::string name, tf::TransformListener *tf,
49 costmap_2d::Costmap2DROS *costmapRos)
50{
51 costmapRos_ = costmapRos;
52 this->initialize();
53}
54
56{
57 ros::NodeHandle nh("~/PureSpinningLocalPlanner");
58 nh.param("k_betta", k_betta_, 10.0);
59 nh.param("yaw_goal_tolerance", yaw_goal_tolerance_, 0.08);
60 nh.param("intermediate_goals_yaw_tolerance", intermediate_goal_yaw_tolerance_, 0.12);
61 nh.param("max_angular_z_speed", max_angular_z_speed_, 1.0);
62
63 dynamic_reconfigure::Server<::pure_spinning_local_planner::PureSpinningLocalPlannerConfig>::CallbackType f;
64 f = boost::bind(&PureSpinningLocalPlanner::reconfigCB, this, _1, _2);
65 paramServer_.setCallback(f);
66}
67
68void PureSpinningLocalPlanner::reconfigCB(::pure_spinning_local_planner::PureSpinningLocalPlannerConfig &config, uint32_t level)
69{
70 this->k_betta_ = config.k_betta;
71 this->yaw_goal_tolerance_ = config.yaw_goal_tolerance;
72 this->max_angular_z_speed_ = config.max_angular_z_speed;
73}
74bool PureSpinningLocalPlanner::computeVelocityCommands(geometry_msgs::Twist &cmd_vel)
75{
76 goalReached_ = false;
77 // ROS_DEBUG("LOCAL PLANNER LOOP");
78
79 tf::Stamped<tf::Pose> tfpose = optionalRobotPose(costmapRos_);
80
81 geometry_msgs::PoseStamped currentPose;
82 tf::poseStampedTFToMsg(tfpose, currentPose);
83 // ROS_INFO_STREAM("[PureSpinningLocalPlanner] current robot pose " << currentPose);
84
85 tf::Quaternion q = tfpose.getRotation();
86 auto currentYaw = tf::getYaw(currentPose.pose.orientation);
87 double angular_error;
88 double targetYaw;
89
90 while (currentPoseIndex_ < plan_.size())
91 {
92 auto &goal = plan_[currentPoseIndex_];
93 targetYaw = tf::getYaw(goal.pose.orientation);
94
95 //double angular_error = angles::shortest_angular_distance( currentYaw , targetYaw) ;
96 angular_error = targetYaw - currentYaw ;
97
98 // all the points must be reached using the control rule, but the last one
99 // have an special condition
100 if ( (currentPoseIndex_ < plan_.size() -1 && fabs(angular_error) < this->intermediate_goal_yaw_tolerance_)
101 || (currentPoseIndex_ == plan_.size() -1 && fabs(angular_error) < this->intermediate_goal_yaw_tolerance_)
102 )
103 {
105 }
106 else
107 {
108 break;
109 }
110 }
111
112 auto omega = angular_error * k_betta_;
113 cmd_vel.angular.z = std::min(std::max(omega, -fabs(max_angular_z_speed_)), fabs(max_angular_z_speed_));
114
115 //ROS_DEBUG_STREAM("[PureSpinningLocalPlanner] current yaw: " << currentYaw);
116 //ROS_DEBUG_STREAM("[PureSpinningLocalPlanner] target yaw: " << targetYaw);
117 ROS_DEBUG_STREAM("[PureSpinningLocalPlanner] angular error: " << angular_error << "("<<yaw_goal_tolerance_<<")");
118 ROS_DEBUG_STREAM("[PureSpinningLocalPlanner] command angular speed: " << cmd_vel.angular.z);
119 ROS_DEBUG_STREAM("[PureSpinningLocalPlanner] completion " << currentPoseIndex_ << "/"<< plan_.size());
120
121 if (currentPoseIndex_ >= plan_.size() -1 && fabs(angular_error) < yaw_goal_tolerance_)
122 {
123 ROS_DEBUG_STREAM("[PureSpinningLocalPlanner] GOAL REACHED ");
124 goalReached_ = true;
125 }
126
127 return true;
128}
129
131{
132 return goalReached_;
133}
134
135bool PureSpinningLocalPlanner::setPlan(const std::vector<geometry_msgs::PoseStamped> &plan)
136{
137 ROS_DEBUG_STREAM("[PureSpinningLocalPlanner] setting global plan to follow");
138
139 plan_ = plan;
140 goalReached_ = false;
142 return true;
143}
144
145void publishGoalMarker(double x, double y, double phi)
146{
147}
148} // namespace pure_spinning_local_planner
149} // namespace cl_move_base_z
PLUGINLIB_EXPORT_CLASS(cl_move_base_z::backward_global_planner::BackwardGlobalPlanner, nav_core::BaseGlobalPlanner)
void reconfigCB(::pure_spinning_local_planner::PureSpinningLocalPlannerConfig &config, uint32_t level)
dynamic_reconfigure::Server<::pure_spinning_local_planner::PureSpinningLocalPlannerConfig > paramServer_
virtual bool setPlan(const std::vector< geometry_msgs::PoseStamped > &plan) override
Set the plan that the local planner is following.
virtual bool isGoalReached() override
Check if the goal pose has been achieved by the local planner.
virtual bool computeVelocityCommands(geometry_msgs::Twist &cmd_vel) override
Given the current position, orientation, and velocity of the robot: compute velocity commands to send...
tf::Stamped< tf::Pose > optionalRobotPose(costmap_2d::Costmap2DROS *costmapRos)
void publishGoalMarker(double x, double y, double phi)