37 #include <nav_msgs/Path.h> 44 PoseFollower::PoseFollower():
tf_(NULL), costmap_ros_(NULL) {}
67 dsrv_ =
new dynamic_reconfigure::Server<pose_follower::PoseFollowerConfig>(
69 dynamic_reconfigure::Server<pose_follower::PoseFollowerConfig>::CallbackType cb =
71 dsrv_->setCallback(cb);
102 base_odom_.twist.twist.linear.x = msg->twist.twist.linear.x;
103 base_odom_.twist.twist.linear.y = msg->twist.twist.linear.y;
104 base_odom_.twist.twist.angular.z = msg->twist.twist.angular.z;
105 ROS_DEBUG(
"In the odometry callback with velocity values: (%.2f, %.2f, %.2f)",
111 double v1_x = x - pt_x;
112 double v1_y = y - pt_y;
113 double v2_x = cos(heading);
114 double v2_y = sin(heading);
116 double perp_dot = v1_x * v2_y - v1_y * v2_x;
117 double dot = v1_x * v2_x + v1_y * v2_y;
120 double vector_angle = atan2(perp_dot, dot);
122 return -1.0 * vector_angle;
127 nav_msgs::Odometry base_odom;
145 nav_msgs::Path gui_path;
146 gui_path.poses.resize(path.size());
147 gui_path.header.frame_id = path[0].header.frame_id;
148 gui_path.header.stamp = path[0].header.stamp;
151 for (
unsigned int i = 0; i < path.size(); i++) {
152 gui_path.poses[i] = path[i];
162 geometry_msgs::Twist empty_twist;
163 cmd_vel = empty_twist;
171 ROS_DEBUG(
"PoseFollower: current robot pose %f %f ==> %f", robot_pose.getOrigin().x(), robot_pose.getOrigin().y(),
tf::getYaw(robot_pose.getRotation()));
172 ROS_DEBUG(
"PoseFollower: target robot pose %f %f ==> %f", target_pose.getOrigin().x(), target_pose.getOrigin().y(),
tf::getYaw(target_pose.getRotation()));
175 geometry_msgs::Twist diff =
diff2D(target_pose, robot_pose);
176 ROS_DEBUG(
"PoseFollower: diff %f %f ==> %f", diff.linear.x, diff.linear.y, diff.angular.z);
178 geometry_msgs::Twist limit_vel =
limitTwist(diff);
180 geometry_msgs::Twist test_vel = limit_vel;
183 double scaling_factor = 1.0;
184 double ds = scaling_factor /
samples_;
189 test_vel.linear.x = limit_vel.linear.x * scaling_factor;
190 test_vel.linear.y = limit_vel.linear.y * scaling_factor;
191 test_vel.angular.z = limit_vel.angular.z * scaling_factor;
197 scaling_factor -= ds;
202 ROS_ERROR(
"Not legal (%.2f, %.2f, %.2f)", limit_vel.linear.x, limit_vel.linear.y, limit_vel.angular.z);
203 geometry_msgs::Twist empty_twist;
204 cmd_vel = empty_twist;
211 bool in_goal_position =
false;
220 diff =
diff2D(target_pose, robot_pose);
224 ROS_INFO(
"Reached goal: %d", current_waypoint_);
225 in_goal_position =
true;
231 if(!in_goal_position)
236 geometry_msgs::Twist empty_twist;
237 cmd_vel = empty_twist;
247 ROS_ERROR(
"Could not transform the global plan to the frame of the controller");
265 geometry_msgs::Twist res;
288 if(fabs(neg_yaw_diff) < fabs(yaw_diff)){
289 ROS_DEBUG(
"Negative is better: %.2f", neg_yaw_diff);
290 yaw_diff = neg_yaw_diff;
300 diff = pose2.
inverse() * new_pose;
310 geometry_msgs::Twist res = twist;
329 double lin_overshoot = sqrt(res.linear.x * res.linear.x + res.linear.y * res.linear.y) /
max_vel_lin_;
330 double lin_undershoot =
min_vel_lin_ / sqrt(res.linear.x * res.linear.x + res.linear.y * res.linear.y);
331 if (lin_overshoot > 1.0)
333 res.linear.x /= lin_overshoot;
334 res.linear.y /= lin_overshoot;
338 if(lin_undershoot > 1.0)
340 res.linear.x *= lin_undershoot;
341 res.linear.y *= lin_undershoot;
346 if (std::isnan(res.linear.x))
348 if (std::isnan(res.linear.y))
352 if(sqrt(twist.linear.x * twist.linear.x + twist.linear.y * twist.linear.y) <
in_place_trans_vel_){
358 ROS_DEBUG(
"Angular command %f", res.angular.z);
364 std::vector<geometry_msgs::PoseStamped>& transformed_plan){
365 const geometry_msgs::PoseStamped& plan_pose = global_plan[0];
367 transformed_plan.clear();
370 if (global_plan.empty())
372 ROS_ERROR(
"Recieved plan with zero length");
378 plan_pose.header.frame_id, plan_pose.header.stamp,
379 plan_pose.header.frame_id, transform);
382 geometry_msgs::PoseStamped newer_pose;
384 for(
unsigned int i = 0; i < global_plan.size(); ++i){
385 const geometry_msgs::PoseStamped& pose = global_plan[i];
386 poseStampedMsgToTF(pose, tf_pose);
387 tf_pose.
setData(transform * tf_pose);
388 tf_pose.stamp_ = transform.
stamp_;
389 tf_pose.frame_id_ = global_frame;
390 poseStampedTFToMsg(tf_pose, newer_pose);
392 transformed_plan.push_back(newer_pose);
396 ROS_ERROR(
"No Transform available Error: %s\n", ex.what());
400 ROS_ERROR(
"Connectivity Error: %s\n", ex.what());
404 ROS_ERROR(
"Extrapolation Error: %s\n", ex.what());
405 if (!global_plan.empty())
406 ROS_ERROR(
"Global Frame: %s Plan Frame size %d: %s\n", global_frame.c_str(), (
unsigned int)global_plan.size(), global_plan[0].header.frame_id.c_str());
void odomCallback(const nav_msgs::Odometry::ConstPtr &msg)
void initialize(std::string name, tf::TransformListener *tf, costmap_2d::Costmap2DROS *costmap_ros)
ros::Publisher global_plan_pub_
ros::Subscriber odom_sub_
base_local_planner::TrajectoryPlannerROS collision_planner_
unsigned int current_waypoint_
void publish(const boost::shared_ptr< M > &message) const
void setData(const T &input)
bool turn_in_place_first_
bool getRobotPose(tf::Stamped< tf::Pose > &global_pose) const
ros::Time goal_reached_time_
void publishPlan(const std::vector< geometry_msgs::PoseStamped > &path, const ros::Publisher &pub)
double max_heading_diff_before_moving_
static double getYaw(const Quaternion &bt_q)
std::string getGlobalFrameID()
PLUGINLIB_EXPORT_CLASS(BAGReader, nodelet::Nodelet)
double trans_stopped_velocity_
double headingDiff(double pt_x, double pt_y, double x, double y, double heading)
tf::TransformListener * tf_
bool setPlan(const std::vector< geometry_msgs::PoseStamped > &global_plan)
std::vector< geometry_msgs::PoseStamped > global_plan_
TFSIMD_FORCE_INLINE const tfScalar & x() const
double tolerance_timeout_
bool transformGlobalPlan(const tf::TransformListener &tf, const std::vector< geometry_msgs::PoseStamped > &global_plan, const costmap_2d::Costmap2DROS &costmap, const std::string &global_frame, std::vector< geometry_msgs::PoseStamped > &transformed_plan)
static Quaternion createQuaternionFromYaw(double yaw)
void reconfigureCB(pose_follower::PoseFollowerConfig &config, uint32_t level)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
bool computeVelocityCommands(geometry_msgs::Twist &cmd_vel)
TFSIMD_FORCE_INLINE const tfScalar & y() const
double in_place_trans_vel_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
TFSIMD_FORCE_INLINE tfScalar dot(const Quaternion &q1, const Quaternion &q2)
void initialize(std::string name, tf::TransformListener *tf, costmap_2d::Costmap2DROS *costmap_ros)
double rot_stopped_velocity_
bool checkTrajectory(double vx_samp, double vy_samp, double vtheta_samp, bool update_map=true)
dynamic_reconfigure::Server< pose_follower::PoseFollowerConfig > * dsrv_
geometry_msgs::Twist diff2D(const tf::Pose &pose1, const tf::Pose &pose2)
static void poseStampedMsgToTF(const geometry_msgs::PoseStamped &msg, Stamped< Pose > &bt)
geometry_msgs::Twist limitTwist(const geometry_msgs::Twist &twist)
double min_in_place_vel_th_
costmap_2d::Costmap2DROS * costmap_ros_
nav_msgs::Odometry base_odom_