00001 /* 00002 * slam_gmapping 00003 * Copyright (c) 2008, Willow Garage, Inc. 00004 * 00005 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE 00006 * COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY 00007 * COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS 00008 * AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. 00009 * 00010 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO 00011 * BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS 00012 * CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND 00013 * CONDITIONS. 00014 * 00015 */ 00016 00017 /* Author: Brian Gerkey */ 00018 00019 #include "ros/ros.h" 00020 #include "sensor_msgs/LaserScan.h" 00021 #include "std_msgs/Float64.h" 00022 #include "nav_msgs/GetMap.h" 00023 #include "tf/transform_listener.h" 00024 #include "tf/transform_broadcaster.h" 00025 #include "message_filters/subscriber.h" 00026 #include "tf/message_filter.h" 00027 00028 #include "gmapping/gridfastslam/gridslamprocessor.h" 00029 #include "gmapping/sensor/sensor_base/sensor.h" 00030 00031 #include <boost/thread.hpp> 00032 00033 class SlamGMapping 00034 { 00035 public: 00036 SlamGMapping(); 00037 SlamGMapping(unsigned long int seed, unsigned long int max_duration_buffer); 00038 ~SlamGMapping(); 00039 00040 void init(); 00041 void startLiveSlam(); 00042 void startReplay(const std::string & bag_fname, std::string scan_topic); 00043 void publishTransform(); 00044 00045 void laserCallback(const sensor_msgs::LaserScan::ConstPtr& scan); 00046 bool mapCallback(nav_msgs::GetMap::Request &req, 00047 nav_msgs::GetMap::Response &res); 00048 void publishLoop(double transform_publish_period); 00049 00050 private: 00051 ros::NodeHandle node_; 00052 ros::Publisher entropy_publisher_; 00053 ros::Publisher sst_; 00054 ros::Publisher sstm_; 00055 ros::ServiceServer ss_; 00056 tf::TransformListener tf_; 00057 message_filters::Subscriber<sensor_msgs::LaserScan>* scan_filter_sub_; 00058 tf::MessageFilter<sensor_msgs::LaserScan>* scan_filter_; 00059 tf::TransformBroadcaster* tfB_; 00060 00061 GMapping::GridSlamProcessor* gsp_; 00062 GMapping::RangeSensor* gsp_laser_; 00063 // The angles in the laser, going from -x to x (adjustment is made to get the laser between 00064 // symmetrical bounds as that's what gmapping expects) 00065 std::vector<double> laser_angles_; 00066 // The pose, in the original laser frame, of the corresponding centered laser with z facing up 00067 tf::Stamped<tf::Pose> centered_laser_pose_; 00068 // Depending on the order of the elements in the scan and the orientation of the scan frame, 00069 // We might need to change the order of the scan 00070 bool do_reverse_range_; 00071 unsigned int gsp_laser_beam_count_; 00072 GMapping::OdometrySensor* gsp_odom_; 00073 00074 bool got_first_scan_; 00075 00076 bool got_map_; 00077 nav_msgs::GetMap::Response map_; 00078 00079 ros::Duration map_update_interval_; 00080 tf::Transform map_to_odom_; 00081 boost::mutex map_to_odom_mutex_; 00082 boost::mutex map_mutex_; 00083 00084 int laser_count_; 00085 int throttle_scans_; 00086 00087 boost::thread* transform_thread_; 00088 00089 std::string base_frame_; 00090 std::string laser_frame_; 00091 std::string map_frame_; 00092 std::string odom_frame_; 00093 00094 void updateMap(const sensor_msgs::LaserScan& scan); 00095 bool getOdomPose(GMapping::OrientedPoint& gmap_pose, const ros::Time& t); 00096 bool initMapper(const sensor_msgs::LaserScan& scan); 00097 bool addScan(const sensor_msgs::LaserScan& scan, GMapping::OrientedPoint& gmap_pose); 00098 double computePoseEntropy(); 00099 00100 // Parameters used by GMapping 00101 double maxRange_; 00102 double maxUrange_; 00103 double maxrange_; 00104 double minimum_score_; 00105 double sigma_; 00106 int kernelSize_; 00107 double lstep_; 00108 double astep_; 00109 int iterations_; 00110 double lsigma_; 00111 double ogain_; 00112 int lskip_; 00113 double srr_; 00114 double srt_; 00115 double str_; 00116 double stt_; 00117 double linearUpdate_; 00118 double angularUpdate_; 00119 double temporalUpdate_; 00120 double resampleThreshold_; 00121 int particles_; 00122 double xmin_; 00123 double ymin_; 00124 double xmax_; 00125 double ymax_; 00126 double delta_; 00127 double occ_thresh_; 00128 double llsamplerange_; 00129 double llsamplestep_; 00130 double lasamplerange_; 00131 double lasamplestep_; 00132 00133 ros::NodeHandle private_nh_; 00134 00135 unsigned long int seed_; 00136 00137 double transform_publish_period_; 00138 double tf_delay_; 00139 };