laser_scan_grid_world.h
Go to the documentation of this file.
00001 
00007 #ifndef __LASER_SCAN_GRID_WORLD_H
00008 #define __LASER_SCAN_GRID_WORLD_H
00009 
00010 #include <memory>
00011 
00012 #include "sensor_data.h"
00013 #include "state_data.h"
00014 #include "maps/grid_cell_strategy.h"
00015 #include "maps/grid_map.h"
00016 
00022 class LaserScanGridWorld : public World<TransformedLaserScan, GridMap> {
00023 public: //types
00024   using MapType = GridMap;
00025   using Point = DiscretePoint2D;
00026 public: // methods
00027 
00032   LaserScanGridWorld(std::shared_ptr<GridCellStrategy> gcs,
00033                      const GridMapParams &init_params) :
00034     _map(gcs->cell_factory(), init_params) {}
00035 
00041   virtual void handle_observation(TransformedLaserScan &scan) {
00042     const RobotState& pose = World<TransformedLaserScan, MapType>::pose();
00043     for (const auto &sp : scan.points) {
00044       // move to world frame assume sensor is in robots' (0,0)
00045       double x_world = pose.x + sp.range * std::cos(sp.angle + pose.theta);
00046       double y_world = pose.y + sp.range * std::sin(sp.angle + pose.theta);
00047 
00048       handle_scan_point(map(), pose.x, pose.y, x_world, y_world,
00049                         sp.is_occupied, scan.quality);
00050     }
00051   }
00052 
00062   virtual void handle_scan_point(MapType &map,
00063                                  double laser_x, double laser_y,
00064                                  double beam_end_x, double beam_end_y,
00065                                  bool is_occ, double quality) {
00066     Point robot_pt = map.world_to_cell(laser_x, laser_y);
00067     Point obst_pt = map.world_to_cell(beam_end_x, beam_end_y);
00068 
00069     std::vector<Point> pts = DiscreteLine2D(robot_pt, obst_pt).points();
00070 
00071     map.update_cell(pts.back(), Occupancy{is_occ ? 1.0 : 0.0, 1.0}, quality);
00072     pts.pop_back();
00073     for (const auto &pt : pts) {
00074       map.update_cell(pt, Occupancy{0.0, 1.0}, quality);
00075     }
00076   }
00077 
00078   virtual const MapType& map() const { return _map; }
00079   virtual MapType& map() { return _map; }
00080 
00081 private: // fields
00082   MapType _map;
00083 };
00084 
00085 #endif


tiny_slam
Author(s):
autogenerated on Thu Jun 6 2019 17:44:57