15 gp_loader_(
"cb_base_navigation",
"cb_global_planner::GlobalPlannerPlugin"),
19 ros::NodeHandle nh(
"~");
24 nh.param(
"global_planner", global_planner,
std::string(
"cb_global_planner::AStarPlannerGPP"));
30 if(!
gp_loader_.isClassAvailable(global_planner)){
32 for(
unsigned int i = 0; i < classes.
size(); ++i){
33 if(global_planner ==
gp_loader_.getName(classes[i])){
34 global_planner = classes[i];
break;
40 }
catch (
const pluginlib::PluginlibException& ex)
42 ROS_FATAL_NAMED(
"GPI",
"Failed to create the %s planner, are you sure it is properly registered and that the containing library is built? Exception: %s", global_planner.
c_str(), ex.what());
52 plan_pub_ = gh.advertise<cb_base_navigation_msgs::LocalPlannerActionGoal>(
"local_planner/action_server/goal",1);
54 ROS_INFO_STREAM_NAMED(
"GPI",
"Subsribed to '" <<
pose_sub_.getTopic() <<
"' for simple pose callbacks and I will send the plans to '" <<
plan_pub_.getTopic() <<
"'.");
59 ROS_INFO_NAMED(
"GPI",
"Simple Pose callback");
61 cb_base_navigation_msgs::GetPlanRequest req;
62 cb_base_navigation_msgs::GetPlanResponse resp;
67 ROS_ERROR_NAMED(
"GPI",
"Could not get global robot pose. We can't generate a plan, sorry.");
71 cb_base_navigation_msgs::PositionConstraint pc;
74 str <<
"(x-" << pose->pose.position.x <<
")^2 + (y-" << pose->pose.position.y <<
")^2 < .05^2";
75 pc.constraint = str.
str();
76 req.goal_position_constraints.push_back(pc);
80 cb_base_navigation_msgs::OrientationConstraint oc;
82 tf2::Quaternion quat_tf;
83 tf2::fromMsg(pose->pose.orientation, quat_tf);
84 oc.look_at.x = pose->pose.position.x + cos(tf2::getYaw(quat_tf));
85 oc.look_at.y = pose->pose.position.y + sin(tf2::getYaw(quat_tf));
87 cb_base_navigation_msgs::LocalPlannerActionGoal goal;
88 goal.goal.orientation_constraint = oc;
89 goal.goal.plan = resp.plan;
91 ROS_INFO_NAMED(
"GPI",
"Succesfully published plan to local planner");
93 ROS_INFO_NAMED(
"GPI",
"I can't find a valid plan to there");
96 ROS_ERROR_NAMED(
"GPI",
"Could not get a plan");
107 ROS_ERROR_NAMED(
"GPI",
"No plan specified so no check can be performed.");
116 if (req.start.header.frame_id.empty())
118 ROS_ERROR_NAMED(
"GPI",
"Start pose can't be empty");
126 if(req.goal_position_constraints.size() > 1) { ROS_ERROR_NAMED(
"GPI",
"You have specified more than 1 constraint, this is not yet supported.");
return false; }
127 if(req.goal_position_constraints.size() == 0) { ROS_ERROR_NAMED(
"GPI",
"No goal position constraint specified, planner cannot create plan.");
return false; }
133 if(
global_planner_->makePlan(req.start, req.goal_position_constraints[0], resp.plan, goal_positions)) {