50 : costmap_ros_(NULL), costmap_(NULL), world_model_(NULL), initialized_(false){}
53 : costmap_ros_(NULL), costmap_(NULL), world_model_(NULL), initialized_(false){
57 CarrotPlanner::~CarrotPlanner() {
64 costmap_ros_ = costmap_ros;
68 private_nh.param(
"step_size", step_size_, costmap_->getResolution());
69 private_nh.param(
"min_dist_from_robot", min_dist_from_robot_, 0.10);
75 ROS_WARN(
"This planner has already been initialized... doing nothing");
79 double CarrotPlanner::footprintCost(
double x_i,
double y_i,
double theta_i){
81 ROS_ERROR(
"The planner has not been initialized, please call initialize() to use the planner");
85 std::vector<geometry_msgs::Point> footprint = costmap_ros_->getRobotFootprint();
87 if(footprint.size() < 3)
91 double footprint_cost = world_model_->footprintCost(x_i, y_i, theta_i, footprint);
92 return footprint_cost;
96 bool CarrotPlanner::makePlan(
const geometry_msgs::PoseStamped& start,
97 const geometry_msgs::PoseStamped& goal, std::vector<geometry_msgs::PoseStamped>& plan){
100 ROS_ERROR(
"The planner has not been initialized, please call initialize() to use the planner");
104 ROS_DEBUG(
"Got a start: %.2f, %.2f, and a goal: %.2f, %.2f",
start.pose.position.x,
start.pose.position.y, goal.pose.position.x, goal.pose.position.y);
107 costmap_ = costmap_ros_->getCostmap();
109 if(goal.header.frame_id != costmap_ros_->getGlobalFrameID()){
110 ROS_ERROR(
"This planner as configured will only accept goals in the %s frame, but a goal was sent in the %s frame.",
111 costmap_ros_->getGlobalFrameID().c_str(), goal.header.frame_id.c_str());
116 const double goal_yaw =
tf2::getYaw(goal.pose.orientation);
119 double goal_x = goal.pose.position.x;
120 double goal_y = goal.pose.position.y;
121 double start_x =
start.pose.position.x;
122 double start_y =
start.pose.position.y;
124 double diff_x = goal_x - start_x;
125 double diff_y = goal_y - start_y;
128 double target_x = goal_x;
129 double target_y = goal_y;
130 double target_yaw = goal_yaw;
134 double dScale = 0.01;
142 target_yaw = start_yaw;
143 ROS_WARN(
"The carrot planner could not find a valid plan for this goal");
146 target_x = start_x + scale * diff_x;
147 target_y = start_y + scale * diff_y;
150 double footprint_cost = footprintCost(target_x, target_y, target_yaw);
151 if(footprint_cost >= 0)
158 plan.push_back(start);
159 geometry_msgs::PoseStamped new_goal = goal;
161 goal_quat.
setRPY(0, 0, target_yaw);
163 new_goal.pose.position.x = target_x;
164 new_goal.pose.position.y = target_y;
166 new_goal.pose.orientation.x = goal_quat.x();
167 new_goal.pose.orientation.y = goal_quat.y();
168 new_goal.pose.orientation.z = goal_quat.z();
169 new_goal.pose.orientation.w = goal_quat.w();
171 plan.push_back(new_goal);