Go to the documentation of this file.00001 #ifndef _LOCAL_MAP_MAP_BUILDER_H_
00002 #define _LOCAL_MAP_MAP_BUILDER_H_
00003
00004 #include <cmath>
00005 #include <exception>
00006 #include <string>
00007 #include <vector>
00008
00009 #include <ros/ros.h>
00010 #include <tf/tf.h>
00011 #include <tf/transform_listener.h>
00012 #include <tf/transform_broadcaster.h>
00013 #include <angles/angles.h>
00014 #include <sensor_msgs/LaserScan.h>
00015 #include <nav_msgs/OccupancyGrid.h>
00016
00017 #include <map_ray_caster/map_ray_caster.h>
00018
00019 namespace local_map
00020 {
00021
00022 using std::vector;
00023 using std::abs;
00024 using std::max;
00025
00026 class MapBuilder
00027 {
00028 public:
00029
00030 MapBuilder(int width, int height, double resolution);
00031
00032 bool saveMap(const std::string& name) const;
00033
00034 void grow(const sensor_msgs::LaserScan& scan);
00035
00036 nav_msgs::OccupancyGrid getMap() const {return map_;}
00037
00038 private:
00039
00040 bool updateMap(const sensor_msgs::LaserScan& scan, long int dx, long int dy, double theta);
00041 bool getRayCastToObstacle(const nav_msgs::OccupancyGrid& map, double angle, double range, vector<size_t>& raycast);
00042 void updatePointOccupancy(bool occupied, size_t idx, vector<int8_t>& occupancy, vector<double>& log_odds) const;
00043
00046 inline void updatePointsOccupancy(bool occupied, const vector<size_t>& indexes, vector<int8_t>& occupancy, vector<double>& log_odds)
00047 {
00048 vector<size_t>::const_iterator idx = indexes.begin();
00049 for (; idx != indexes.end(); ++idx)
00050 {
00051 updatePointOccupancy(occupied, *idx, occupancy, log_odds);
00052 }
00053 }
00054
00055
00056 double angle_resolution_;
00057
00058 double p_occupied_when_laser_;
00059
00060
00061 double p_occupied_when_no_laser_ ;
00062
00063
00064
00065 double large_log_odds_;
00066
00067
00068 double max_log_odds_for_belief_;
00069
00070
00071
00072
00073
00074
00075 tf::TransformListener tf_listerner_;
00076 std::string world_frame_id_;
00077 tf::TransformBroadcaster tr_broadcaster_;
00078 bool has_frame_id_;
00079 std::string map_frame_id_;
00080 double xinit_;
00081 double yinit_;
00082 long int last_xmap_;
00083 long int last_ymap_;
00084
00085 nav_msgs::OccupancyGrid map_;
00086 std::vector<double> log_odds_;
00087
00088 map_ray_caster::MapRayCaster ray_caster_;
00089 };
00090
00091
00092
00093
00094
00095 inline int offsetFromRowColNoRangeCheck(int row, int col, size_t ncol)
00096 {
00097 return (row * ncol) + col;
00098 }
00099
00100 template <typename T>
00101 void moveAndCopyImage(int fill, int dx, int dy, unsigned int ncol, std::vector<T>& map);
00102
00103 }
00104
00105 #endif // # ifndef _LOCAL_MAP_MAP_BUILDER_H_