00001 #ifndef __TINY_SLAM_FASCADE_H 00002 #define __TINY_SLAM_FASCADE_H 00003 00004 #include <memory> 00005 00006 #include "../ros/laser_scan_observer.h" 00007 #include "../ros/rviz_grid_viewer.h" 00008 #include "../core/maps/grid_cell_strategy.h" 00009 00010 #include "tiny_world.h" 00011 00021 class TinySlamFascade : public LaserScanObserver { 00022 private: 00023 using ScanMatcherObsPtr = std::shared_ptr<GridScanMatcherObserver>; 00024 public: // methods 00025 // TODO: copy ctor, move ctor, dtor 00034 TinySlamFascade(std::shared_ptr<GridCellStrategy> gcs, 00035 const TinyWorldParams ¶ms, 00036 const GridMapParams &init_map_params, 00037 bool skip_max_vals): 00038 LaserScanObserver(skip_max_vals), 00039 _world(new TinyWorld(gcs, params, init_map_params)) {} 00040 00045 void set_viewer(std::shared_ptr<RvizGridViewer> viewer) { 00046 _viewer = viewer; 00047 } 00048 00055 virtual void handle_laser_scan(TransformedLaserScan &scan) { 00056 _world->update_robot_pose(scan.d_x, scan.d_y, scan.d_yaw); 00057 _world->handle_observation(scan); 00058 00059 if (_viewer) { 00060 _viewer->show_robot_pose(_world->pose()); 00061 _viewer->show_map(_world->map()); 00062 } 00063 } 00064 00069 void add_scan_matcher_observer(ScanMatcherObsPtr obs) { 00070 _world->scan_matcher()->subscribe(obs); 00071 } 00072 00077 void remove_scan_matcher_observer(ScanMatcherObsPtr obs) { 00078 _world->scan_matcher()->unsubscribe(obs); 00079 } 00080 00081 private: 00082 // Position by IMU, used to calculate delta 00083 std::unique_ptr<TinyWorld> _world; 00084 std::shared_ptr<RvizGridViewer> _viewer; 00085 }; 00086 00087 #endif