local_map_node.cpp
Go to the documentation of this file.
00001 /*
00002  * Local map builder
00003  * The local_map node takes as input a LaserScan message and outputs
00004  * a local map as OccupancyGrid. The local map orientation is the same
00005  * as the one of the global frame. The position of the map is the same
00006  * as the one of the LaserScan.
00007  *
00008  * Parameters:
00009  * - map_width, float, 200, map pixel width (x-direction)
00010  * - map_height, float, 200, map pixel height (y-direction)
00011  * - map_resolution, float, 0.020, map resolution (m/pixel)
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 


local_map
Author(s): Gaƫl Ecorchard
autogenerated on Thu Jun 6 2019 22:02:09