40 #include <nav_msgs/Path.h> 41 #include <sbpl_lattice_planner/SBPLLatticePlannerStats.h> 55 return p1.
x == p2.
x && p1.
y == p2.
y && p1.
z == p2.
z;
63 LatticeSCQ(EnvironmentNAVXYTHETALAT* env, std::vector<nav2dcell_t>
const & changedcellsV)
64 : env_(env), changedcellsV_(changedcellsV) {
69 if(predsOfChangedCells_.empty() && !changedcellsV_.empty())
70 env_->GetPredsofChangedEdges(&changedcellsV_, &predsOfChangedCells_);
71 return &predsOfChangedCells_;
76 if(succsOfChangedCells_.empty() && !changedcellsV_.empty())
77 env_->GetSuccsofChangedEdges(&changedcellsV_, &succsOfChangedCells_);
78 return &succsOfChangedCells_;
81 EnvironmentNAVXYTHETALAT *
env_;
87 SBPLLatticePlanner::SBPLLatticePlanner()
88 : initialized_(false), costmap_ros_(NULL){
101 ROS_INFO(
"Name is %s", name.c_str());
111 double nominalvel_mpersecs, timetoturn45degsinplace_secs;
112 private_nh.
param(
"nominalvel_mpersecs", nominalvel_mpersecs, 0.4);
113 private_nh.
param(
"timetoturn45degsinplace_secs", timetoturn45degsinplace_secs, 0.6);
116 private_nh.
param(
"lethal_obstacle",lethal_obstacle,20);
128 ROS_DEBUG(
"Using a 3D costmap for theta lattice\n");
129 env_ =
new EnvironmentNAVXYTHETALAT();
132 ROS_ERROR(
"XYThetaLattice is currently the only supported environment!\n");
146 ROS_WARN(
"SBPL performance will suffer.");
147 ROS_WARN(
"Please decrease the costmap's cost_scaling_factor.");
150 ROS_ERROR(
"Failed to set cost_inscribed_thresh parameter");
154 ROS_ERROR(
"Failed to set cost_possibly_circumscribed_thresh parameter");
158 vector<sbpl_2Dpt_t> perimeterptsV;
160 for (
size_t ii(0); ii <
footprint_.size(); ++ii) {
164 perimeterptsV.push_back(pt);
176 timetoturn45degsinplace_secs, obst_cost_thresh,
181 catch(SBPL_Exception *e){
182 ROS_ERROR(
"SBPL encountered a fatal exception: %s", e->what());
186 ROS_ERROR(
"SBPL initialization failed!");
202 ROS_ERROR(
"ARAPlanner and ADPlanner are currently the only supported planners!\n");
206 ROS_INFO(
"[sbpl_lattice_planner] Initialized successfully");
232 const geometry_msgs::PoseStamped& start,
233 const geometry_msgs::PoseStamped& goal){
235 sbpl_lattice_planner::SBPLLatticePlannerStats stats;
237 stats.plan_to_first_solution =
false;
238 stats.final_number_of_expands =
planner_->get_n_expands();
241 stats.time_to_first_solution =
planner_->get_initial_eps_planning_time();
242 stats.actual_time =
planner_->get_final_eps_planning_time();
243 stats.number_of_expands_initial_solution =
planner_->get_n_expands_init_solution();
244 stats.final_epsilon =
planner_->get_final_epsilon();
246 stats.solution_cost = solution_cost;
247 stats.path_size = solution_size;
254 unsigned char result = 0;
266 if (!inflation_layer)
continue;
274 const geometry_msgs::PoseStamped& goal,
275 std::vector<geometry_msgs::PoseStamped>& plan){
277 ROS_ERROR(
"Global planner is not initialized");
281 bool do_init =
false;
284 ROS_INFO(
"Costmap dimensions have changed from (%d x %d) to (%d x %d), reinitializing sbpl_lattice_planner.",
290 ROS_INFO(
"Robot footprint has changed, reinitializing sbpl_lattice_planner.");
294 ROS_INFO(
"Cost at circumscribed radius has changed, reinitializing sbpl_lattice_planner.");
309 ROS_INFO(
"[sbpl_lattice_planner] getting start point (%g,%g) goal point (%g,%g)",
310 start.pose.position.x, start.pose.position.y,goal.pose.position.x, goal.pose.position.y);
311 double theta_start = 2 * atan2(start.pose.orientation.z, start.pose.orientation.w);
312 double theta_goal = 2 * atan2(goal.pose.orientation.z, goal.pose.orientation.w);
316 if(ret < 0 || planner_->set_start(ret) == 0){
317 ROS_ERROR(
"ERROR: failed to set start state\n");
321 catch(SBPL_Exception *e){
322 ROS_ERROR(
"SBPL encountered a fatal exception while setting the start state");
328 if(ret < 0 || planner_->set_goal(ret) == 0){
329 ROS_ERROR(
"ERROR: failed to set goal state\n");
333 catch(SBPL_Exception *e){
334 ROS_ERROR(
"SBPL encountered a fatal exception while setting the goal state");
341 vector<nav2dcell_t> changedcellsV;
346 unsigned char oldCost =
env_->GetMapCost(ix,iy);
349 if(oldCost == newCost)
continue;
366 nav2dcell_t nav2dcell;
369 changedcellsV.push_back(nav2dcell);
374 if(!changedcellsV.empty()){
381 planner_->force_planning_from_scratch();
383 catch(SBPL_Exception *e){
384 ROS_ERROR(
"SBPL failed to update the costmap");
393 ROS_DEBUG(
"[sbpl_lattice_planner] run planner");
394 vector<int> solution_stateIDs;
406 catch(SBPL_Exception *e){
407 ROS_ERROR(
"SBPL encountered a fatal exception while planning");
411 ROS_DEBUG(
"size of solution=%d", (
int)solution_stateIDs.size());
413 vector<EnvNAVXYTHETALAT3Dpt_t> sbpl_path;
415 env_->ConvertStateIDPathintoXYThetaPath(&solution_stateIDs, &sbpl_path);
417 catch(SBPL_Exception *e){
418 ROS_ERROR(
"SBPL encountered a fatal exception while reconstructing the path");
422 if( sbpl_path.size() == 0 ) {
423 EnvNAVXYTHETALAT3Dpt_t
s(
427 sbpl_path.push_back(
s);
430 ROS_DEBUG(
"Plan has %d points.\n", (
int)sbpl_path.size());
434 nav_msgs::Path gui_path;
435 gui_path.poses.resize(sbpl_path.size());
437 gui_path.header.stamp = plan_time;
438 for(
unsigned int i=0; i<sbpl_path.size(); i++){
439 geometry_msgs::PoseStamped pose;
440 pose.header.stamp = plan_time;
445 pose.pose.position.z = start.pose.position.z;
448 temp.
setRPY(0,0,sbpl_path[i].theta);
449 pose.pose.orientation.x = temp.getX();
450 pose.pose.orientation.y = temp.getY();
451 pose.pose.orientation.z = temp.getZ();
452 pose.pose.orientation.w = temp.
getW();
454 plan.push_back(pose);
456 gui_path.poses[i] = plan[i];
459 publishStats(solution_cost, sbpl_path.size(), start, goal);
LatticeSCQ(EnvironmentNAVXYTHETALAT *env, std::vector< nav2dcell_t > const &changedcellsV)
virtual void initialize(std::string name, costmap_2d::Costmap2DROS *costmap_ros)
Initialization function for the SBPLLatticePlanner object.
void setRPY(const tf2Scalar &roll, const tf2Scalar &pitch, const tf2Scalar &yaw)
EnvironmentNAVXYTHETALAT * env_
void publish(const boost::shared_ptr< M > &message) const
unsigned int current_env_width_
unsigned char computeCircumscribedCost()
virtual std::vector< int > const * getPredecessors() const
unsigned char circumscribed_cost_
ros::Publisher stats_publisher_
std::string primitive_filename_
TF2SIMD_FORCE_INLINE const tf2Scalar & getW() const
void publishStats(int solution_cost, int solution_size, const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal)
std::string getGlobalFrameID()
PLUGINLIB_EXPORT_CLASS(BAGReader, nodelet::Nodelet)
unsigned int current_env_height_
double getOriginX() const
std::string environment_type_
std::string planner_type_
std::vector< int > succsOfChangedCells_
std::vector< boost::shared_ptr< Layer > > * getPlugins()
bool operator==(const Point &p1, const Point &p2)
std::vector< nav2dcell_t > const & changedcellsV_
EnvironmentNAVXYTHETALAT * env_
TFSIMD_FORCE_INLINE const tfScalar & x() const
unsigned char lethal_obstacle_
virtual std::vector< int > const * getSuccessors() const
unsigned char getCost(unsigned int mx, unsigned int my) const
static const unsigned char INSCRIBED_INFLATED_OBSTACLE
TFSIMD_FORCE_INLINE const tfScalar & z() const
unsigned char inscribed_inflated_obstacle_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
std::vector< int > predsOfChangedCells_
TFSIMD_FORCE_INLINE const tfScalar & y() const
double getOriginY() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
virtual bool makePlan(const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal, std::vector< geometry_msgs::PoseStamped > &plan)
Given a goal pose in the world, compute a plan.
unsigned int getSizeInCellsY() const
unsigned char costMapCostToSBPLCost(unsigned char newcost)
unsigned int getSizeInCellsX() const
static const unsigned char LETHAL_OBSTACLE
static const unsigned char NO_INFORMATION
costmap_2d::Costmap2DROS * costmap_ros_
double getResolution() const
std::vector< geometry_msgs::Point > getRobotFootprint()
double getCircumscribedRadius()
std::vector< geometry_msgs::Point > footprint_
SBPLLatticePlanner()
Default constructor for the NavFnROS object.
unsigned char sbpl_cost_multiplier_
LayeredCostmap * getLayeredCostmap()