00001 /* 00002 * Navigating jockey used to go away from a crossing center. 00003 * 00004 * This jockey takes an edge descriptor (with exit angles) to know in which 00005 * direction to go. 00006 * This jockey takes a crossing descriptor to know how far it should travel. 00007 * But this distance can also be given as parameter. If the parameter is 00008 * non-existent or its value is 0, the robot will travel a distance equal to 00009 * the crossing radius. 00010 * It supports the TRAVERSE action and is DONE when the distance is traveled. 00011 * As for now, the jockey is pretty stupid and does not stop before the 00012 * distance is traveled (it does not FAIL). 00013 * 00014 * Interaction with the map (created by this jockey): 00015 * - none 00016 * 00017 * Interaction with the map (created by other jockeys): 00018 * - Getter: lama_msgs/Crossing, "crossing" 00019 * - Getter: float64, "exit_angle" 00020 * 00021 * Subscribers (other than map-related): 00022 * - nav_msgs/Odometry, "~odometry", robot position 00023 * - std_msgs/Float32, "~direction", direction in which to escape. 00024 * The direction must be in the same reference frame as ~odometry. 00025 * This topic is used only if the requested edge does not exist or if it 00026 * has no exit angle descriptor. 00027 * 00028 * Publishers (other than map-related): 00029 * - geometry_msgs/Twist, "~cmd_vel", set velocity 00030 * 00031 * Services used (other than map-related): 00032 * - none 00033 * 00034 * Parameters: 00035 * - ~/kp_v, Float, 0.05, proportional gain for the linear velocity (s^-1). 00036 * - ~/kp_w, Float, 0.2, proportional gain for the angular velocity (s^-1). 00037 * - ~/min_linear_velocity, Float, 0.020, minimum set linear velocity (m.s^-1) 00038 * - ~/min_angular_velocity, Float, 0.1, minimum set angular velocity (rad.s^-1). 00039 * - ~/escape_distance, Float, 0.0, distance to travel from crossing center 00040 * (m). If set to 0, the radius value in the crossing descriptor will be used. 00041 * - ~/distance_reached, Float, 0.1, distance when considering reached target 00042 * when going to the start vertex (m). 00043 * - ~/max_angle_turn_only, Float, 1,0, if dtheta is greater than this, only turn, do 00044 * not go forward (rad). 00045 * - ~/crossing_interface_name, String, "crossing", name of the map interface for Crossing 00046 * - ~/exit_angle_interface_name, String "exit_angle", name of the map interface for exit angle 00047 * - ~/exit_angle_topic_name, String, "exit_angle", name of the optional topic 00048 * for exit angle (or direction). 00049 */ 00050 00051 #ifndef NJ_ESCAPE_CROSSING_CROSSING_ESCAPER_H 00052 #define NJ_ESCAPE_CROSSING_CROSSING_ESCAPER_H 00053 00054 #include <cmath> 00055 #include <string> 00056 00057 #include <angles/angles.h> // for shortest_angular_distance(). 00058 #include <geometry_msgs/Point.h> 00059 #include <geometry_msgs/Twist.h> 00060 #include <nav_msgs/Odometry.h> 00061 #include <ros/ros.h> 00062 #include <std_msgs/Float32.h> 00063 #include <tf/transform_datatypes.h> // for getYaw() 00064 00065 #include <lama_interfaces/GetDouble.h> 00066 #include <lama_jockeys/navigating_jockey.h> 00067 #include <lama_msgs/Crossing.h> 00068 #include <lama_msgs/GetCrossing.h> 00069 00070 namespace nj_escape_crossing { 00071 00072 class CrossingEscaper : public lama_jockeys::NavigatingJockey 00073 { 00074 public: 00075 00076 CrossingEscaper(std::string name, double escape_distance = 0); 00077 00078 protected: 00079 00080 virtual void onTraverse(); 00081 virtual void onStop(); 00082 00083 void direction_callback(const std_msgs::Float32& direction); 00084 void odometry_callback(const nav_msgs::Odometry& odometry); 00085 00086 private: 00087 00088 bool getDistanceToEscape(); 00089 bool getCrossing(); 00090 bool retrieveCrossingFromMap(int32_t descriptor_id); 00091 void getExitDirection(); 00092 bool getExitAngleFromMap(); 00093 bool turnToAngle(double direction, geometry_msgs::Twist& twist); 00094 bool goToGoal(const geometry_msgs::Point& goal, geometry_msgs::Twist& twist); 00095 geometry_msgs::Point goalFromOdometry(double dx, double dy); 00096 00097 // Subscribers and publishers. 00098 ros::Subscriber odometry_subscriber_; 00099 ros::Publisher twist_publisher_; 00100 ros::ServiceClient crossing_getter_; 00101 ros::ServiceClient exit_angle_getter_; 00102 00103 // Parameters shown outside. 00104 double kp_v_; 00105 double kp_w_; 00106 double min_linear_velocity_; 00107 double max_linear_velocity_; 00108 00109 double min_angular_velocity_; 00110 double max_angular_velocity_; 00111 00112 double escape_distance_; 00113 double distance_reached_; 00114 00115 double max_angle_turn_only_; 00116 double max_odometry_age_; 00117 std::string exit_angle_topic_name_; 00118 00119 // Internals. 00120 bool start_reached_; 00121 bool angle_reached_; 00122 bool goal_reached_; 00123 bool has_odometry_; 00124 lama_msgs::Crossing crossing_; 00125 nav_msgs::Odometry odometry_; 00126 double direction_; 00127 bool has_direction_; 00128 nav_msgs::Odometry start_position_; 00129 double distance_to_escape_; 00130 std::string crossing_interface_name_; 00131 std::string exit_angle_interface_name_; 00132 double last_dtheta_; 00133 }; 00134 00135 } // namespace nj_escape_crossing 00136 00137 #endif // NJ_ESCAPE_CROSSING_CROSSING_ESCAPER_H