00001 #ifndef MULTI_MAPPER_H 00002 #define MULTI_MAPPER_H 00003 00004 #include <ros/ros.h> 00005 #include <tf/transform_listener.h> 00006 #include <tf/transform_broadcaster.h> 00007 #include <nav_msgs/OccupancyGrid.h> 00008 #include <nav_msgs/GetMap.h> 00009 #include <geometry_msgs/PoseArray.h> 00010 #include <geometry_msgs/PoseWithCovarianceStamped.h> 00011 #include <nav2d_msgs/LocalizedScan.h> 00012 #include <nav2d_localizer/SelfLocalizer.h> 00013 00014 #include <OpenKarto/OpenKarto.h> 00015 00016 #include <string> 00017 #include <map> 00018 00019 #define ST_WAITING_FOR_MAP 10 00020 #define ST_LOCALIZING 20 00021 #define ST_MAPPING 30 00022 00023 class MultiMapper 00024 { 00025 public: 00026 // Constructor & Destructor 00027 MultiMapper(); 00028 ~MultiMapper(); 00029 00030 // Public methods 00031 void receiveLaserScan(const sensor_msgs::LaserScan::ConstPtr& scan); 00032 void receiveLocalizedScan(const nav2d_msgs::LocalizedScan::ConstPtr& scan); 00033 void receiveInitialPose(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& pose); 00034 void sendLocalizedScan(const sensor_msgs::LaserScan::ConstPtr& scan, const karto::Pose2& pose); 00035 void onMessage(const void* sender, karto::MapperEventArguments& args); 00036 bool getMap(nav_msgs::GetMap::Request &req, nav_msgs::GetMap::Response &res); 00037 void publishLoop(); 00038 void publishTransform(); 00039 void setScanSolver(karto::ScanSolver* scanSolver); 00040 00041 private: 00042 // Private methods 00043 bool updateMap(); 00044 bool sendMap(); 00045 void setRobotPose(double x, double y, double yaw); 00046 karto::LocalizedRangeScan* createFromRosMessage(const sensor_msgs::LaserScan& scan, const karto::Identifier& robot); 00047 00048 // Particle filter to localize within received map 00049 SelfLocalizer* mSelfLocalizer; 00050 00051 // Everything related to ROS 00052 tf::TransformListener mTransformListener; 00053 tf::TransformBroadcaster mTransformBroadcaster; 00054 tf::Transform mMapToOdometry; 00055 tf::Transform mOdometryOffset; 00056 00057 nav_msgs::OccupancyGrid mGridMap; 00058 00059 ros::ServiceServer mMapServer; 00060 ros::Publisher mMapPublisher; 00061 ros::Publisher mScanPublisher; 00062 ros::Publisher mVerticesPublisher; 00063 ros::Publisher mEdgesPublisher; 00064 ros::Publisher mPosePublisher; 00065 ros::Publisher mOtherRobotsPublisher; 00066 ros::Subscriber mLaserSubscriber; 00067 ros::Subscriber mScanSubscriber; 00068 ros::Subscriber mInitialPoseSubscriber; 00069 00070 // Everything related to KARTO 00071 karto::LaserRangeFinderPtr mLaser; 00072 karto::SmartPointer<karto::OpenMapper> mMapper; 00073 std::map<int, karto::LaserRangeFinderPtr> mOtherLasers; 00074 bool mMapChanged; 00075 00076 // Parameters and Variables 00077 int mRobotID; // Who am I? 00078 double mMapResolution; // Resolution of published grid map. 00079 double mRangeThreshold; // Maximum range of laser sensor. (All robots MUST use the same due to Karto-Mapper!) 00080 double mMaxCovariance; // When to accept the result of the particle filter? 00081 int mState; // What am I doing? (waiting, localizing, mapping) 00082 int mMapUpdateRate; // Publish the map every # received updates. 00083 bool mPublishPoseGraph; // Whether or not to publish the pose graph as marker-message. 00084 int mNodesAdded; // Number of nodes added to the pose graph. 00085 int mMinMapSize; // Minimum map size (# of nodes) needed for localization. 00086 ros::WallTime mLastMapUpdate; 00087 00088 // Frames and Topics 00089 std::string mLaserFrame; 00090 std::string mRobotFrame; 00091 std::string mOdometryFrame; 00092 std::string mOffsetFrame; 00093 std::string mMapFrame; 00094 std::string mLaserTopic; 00095 std::string mMapTopic; 00096 std::string mMapService; 00097 std::string mScanInputTopic; 00098 std::string mScanOutputTopic; 00099 }; 00100 00101 #endif