Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <ros/ros.h>
00015 #include <tf/transform_broadcaster.h>
00016 #include <sensor_msgs/LaserScan.h>
00017 #include <nav_msgs/OccupancyGrid.h>
00018
00019 #include <local_map/map_builder.h>
00020 #include <local_map/SaveMap.h>
00021
00022 ros::Publisher map_publisher;
00023 local_map::MapBuilder* map_builder_ptr;
00024
00025 void handleLaserScan(sensor_msgs::LaserScan msg)
00026 {
00027 map_builder_ptr->grow(msg);
00028 map_publisher.publish(map_builder_ptr->getMap());
00029 }
00030
00031 bool save_map(local_map::SaveMap::Request& req,
00032 local_map::SaveMap::Response& res)
00033 {
00034 return map_builder_ptr->saveMap(req.name);
00035 }
00036
00037 int main(int argc, char **argv)
00038 {
00039 ros::init(argc, argv, "local_map");
00040 ros::NodeHandle nh("~");
00041
00042 double map_width;
00043 double map_height;
00044 double map_resolution;
00045 nh.param<double>("map_width", map_width, 200);
00046 nh.param<double>("map_height", map_height, 200);
00047 nh.param<double>("map_resolution", map_resolution, 0.020);
00048 local_map::MapBuilder map_builder(map_width, map_height, map_resolution);
00049 map_builder_ptr = &map_builder;
00050
00051 ros::Subscriber scanHandler = nh.subscribe<sensor_msgs::LaserScan>("scan", 1, handleLaserScan);
00052 map_publisher = nh.advertise<nav_msgs::OccupancyGrid>("local_map", 1, true);
00053 ros::ServiceServer service = nh.advertiseService("save_map", save_map);
00054
00055 ros::spin();
00056 }
00057