00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00042 #ifndef CART_LOCAL_PLANNER_H_
00043 #define CART_LOCAL_PLANNER_H_
00044
00045 #include <cart_local_planner/sbpl_subscriber.h>
00046 #include <ros/ros.h>
00047 #include <tf/tf.h>
00048 #include <tf/transform_datatypes.h>
00049 #include <tf/transform_listener.h>
00050 #include <tf/transform_broadcaster.h>
00051 #include <nav_core/base_local_planner.h>
00052 #include <costmap_2d/costmap_2d_ros.h>
00053 #include <geometry_msgs/PoseStamped.h>
00054 #include <geometry_msgs/PolygonStamped.h>
00055 #include <geometry_msgs/Twist.h>
00056 #include <geometry_msgs/Pose2D.h>
00057 #include <nav_msgs/Odometry.h>
00058 #include <cart_pushing_msgs/RobotCartPath.h>
00059 #include <cart_pushing_msgs/RobotCartConfiguration.h>
00060 #include <boost/scoped_ptr.hpp>
00061 #include <costmap_trajectory_checker/costmap_trajectory_checker.h>
00062 #include <manipulation_transforms/manipulation_transforms.h>
00063
00064 namespace cart_local_planner {
00065
00066 typedef struct {
00067 double x_min;
00068 double x_max;
00069 double y_min;
00070 double y_max;
00071 double t_min;
00072 double t_max;
00073 } pose_range_2D;
00074
00076 const geometry_msgs::Twist operator+(const geometry_msgs::Twist& t1, const geometry_msgs::Twist& t2);
00077 const geometry_msgs::Twist operator-(const geometry_msgs::Twist& t1, const geometry_msgs::Twist& t2);
00078 double mag(geometry_msgs::Twist &t);
00079 double mag(geometry_msgs::Pose2D &p);
00080
00081 class CartLocalPlanner: public nav_core::BaseLocalPlanner {
00082 public:
00083 CartLocalPlanner();
00084 void initialize(std::string name, tf::TransformListener* tf, costmap_2d::Costmap2DROS* costmap_ros);
00085 bool isGoalReached();
00086 bool setPlan(const std::vector<geometry_msgs::PoseStamped>& global_plan);
00087 bool computeVelocityCommands(geometry_msgs::Twist& cmd_vel);
00088
00089 protected:
00094 virtual void initialization_extras();
00095
00096
00097
00098
00103 virtual void setControlMode();
00104
00111 virtual void controlModeAction();
00112
00116 virtual void setGoalPoses();
00117
00122 virtual void filterTwistsCombined(int filter_options);
00123
00128 virtual bool checkTwists();
00129
00134 virtual bool checkTwistsMonotonic();
00135
00136
00137
00138
00145 int setCartGoalFromWaypoint(double min_dist, double min_x_component);
00146
00147
00148 void setCartPoseGoal (const tf::Stamped<tf::Pose>& goal);
00149 void setRobotPoseGoal (const tf::Stamped<tf::Pose>& goal);
00150
00151
00153 double baseTwistFromError();
00154
00156 double cartTwistFromError();
00157
00159 void setYawFromVec(const tf::Pose& pose1, const tf::Pose& pose2,
00160 tf::Pose& res);
00161
00163 bool transformGlobalPlan(const tf::TransformListener& tf,
00164 const std::vector<geometry_msgs::PoseStamped>& global_plan,
00165 const costmap_2d::Costmap2DROS& costmap,
00166 const std::string& global_frame, std::vector<
00167 geometry_msgs::PoseStamped>& transformed_plan);
00168
00170 std::vector<geometry_msgs::Point> transformFootprint(const geometry_msgs::PolygonStamped& poly) const;
00171
00173 void freeze();
00174
00176 static void scaleTwist2D(geometry_msgs::Twist& t, double scale);
00177
00179 geometry_msgs::Twist mapBaseTwistToCart(
00180 const geometry_msgs::Twist &twist_base);
00181
00183 void odomCallback(const nav_msgs::Odometry::ConstPtr& msg);
00184
00186 void invalidPoseCallback (const std_msgs::Empty::ConstPtr& msg);
00187
00188
00189 void publishDebugPose(geometry_msgs::Pose &p);
00190 void publishDebugTwist(geometry_msgs::Twist &t);
00191 void publishDebugPose(tf::Pose &p);
00192
00193
00194
00195
00196 enum FILTER_OPTIONS {
00197 GLOBAL_SCALING = 0x1,
00198 CART_ERR_SCALING = GLOBAL_SCALING << 1,
00199 ALL = 0xffff
00200 };
00201
00202 enum CONTROL_MODE {
00203 REGULAR
00204 };
00205
00206
00207 enum CONTROL_MODE control_mode_;
00208
00209 tf::TransformListener* tf_;
00210 tf::TransformBroadcaster tb_;
00211 ros::NodeHandle nh_;
00212
00213 costmap_2d::Costmap2DROS* costmap_ros_;
00214
00215 CostmapTrajectoryChecker robot_collision_checker_;
00216 CostmapTrajectoryChecker cart_collision_checker_;
00217
00218 ros::Publisher vel_pub_;
00219 ros::Subscriber odom_sub_, invalid_pose_sub_;
00220 nav_msgs::Odometry base_odom_;
00221 ros::Time goal_reached_time_;
00222 std::vector<geometry_msgs::PoseStamped> global_plan_;
00223 boost::mutex odom_lock_, invalid_pose_mutex_;
00224
00225
00226 tf::Stamped<tf::Pose> robot_pose_actual_;
00227 tf::Stamped<tf::Pose> cart_pose_actual_;
00229
00230 tf::Stamped<tf::Pose> robot_pose_goal_;
00231 tf::Stamped<tf::Pose> cart_pose_goal_;
00233
00234 tf::Pose robot_pose_error_;
00235 geometry_msgs::Pose2D cart_pose_error_;
00237
00238 geometry_msgs::Twist *twist_base_;
00239 geometry_msgs::TwistStamped twist_cart_;
00241 bool initialized_;
00242 double K_trans_base_, K_rot_base_;
00243 double K_trans_cart_, K_rot_cart_;
00244 int num_traj_steps_;
00245 double dt_;
00246 unsigned int current_waypoint_;
00247 double tolerance_trans_, tolerance_rot_, tolerance_timeout_;
00248 double trans_stopped_velocity_, rot_stopped_velocity_;
00250
00251 bool subscribe_sbpl_plan_;
00252
00253
00254 ros::Publisher cart_pose_pub_;
00255 ros::Publisher cart_twist_pub_;
00257
00258 pose_range_2D cart_range;
00259
00260 ros::Publisher pose2D_pub_;
00261 geometry_msgs::Twist twist_cart_max_, twist_base_max_;
00262
00263
00264 bool debug_print_;
00265
00266
00267
00268 ros::Time last_invalid_pose_time_;
00269
00270 boost::shared_ptr<cart_local_planner::SBPLSubscriber<cart_pushing_msgs::RobotCartPath> > sbpl_subscriber_;
00271 std::vector<geometry_msgs::PoseStamped> original_global_plan_;
00272
00273 bool getNextFewWaypointsIndices(const std::vector<geometry_msgs::PoseStamped> ¤t_plan,
00274 const int ¤t_waypoint_index,
00275 const int &max_num_waypoints,
00276 const double &max_translation,
00277 const double &max_rotation,
00278 std::vector<unsigned int> &waypoint_indices);
00279
00280 bool checkTrajectoryMonotonic(const std::vector<unsigned int> &indices);
00281
00282
00283
00284 };
00285
00286 }
00287 #endif // guard