48 const std::string &name,
59 const mbf_msgs::GetPathGoal& goal = *(goal_handle.
getGoal().get());
61 mbf_msgs::GetPathResult result;
62 geometry_msgs::PoseStamped start_pose;
67 double tolerance = goal.tolerance;
68 bool use_start_pose = goal.use_start_pose;
71 bool planner_active =
true;
75 start_pose = goal.start_pose;
76 const geometry_msgs::Point& p = start_pose.pose.position;
84 result.outcome = mbf_msgs::GetPathResult::TF_ERROR;
85 result.message =
"Could not get the current robot pose!";
86 goal_handle.
setAborted(result, result.message);
92 const geometry_msgs::Point& p = start_pose.pose.position;
94 << p.x <<
", " << p.y <<
", " << p.z <<
").");
100 std::vector<geometry_msgs::PoseStamped> plan, global_plan;
102 while (planner_active &&
ros::ok())
105 state_planning_input = execution.
getState();
107 switch (state_planning_input)
111 if (!execution.
start(start_pose, goal.target_pose, tolerance))
113 result.outcome = mbf_msgs::GetPathResult::INTERNAL_ERROR;
114 result.message =
"Another thread is still planning!";
115 goal_handle.
setAborted(result, result.message);
117 planner_active =
false;
128 result.outcome = mbf_msgs::GetPathResult::STOPPED;
129 result.message =
"Global planner has been stopped!";
130 goal_handle.
setAborted(result, result.message);
131 planner_active =
false;
138 result.outcome = mbf_msgs::GetPathResult::CANCELED;
139 result.message =
"Global planner has been canceled!";
141 planner_active =
false;
149 <<
"Cancel planning...");
153 "must wait until current plan finish!");
173 result.outcome = mbf_msgs::GetPathResult::TF_ERROR;
174 result.message =
"Could not transform the plan to the global frame!";
177 goal_handle.
setAborted(result, result.message);
178 planner_active =
false;
182 if (global_plan.empty())
184 result.outcome = mbf_msgs::GetPathResult::EMPTY_PATH;
185 result.message =
"Global planner returned an empty path!";
188 goal_handle.
setAborted(result, result.message);
189 planner_active =
false;
193 result.path.poses = global_plan;
194 result.cost = execution.
getCost();
199 planner_active =
false;
207 goal_handle.
setAborted(result, result.message);
208 planner_active =
false;
215 goal_handle.
setAborted(result, result.message);
216 planner_active =
false;
221 result.outcome = mbf_msgs::GetPathResult::PAT_EXCEEDED;
222 result.message =
"Global planner exceeded the patience time";
223 goal_handle.
setAborted(result, result.message);
224 planner_active =
false;
229 planner_active =
false;
230 result.outcome = mbf_msgs::GetPathResult::INTERNAL_ERROR;
231 result.message =
"Internal error: Unknown error thrown by the plugin!";
232 goal_handle.
setAborted(result, result.message);
236 result.outcome = mbf_msgs::GetPathResult::INTERNAL_ERROR;
237 std::ostringstream ss;
238 ss <<
"Internal error: Unknown state in a move base flex planner execution with the number: " 239 <<
static_cast<int>(state_planning_input);
240 result.message = ss.str();
242 goal_handle.
setAborted(result, result.message);
243 planner_active =
false;
253 boost::unique_lock<boost::mutex> lock(mutex);
269 std::vector<geometry_msgs::PoseStamped> &plan, std::vector<geometry_msgs::PoseStamped> &global_plan)
272 std::vector<geometry_msgs::PoseStamped>::iterator iter;
273 bool tf_success =
false;
274 for (iter = plan.begin(); iter != plan.end(); ++iter)
276 geometry_msgs::PoseStamped global_pose;
281 ROS_ERROR_STREAM(
"Can not transform pose from the \"" << iter->header.frame_id <<
"\" frame into the \"" 285 global_plan.push_back(global_pose);
const RobotInformation & robot_info_
PlanningState getState()
Returns the current internal state.
#define ROS_DEBUG_STREAM_NAMED(name, args)
void publish(const boost::shared_ptr< M > &message) const
#define ROS_ERROR_STREAM_NAMED(name, args)
ros::Publisher current_goal_pub_
Publisher to publish the current goal pose, which is used for path planning.
The planner has been stopped.
bool isPatienceExceeded()
Checks whether the patience was exceeded.
unsigned int path_seq_count_
Path sequence counter.
No plan has been found (MAX_RETRIES and PAT_EXCEEDED are 0).
boost::shared_ptr< const Goal > getGoal() const
The planner has been canceled.
#define ROS_INFO_STREAM_NAMED(name, args)
std::string getMessage()
Gets the current plugin execution message.
void setCanceled(const Result &result=Result(), const std::string &text=std::string(""))
Exceeded the maximum number of retries without a valid command.
void waitForStateUpdate(boost::chrono::microseconds const &duration)
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
#define ROS_WARN_STREAM_THROTTLE_NAMED(period, name, args)
const std::string & name_
#define ROS_FATAL_STREAM_NAMED(name, args)
An internal error occurred.
virtual bool cancel()
Cancel the planner execution. This calls the cancel method of the planner plugin. This could be usefu...
Exceeded the patience time without a valid command.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::vector< geometry_msgs::PoseStamped > getPlan()
Returns a new plan, if one is available.
PlanningState
Internal states.
PlannerAction(const std::string &name, const RobotInformation &robot_info)
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
bool transformPlanToGlobalFrame(std::vector< geometry_msgs::PoseStamped > &plan, std::vector< geometry_msgs::PoseStamped > &global_plan)
Transforms a plan to the global frame (global_frame_) coord system.
#define ROS_DEBUG_THROTTLE_NAMED(period, name,...)
#define ROS_ERROR_STREAM(args)
bool start(const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal, double tolerance)
Starts the planner execution thread with the given parameters.
bool transformPose(const TF &tf, const std::string &target_frame, const ros::Time &target_time, const ros::Duration &timeout, const geometry_msgs::PoseStamped &in, const std::string &fixed_frame, geometry_msgs::PoseStamped &out)
uint32_t getOutcome()
Gets the current plugin execution outcome.
void run(GoalHandle &goal_handle, AbstractPlannerExecution &execution)
The AbstractPlannerExecution class loads and binds the global planner plugin. It contains a thread ru...
#define ROS_WARN_STREAM_NAMED(name, args)
double getCost()
Gets computed costs.