41 #include <nav_2d_msgs/Twist2D.h> 42 #include <dwb_msgs/CriticScore.h> 52 traj_gen_loader_(
"dwb_local_planner",
"dwb_local_planner::TrajectoryGenerator"),
53 goal_checker_loader_(
"dwb_local_planner",
"dwb_local_planner::GoalChecker"),
54 critic_loader_(
"dwb_local_planner",
"dwb_local_planner::TrajectoryCritic")
75 std::string traj_generator_name;
78 ROS_INFO_NAMED(
"DWBLocalPlanner",
"Using Trajectory Generator \"%s\"", traj_generator_name.c_str());
82 std::string goal_checker_name;
83 planner_nh_.
param(
"goal_checker_name", goal_checker_name, std::string(
"dwb_plugins::SimpleGoalChecker"));
84 ROS_INFO_NAMED(
"DWBLocalPlanner",
"Using Goal Checker \"%s\"", goal_checker_name.c_str());
93 if (base_name.find(
"Critic") == std::string::npos)
95 base_name = base_name +
"Critic";
98 if (base_name.find(
"::") == std::string::npos)
125 std::vector<std::string> critic_names;
127 for (
unsigned int i = 0; i < critic_names.size(); i++)
129 std::string plugin_name = critic_names[i];
130 std::string plugin_class;
135 ROS_INFO_NAMED(
"DWBLocalPlanner",
"Using critic \"%s\" (%s)", plugin_name.c_str(), plugin_class.c_str());
145 ROS_WARN_NAMED(
"DWBLocalPlanner",
"Cannot check if the goal is reached without the goal being set!");
179 const nav_2d_msgs::Twist2D& velocity)
181 std::shared_ptr<dwb_msgs::LocalPlanEvaluation> results =
nullptr;
184 results = std::make_shared<dwb_msgs::LocalPlanEvaluation>();
220 if (!critic->prepare(local_start_pose, velocity, local_goal_pose, transformed_plan))
222 ROS_WARN_NAMED(
"DWBLocalPlanner",
"Critic \"%s\" failed to prepare", critic->getName().c_str());
228 const nav_2d_msgs::Twist2D& velocity, std::shared_ptr<dwb_msgs::LocalPlanEvaluation>& results)
232 results->header.frame_id = pose.header.frame_id;
243 nav_2d_msgs::Twist2DStamped cmd_vel;
245 cmd_vel.velocity = best.traj.velocity;
250 critic->debrief(cmd_vel.velocity);
260 nav_2d_msgs::Twist2D empty_cmd;
261 dwb_msgs::Trajectory2D empty_traj;
265 critic->debrief(empty_cmd);
275 const nav_2d_msgs::Twist2D velocity,
276 std::shared_ptr<dwb_msgs::LocalPlanEvaluation>& results)
278 nav_2d_msgs::Twist2D twist;
279 dwb_msgs::Trajectory2D traj;
280 dwb_msgs::TrajectoryScore best, worst;
297 results->twists.push_back(score);
299 if (best.total < 0 || score.total < best.total)
304 results->best_index = results->twists.size() - 1;
307 if (worst.total < 0 || score.total > worst.total)
312 results->worst_index = results->twists.size() - 1;
320 dwb_msgs::TrajectoryScore failed_score;
321 failed_score.traj = traj;
323 dwb_msgs::CriticScore cs;
326 failed_score.scores.push_back(cs);
327 failed_score.total = -1.0;
328 results->twists.push_back(failed_score);
341 ROS_ERROR_NAMED(
"DWBLocalPlanner",
"%.2f: %10s/%s",
x.second,
x.first.first.c_str(),
x.first.second.c_str());
353 dwb_msgs::TrajectoryScore score;
358 dwb_msgs::CriticScore cs;
359 cs.name = critic->getName();
360 cs.scale = critic->getScale();
364 score.scores.push_back(cs);
368 double critic_score = critic->scoreTrajectory(traj);
369 cs.raw_score = critic_score;
370 score.scores.push_back(cs);
371 score.total += critic_score * cs.scale;
382 double getSquareDistance(
const geometry_msgs::Pose2D& pose_a,
const geometry_msgs::Pose2D& pose_b)
384 double x_diff = pose_a.x - pose_b.x;
385 double y_diff = pose_a.y - pose_b.y;
386 return x_diff * x_diff + y_diff * y_diff;
391 nav_2d_msgs::Path2D transformed_plan;
398 nav_2d_msgs::Pose2DStamped robot_pose;
404 transformed_plan.header.frame_id =
costmap_->getFrameId();
405 transformed_plan.header.stamp = pose.header.stamp;
409 double sq_dist_threshold = dist_threshold * dist_threshold;
410 nav_2d_msgs::Pose2DStamped stamped_pose;
411 stamped_pose.header.frame_id =
global_plan_.header.frame_id;
413 for (
unsigned int i = 0; i <
global_plan_.poses.size(); i++)
415 bool should_break =
false;
418 if (transformed_plan.poses.size() == 0)
433 if (should_break)
break;
442 nav_2d_msgs::Pose2DStamped costmap_pose;
449 std::vector<geometry_msgs::Pose2D>::iterator it = transformed_plan.poses.begin();
450 std::vector<geometry_msgs::Pose2D>::iterator global_it =
global_plan_.poses.begin();
452 while (it != transformed_plan.poses.end())
454 const geometry_msgs::Pose2D&
w = *it;
458 ROS_DEBUG_NAMED(
"DWBLocalPlanner",
"Nearest waypoint to <%f, %f> is <%f, %f>\n",
459 costmap_pose.pose.x, costmap_pose.pose.y, w.x, w.y);
462 it = transformed_plan.poses.erase(it);
468 if (transformed_plan.poses.size() == 0)
472 return transformed_plan;
void addIllegalTrajectory(const nav_core2::IllegalTrajectoryException &e)
void publishCostGrid(const nav_core2::Costmap::Ptr costmap, const std::vector< TrajectoryCritic::Ptr > critics)
std::map< std::pair< std::string, std::string >, double > getPercentages() const
#define ROS_INFO_THROTTLE_NAMED(period, name,...)
#define ROS_INFO_NAMED(name,...)
GoalChecker::Ptr goal_checker_
pluginlib::ClassLoader< TrajectoryCritic > critic_loader_
bool short_circuit_trajectory_evaluation_
#define ROS_WARN_NAMED(name,...)
std::shared_ptr< dwb_local_planner::TrajectoryCritic > Ptr
void publishGlobalPlan(const nav_2d_msgs::Path2D plan)
void publishTransformedPlan(const nav_2d_msgs::Path2D plan)
std::string getBackwardsCompatibleDefaultGenerator(const ros::NodeHandle &nh)
bool transformPose(const TFListenerPtr tf, const std::string frame, const geometry_msgs::PoseStamped &in_pose, geometry_msgs::PoseStamped &out_pose, const bool extrapolation_fallback=true)
nav_core2::Costmap::Ptr costmap_
TrajectoryGenerator::Ptr traj_generator_
virtual void prepare(const nav_2d_msgs::Pose2DStamped &pose, const nav_2d_msgs::Twist2D &velocity)
Helper method for preparing for the core scoring algorithm.
bool debug_trajectory_details_
double getSquareDistance(const geometry_msgs::Pose2D &pose_a, const geometry_msgs::Pose2D &pose_b)
void publishInputParams(const nav_grid::NavGridInfo &info, const geometry_msgs::Pose2D &start_pose, const nav_2d_msgs::Twist2D &velocity, const geometry_msgs::Pose2D &goal_pose)
void initialize(const ros::NodeHandle &parent, const std::string &name, TFListenerPtr tf, nav_core2::Costmap::Ptr costmap) override
nav_core2 initialization
nav_2d_msgs::Pose2DStamped goal_pose_
Saved Goal Pose.
Plugin-based flexible local_planner.
nav_2d_msgs::Twist2DStamped computeVelocityCommands(const nav_2d_msgs::Pose2DStamped &pose, const nav_2d_msgs::Twist2D &velocity) override
nav_core2 computeVelocityCommands - calculates the best command given the current pose and velocity ...
#define ROS_DEBUG_NAMED(name,...)
pluginlib::ClassLoader< GoalChecker > goal_checker_loader_
bool update_costmap_before_planning_
void loadBackwardsCompatibleParameters(const ros::NodeHandle &nh)
Load parameters to emulate dwa_local_planner.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
pluginlib::ClassLoader< TrajectoryGenerator > traj_gen_loader_
void publishEvaluation(std::shared_ptr< dwb_msgs::LocalPlanEvaluation > results)
If the pointer is not null, publish the evaluation and trajectories as needed.
TFSIMD_FORCE_INLINE const tfScalar & x() const
void setPlan(const nav_2d_msgs::Path2D &path) override
nav_core2 setPlan - Sets the global plan
bool isGoalReached(const nav_2d_msgs::Pose2DStamped &pose, const nav_2d_msgs::Twist2D &velocity) override
nav_core2 isGoalReached - Check whether the robot has reached its goal, given the current pose & velo...
std::string getMessage() const
nav_2d_msgs::Path2D global_plan_
Saved Global Plan.
TFSIMD_FORCE_INLINE const tfScalar & w() const
virtual void loadCritics(const std::string name)
Load the critic parameters from the namespace.
void publishLocalPlan(const std_msgs::Header &header, const dwb_msgs::Trajectory2D &traj)
std::vector< std::string > default_critic_namespaces_
std::string resolveCriticClassName(std::string base_name)
try to resolve a possibly shortened critic name with the default namespaces and the suffix "Critic" ...
bool getParam(const std::string &key, std::string &s) const
virtual nav_2d_msgs::Path2D transformGlobalPlan(const nav_2d_msgs::Pose2DStamped &pose)
Transforms global plan into same frame as pose, clips far away poses and possibly prunes passed poses...
#define ROS_ERROR_NAMED(name,...)
geometry_msgs::Pose2D transformStampedPose(const TFListenerPtr tf, const nav_2d_msgs::Pose2DStamped &pose, const std::string &frame_id)
Thrown when all the trajectories explored are illegal.
std::vector< TrajectoryCritic::Ptr > critics_
std::shared_ptr< Costmap > Ptr
std::string getCriticName() const
bool hasParam(const std::string &key) const
std::shared_ptr< tf::TransformListener > TFListenerPtr
virtual dwb_msgs::TrajectoryScore coreScoringAlgorithm(const geometry_msgs::Pose2D &pose, const nav_2d_msgs::Twist2D velocity, std::shared_ptr< dwb_msgs::LocalPlanEvaluation > &results)
Iterate through all the twists and find the best one.
ros::NodeHandle planner_nh_
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
geometry_msgs::Pose2D transformPoseToLocal(const nav_2d_msgs::Pose2DStamped &pose)
Helper method to transform a given pose to the local costmap frame.
bool shouldRecordEvaluation()
Does the publisher require that the LocalPlanEvaluation be saved.
virtual dwb_msgs::TrajectoryScore scoreTrajectory(const dwb_msgs::Trajectory2D &traj, double best_score=-1)
Score a given command. Can be used for testing.
void setGoalPose(const nav_2d_msgs::Pose2DStamped &goal_pose) override
nav_core2 setGoalPose - Sets the global goal pose
void initialize(ros::NodeHandle &nh)
Load the parameters and advertise topics as needed.
void addLegalTrajectory()
DWBLocalPlanner()
Constructor that brings up pluginlib loaders.