3 #include <pluginlib/class_list_macros.h>
6 #include <ed_msgs/SimpleQuery.h>
8 #include <ros/console.h>
10 #include <tf2/utils.h>
22 if (
id ==
"map" ||
id ==
"/map")
24 pose = tf2::Transform::getIdentity();
28 ed_msgs::SimpleQuery ed_query;
29 ed_query.request.id = id;
31 ROS_DEBUG_STREAM(
"[A* Planner] Querying ed for entity '" <<
id <<
"'");
33 if (!ed_client_.call(ed_query))
35 ROS_ERROR_STREAM(
"[A* Planner] Failed to get pose for entity '" <<
id <<
"': ED could not be queried");
39 if (ed_query.response.entities.empty())
41 ROS_ERROR_STREAM(
"[A* Planner] Failed to get pose for entity '" <<
id <<
"': ED returns 'no such entity'");
45 const ed_msgs::EntityInfo& e_info = ed_query.response.entities.front();
47 tf2::fromMsg(e_info.pose, pose);
68 ed_client_ = nh.serviceClient<ed_msgs::SimpleQuery>(
"ed/simple_query");
70 ROS_INFO(
"A* Global planner initialized.");
80 if (!
initialized_) { ROS_WARN(
"The global planner is not initialized! It's not possible to create a global plan.");
return false; }
84 goal_positions.
clear();
87 if (pc.frame ==
"" && pc.constraint ==
"")
90 unsigned int mx_start, my_start;
92 ROS_WARN(
"The robot's start position is off the global costmap. Planning will always fail, are you sure the robot has been properly localized?");
93 ROS_ERROR_STREAM(
"Received position constraint: " << pc);
104 ROS_WARN(
"Failed to update constraint positions in constraint frame.");
105 ROS_ERROR_STREAM(
"Received position constraint: " << pc);
114 ROS_ERROR_STREAM(
"Received position constraint: " << pc);
118 if(mx_goal.
size() == 0) {
119 ROS_ERROR(
"There is no goal which meets the given constraints. Planning will always fail to this goal constraint.");
120 ROS_ERROR_STREAM(
"Received position constraint: " << pc);
127 for (
unsigned int i = 0; i < mx_goal.
size(); i++) {
154 planner_->plan(mx_free, my_free, mx_start, my_start, plan_xs, plan_ys);
157 if (plan_xs.
empty()) {
158 planner_->plan(mx_low, my_low, mx_start, my_start, plan_xs, plan_ys);
162 if (plan_xs.
empty()) {
163 planner_->plan(mx_high, my_high, mx_start, my_start, plan_xs, plan_ys);
187 ROS_ERROR(
"No connectivity to specified constraint found, sorry :(");
189 ROS_INFO(
"A* planner succesfully generated plan :)");
196 ROS_INFO(
"Position constraint has been changed, updating positions in constraint frame.");
202 tf2::Transform world_to_constraint_tf;
206 tf2::Transform constraint_to_world_tf = world_to_constraint_tf.inverse();
217 if (!ce.
init(pc.constraint)) {
218 ROS_ERROR(
"Could not setup goal constraints...");
228 tf2::Vector3 pc(wx,wy,0);
229 pc = constraint_to_world_tf*pc;
232 ROS_DEBUG_STREAM(
"Pushing back in constraint frame point: (" << pc.x() <<
", " << pc.y() <<
")");
242 ROS_DEBUG(
"Calculating map constraint area");
245 tf2::Stamped<tf2::Transform> world_to_constraint_tf;
259 tf2::Vector3 pw = world_to_constraint_tf * *it;
271 ROS_DEBUG_STREAM(
"Pushing back in map point: (" << x <<
", " << y <<
")");
280 ros::Time plan_time = ros::Time::now();
284 for(
unsigned int i = 0; i < plan_xs.
size(); ++i) {
285 double world_x, world_y;
288 plan[i].header.stamp = plan_time;
289 plan[i].header.frame_id = global_frame;
290 plan[i].pose.position.x = world_x;
291 plan[i].pose.position.y = world_y;
292 plan[i].pose.position.z = 0;
294 unsigned int size = 5;
296 if (i+size < plan_xs.
size())
299 double yaw = atan2(world_y - plan[i].pose.position.y, world_x - plan[i].pose.position.x);
300 tf2::Quaternion quat_tf;
301 quat_tf.setRPY(0, 0, yaw);
302 plan[i].pose.orientation = tf2::toMsg(quat_tf);
304 else if (plan_xs.
size() > size)
306 plan[i].pose.orientation = plan[i-1].pose.orientation;
317 geometry_msgs::PoseStamped p;