37 #include <nav_msgs/Path.h> 44 PoseFollower::PoseFollower():
tf_(NULL), costmap_ros_(NULL) {}
104 vel_pub_ = node.advertise<geometry_msgs::Twist>(
"cmd_vel", 10);
112 base_odom_.twist.twist.linear.x = msg->twist.twist.linear.x;
113 base_odom_.twist.twist.linear.y = msg->twist.twist.linear.y;
114 base_odom_.twist.twist.angular.z = msg->twist.twist.angular.z;
115 ROS_DEBUG(
"In the odometry callback with velocity values: (%.2f, %.2f, %.2f)",
121 double v1_x = x - pt_x;
122 double v1_y = y - pt_y;
123 double v2_x = cos(heading);
124 double v2_y = sin(heading);
126 double perp_dot = v1_x * v2_y - v1_y * v2_x;
127 double dot = v1_x * v2_x + v1_y * v2_y;
130 double vector_angle = atan2(perp_dot, dot);
132 return -1.0 * vector_angle;
137 nav_msgs::Odometry base_odom;
155 nav_msgs::Path gui_path;
156 gui_path.poses.resize(path.size());
157 gui_path.header.frame_id = path[0].header.frame_id;
158 gui_path.header.stamp = path[0].header.stamp;
161 for (
unsigned int i = 0; i < path.size(); i++) {
162 gui_path.poses[i] = path[i];
172 geometry_msgs::Twist empty_twist;
173 cmd_vel = empty_twist;
181 ROS_DEBUG(
"PoseFollower: current robot pose %f %f ==> %f", robot_pose.getOrigin().x(), robot_pose.getOrigin().y(),
tf::getYaw(robot_pose.getRotation()));
182 ROS_DEBUG(
"PoseFollower: target robot pose %f %f ==> %f", target_pose.getOrigin().x(), target_pose.getOrigin().y(),
tf::getYaw(target_pose.getRotation()));
185 geometry_msgs::Twist diff =
diff2D(target_pose, robot_pose);
186 ROS_DEBUG(
"PoseFollower: diff %f %f ==> %f", diff.linear.x, diff.linear.y, diff.angular.z);
188 geometry_msgs::Twist limit_vel =
limitTwist(diff);
190 geometry_msgs::Twist test_vel = limit_vel;
193 double scaling_factor = 1.0;
194 double ds = scaling_factor /
samples_;
199 test_vel.linear.x = limit_vel.linear.x * scaling_factor;
200 test_vel.linear.y = limit_vel.linear.y * scaling_factor;
201 test_vel.angular.z = limit_vel.angular.z * scaling_factor;
207 scaling_factor -= ds;
212 ROS_ERROR(
"Not legal (%.2f, %.2f, %.2f)", limit_vel.linear.x, limit_vel.linear.y, limit_vel.angular.z);
213 geometry_msgs::Twist empty_twist;
214 cmd_vel = empty_twist;
221 bool in_goal_position =
false;
230 diff =
diff2D(target_pose, robot_pose);
234 ROS_INFO(
"Reached goal: %d", current_waypoint_);
235 in_goal_position =
true;
241 if(!in_goal_position)
246 geometry_msgs::Twist empty_twist;
247 cmd_vel = empty_twist;
257 ROS_ERROR(
"Could not transform the global plan to the frame of the controller");
275 geometry_msgs::Twist res;
298 if(fabs(neg_yaw_diff) < fabs(yaw_diff)){
299 ROS_DEBUG(
"Negative is better: %.2f", neg_yaw_diff);
300 yaw_diff = neg_yaw_diff;
310 diff = pose2.
inverse() * new_pose;
320 geometry_msgs::Twist res = twist;
339 double lin_overshoot = sqrt(res.linear.x * res.linear.x + res.linear.y * res.linear.y) /
max_vel_lin_;
340 double lin_undershoot =
min_vel_lin_ / sqrt(res.linear.x * res.linear.x + res.linear.y * res.linear.y);
341 if (lin_overshoot > 1.0)
343 res.linear.x /= lin_overshoot;
344 res.linear.y /= lin_overshoot;
348 if(lin_undershoot > 1.0)
350 res.linear.x *= lin_undershoot;
351 res.linear.y *= lin_undershoot;
356 if (std::isnan(res.linear.x))
358 if (std::isnan(res.linear.y))
362 if(sqrt(twist.linear.x * twist.linear.x + twist.linear.y * twist.linear.y) <
in_place_trans_vel_){
368 ROS_DEBUG(
"Angular command %f", res.angular.z);
374 std::vector<geometry_msgs::PoseStamped>& transformed_plan){
375 const geometry_msgs::PoseStamped& plan_pose = global_plan[0];
377 transformed_plan.clear();
380 if (global_plan.empty())
382 ROS_ERROR(
"Recieved plan with zero length");
388 plan_pose.header.frame_id, plan_pose.header.stamp,
389 plan_pose.header.frame_id, transform);
392 geometry_msgs::PoseStamped newer_pose;
394 for(
unsigned int i = 0; i < global_plan.size(); ++i){
395 const geometry_msgs::PoseStamped& pose = global_plan[i];
396 poseStampedMsgToTF(pose, tf_pose);
397 tf_pose.
setData(transform * tf_pose);
398 tf_pose.stamp_ = transform.
stamp_;
399 tf_pose.frame_id_ = global_frame;
400 poseStampedTFToMsg(tf_pose, newer_pose);
402 transformed_plan.push_back(newer_pose);
406 ROS_ERROR(
"No Transform available Error: %s\n", ex.what());
410 ROS_ERROR(
"Connectivity Error: %s\n", ex.what());
414 ROS_ERROR(
"Extrapolation Error: %s\n", ex.what());
415 if (!global_plan.empty())
416 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)
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)
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_