Go to the documentation of this file.00001 #include <nj_laser/jockey.h>
00002
00003 namespace nj_laser
00004 {
00005
00006 Jockey::Jockey(const std::string& name, const double frontier_width) :
00007 lama_jockeys::NavigatingJockey(name),
00008 has_crossing_(false),
00009 crossing_detector_(frontier_width),
00010 obstacle_avoider_(frontier_width / 2)
00011 {
00012 private_nh_.getParam("range_cutoff", range_cutoff_);
00013 double robot_radius;
00014 if (private_nh_.getParam("robot_radius", robot_radius))
00015 {
00016 obstacle_avoider_.robot_radius = robot_radius;
00017 }
00018
00019 pub_twist_ = private_nh_.advertise<geometry_msgs::Twist>("cmd_vel", 1);
00020 pub_crossing_marker_ = private_nh_.advertise<visualization_msgs::Marker>("crossing_marker", 50, true);
00021 pub_exits_marker_ = private_nh_.advertise<visualization_msgs::Marker> ("exits_marker", 50, true);
00022 pub_place_profile_ = private_nh_.advertise<sensor_msgs::PointCloud>("place_profile_cloud", 50, true);
00023 pub_crossing_ = private_nh_.advertise<lama_msgs::Crossing>("crossing", 50, true);
00024 }
00025
00026 void Jockey::onTraverse()
00027 {
00028 ROS_DEBUG("Received action TRAVERSE or CONTINUE");
00029 crossing_goer_.resetIntegrals();
00030
00031 laserHandler_ = private_nh_.subscribe<sensor_msgs::LaserScan>("base_scan", 1, &Jockey::handleLaser, this);
00032
00033 ros::Rate r(100);
00034 while (ros::ok())
00035 {
00036 if (server_.isPreemptRequested() && !ros::ok())
00037 {
00038 ROS_INFO("%s: Preempted", jockey_name_.c_str());
00039
00040 server_.setPreempted();
00041 break;
00042 }
00043
00044 if (has_crossing_)
00045 {
00046 geometry_msgs::Twist twist;
00047 if (crossing_.frontiers.size() < 3)
00048 {
00049 twist = obstacle_avoider_.getTwist(scan_);
00050 pub_twist_.publish(twist);
00051 }
00052 else
00053 {
00054 const bool goal_reached = crossing_goer_.goto_crossing(crossing_, twist);
00055 pub_twist_.publish(twist);
00056
00057 if (goal_reached)
00058 {
00059 laserHandler_.shutdown();
00060 result_.final_state = result_.DONE;
00061 result_.completion_time = getCompletionDuration();
00062 server_.setSucceeded(result_);
00063 break;
00064 }
00065 }
00066 ROS_DEBUG("Twist (%.3f, %.3f)", twist.linear.x, twist.angular.z);
00067 has_crossing_ = false;
00068 }
00069 ros::spinOnce();
00070 r.sleep();
00071 }
00072 ROS_DEBUG("Exiting onTraverse");
00073 }
00074
00075 void Jockey::onStop()
00076 {
00077 ROS_DEBUG("Received action STOP or INTERRUPT");
00078 laserHandler_.shutdown();
00079 result_.final_state = lama_jockeys::NavigateResult::DONE;
00080 result_.completion_time = ros::Duration(0.0);
00081 server_.setSucceeded(result_);
00082 }
00083
00084 void Jockey::onInterrupt()
00085 {
00086 ROS_DEBUG("Received action INTERRUPT");
00087 onStop();
00088 }
00089
00090 void Jockey::onContinue()
00091 {
00092 ROS_DEBUG("Received action CONTINUE");
00093 onTraverse();
00094 }
00095
00096 void Jockey::handleLaser(const sensor_msgs::LaserScanConstPtr& msg)
00097 {
00098 ROS_DEBUG("Laser arrived with %zu beams", msg->ranges.size());
00099
00100 scan_ = *msg;
00101 crossing_detector_.setMaxFrontierDistance(range_cutoff_);
00102 crossing_ = crossing_detector_.crossingDescriptor(scan_);
00103 ROS_DEBUG("Crossing (%.3f, %.3f, %.3f), number of exits: %zu",
00104 crossing_.center.x, crossing_.center.y, crossing_.radius, crossing_.frontiers.size());
00105
00106 has_crossing_ = true;
00107
00108
00109 if (pub_crossing_marker_.getNumSubscribers())
00110 {
00111 visualization_msgs::Marker m = lama_common::getCrossingCenterMarker(msg->header.frame_id, crossing_);
00112 pub_crossing_marker_.publish(m);
00113 }
00114
00115
00116 if (pub_exits_marker_.getNumSubscribers())
00117 {
00118 visualization_msgs::Marker m = lama_common::getFrontiersMarker(msg->header.frame_id, crossing_);
00119 pub_exits_marker_.publish(m);
00120 }
00121
00122
00123 if (pub_place_profile_.getNumSubscribers())
00124 {
00125 sensor_msgs::PointCloud cloud = lama_common::placeProfileToPointCloud(crossing_detector_.getPlaceProfile());
00126 pub_place_profile_.publish(cloud);
00127 }
00128
00129 pub_crossing_.publish(crossing_);
00130 }
00131
00132 }
00133