52 return dx * dx + dy * dy;
55 void RotateToGoalCritic::onInit()
58 xy_goal_tolerance_sq_ = xy_goal_tolerance_ * xy_goal_tolerance_;
60 stopped_xy_velocity_sq_ = stopped_xy_velocity * stopped_xy_velocity;
61 critic_nh_.param(
"slowing_factor", slowing_factor_, 5.0);
62 critic_nh_.param(
"lookahead_time", lookahead_time_, -1.0);
66 void RotateToGoalCritic::reset()
72 bool RotateToGoalCritic::prepare(
const geometry_msgs::Pose2D& pose,
const nav_2d_msgs::Twist2D& vel,
73 const geometry_msgs::Pose2D& goal,
74 const nav_2d_msgs::Path2D& global_plan)
76 double dxy_sq =
hypot_sq(pose.x - goal.x, pose.y - goal.y);
77 in_window_ = in_window_ || dxy_sq <= xy_goal_tolerance_sq_;
78 current_xy_speed_sq_ =
hypot_sq(vel.x, vel.y);
79 rotating_ = rotating_ || (in_window_ && current_xy_speed_sq_ <= stopped_xy_velocity_sq_);
80 goal_yaw_ = goal.theta;
84 double RotateToGoalCritic::scoreTrajectory(
const dwb_msgs::Trajectory2D& traj)
93 double speed_sq =
hypot_sq(traj.velocity.x, traj.velocity.y);
94 if (speed_sq >= current_xy_speed_sq_)
98 return speed_sq * slowing_factor_ + scoreRotation(traj);
102 if (fabs(traj.velocity.x) >
EPSILON || fabs(traj.velocity.y) >
EPSILON)
107 return scoreRotation(traj);
110 double RotateToGoalCritic::scoreRotation(
const dwb_msgs::Trajectory2D& traj)
112 if (traj.poses.empty())
118 if (lookahead_time_ >= 0.0)
121 end_yaw = eval_pose.theta;
125 end_yaw = traj.poses.back().theta;
geometry_msgs::Pose2D projectPose(const dwb_msgs::Trajectory2D &trajectory, const double time_offset)
param_t searchAndGetParam(const ros::NodeHandle &nh, const std::string ¶m_name, const param_t &default_value)
double hypot_sq(double dx, double dy)
Forces the commanded trajectories to only be rotations if within a certain distance window...
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
def shortest_angular_distance(from_angle, to_angle)