Go to the documentation of this file.00001
00007 #ifndef __GRID_SCAN_MATCHER_H
00008 #define __GRID_SCAN_MATCHER_H
00009
00010 #include <vector>
00011 #include <memory>
00012 #include <algorithm>
00013
00014 #include "state_data.h"
00015 #include "sensor_data.h"
00016
00020 class GridScanMatcherObserver {
00021 public:
00028 virtual void on_matching_start(const RobotState &,
00029 const TransformedLaserScan &,
00030 const GridMap &) {}
00031
00037 virtual void on_scan_test(const RobotState &,
00038 const TransformedLaserScan &,
00039 double) {};
00040
00047 virtual void on_pose_update(const RobotState &,
00048 const TransformedLaserScan &,
00049 double) {};
00050
00055 virtual void on_matching_end(const RobotState &,
00056 double) {};
00057 };
00058
00063 class ScanCostEstimator {
00064 public:
00065
00072 virtual double estimate_scan_cost(const RobotState &pose,
00073 const TransformedLaserScan &scan,
00074 const GridMap &map,
00075 double min_cost) = 0;
00076 };
00077
00084 class GridScanMatcher {
00085 public:
00086 GridScanMatcher(std::shared_ptr<ScanCostEstimator> estimator) :
00087 _cost_estimator(estimator) {}
00088
00097 virtual double process_scan(const RobotState &init_pose,
00098 const TransformedLaserScan &scan,
00099 const GridMap &map,
00100 RobotState &pose_delta) = 0;
00101
00103 virtual void reset_state() {};
00104
00109 void subscribe(std::shared_ptr<GridScanMatcherObserver> obs) {
00110 _observers.push_back(obs);
00111 }
00112
00117 void unsubscribe(std::shared_ptr<GridScanMatcherObserver> obs) {
00118
00119 std::vector<std::weak_ptr<GridScanMatcherObserver>> new_observers;
00120 for (auto &raw_obs : GridScanMatcher::observers()) {
00121 auto obs_ptr = raw_obs.lock();
00122 if (obs_ptr && obs_ptr != obs) {
00123 new_observers.push_back(raw_obs);
00124 }
00125 }
00126 _observers = new_observers;
00127 }
00128
00129 protected:
00131 std::shared_ptr<ScanCostEstimator> cost_estimator() {
00132 return _cost_estimator;
00133 }
00134
00136 std::vector<std::weak_ptr<GridScanMatcherObserver>> & observers() {
00137 return _observers;
00138 }
00139 private:
00140 std::vector<std::weak_ptr<GridScanMatcherObserver>> _observers;
00141 std::shared_ptr<ScanCostEstimator> _cost_estimator;
00142 };
00143
00144 #endif