pose2D_search_space_evaluator.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <memory>
3 #include <utility>
4 #include <chrono>
5 
6 #include "../core/maps/grid_cell.h"
7 #include "../core/maps/plain_grid_map.h"
11 #include "map_dumpers.h"
12 
13 #include "../core/maps/grid_map_scan_adders.h"
14 #include "../core/maps/const_occupancy_estimator.h"
15 #include "../core/scan_matchers/occupancy_observation_probability.h"
16 #include "../core/scan_matchers/weighted_mean_point_probability_spe.h"
17 #include "../core/scan_matchers/brute_force_scan_matcher.h"
18 
19 // FIXME: code duplication with tests's MockGridCell
21 public:
22  LastWriteWinsGridCell(double prob = 0.5) : GridCell{Occupancy{prob, 0}} {}
23  std::unique_ptr<GridCell> clone() const override {
24  return std::make_unique<LastWriteWinsGridCell>(*this);
25  }
26  void operator+= (const AreaOccupancyObservation &aoo) override {
27  _occupancy = aoo.occupancy;
28  }
29 };
30 
32 public:
33 
34  ScanMatcherSearchSpaceBuilder(double resolution)
35  : _map{
36  std::make_shared<UnboundedPlainGridMap>(
37  std::make_shared<LastWriteWinsGridCell>(),
38  GridMapParams{100, 100, resolution}
39  )} {}
40 
41  std::shared_ptr<GridMap> map() {
42  return _map;
43  }
44 
45  void on_scan_test(const RobotPose &pose, const LaserScan2D &,
46  double score) override {
47  auto coord = _map->world_to_cell({pose.x, pose.y});
48  auto eff_score = score;
49 
50  // if (are_equal(pose.x, 0.05)) {
51  // std::cout << pose << " -> " << score << " ~ "
52  // << eff_score << std::endl;
53  // }
54 
55  _map->update(coord, {true, {eff_score, 0}, {0, 0}, 1.0});
56  }
57 
58 private:
59  std::shared_ptr<GridMap> _map;
60 };
61 
62 void run_evaluation(const GridMap &map, double resolution);
63 
65  std::cout << "[1] Closed Corridor" << std::endl;
66  auto map = UnboundedPlainGridMap{std::make_shared<LastWriteWinsGridCell>(),
67  {100, 100, 0.1}};
68  auto primitive = CecumTextRasterMapPrimitive{
70  GridMapPatcher{}.apply_text_raster(map, primitive.to_stream(), {0, 10}, 1, 1);
71 
74  GridMapPatcher{}.apply_text_raster(map, pr.to_stream(), {-20, 49}, 1, 1);
77  GridMapPatcher{}.apply_text_raster(map, p.to_stream(), {-20, -9}, 1, 1);
78  for (int x = -20; x < 0; x++) {
79  for (int y = -8; y < 10; y++) {
80  map.update({x, y}, {false, {0, 0}, {0, 0}, 1});
81  }
82  }
83 
85  // TODO: dump scan
86  run_evaluation(map, 0.01);
87 }
88 
90  std::cout << "[2] Open Corridor" << std::endl;
91  auto map = UnboundedPlainGridMap{std::make_shared<LastWriteWinsGridCell>(),
92  {100, 100, 0.1}};
93  auto primitive = CecumTextRasterMapPrimitive{
95  GridMapPatcher{}.apply_text_raster(map, primitive.to_stream(),
96  {-40, 10}, 1, 1);
97  // FIXME: none bounded case
98  for (int y = -8; y < 10; y++) {
99  map.update({39, y}, {false, {0, 0}, {0, 0}, 1});
100  }
101 
102  // auto pr = CecumTextRasterMapPrimitive{
103  // 20, 40, CecumTextRasterMapPrimitive::BoundPosition::Top};
104  // GridMapPatcher{}.apply_text_raster(map, pr.to_stream(), {-20, 49}, 1, 1);
105  // auto p = CecumTextRasterMapPrimitive{
106  // 20, 40, CecumTextRasterMapPrimitive::BoundPosition::Bot};
107  // GridMapPatcher{}.apply_text_raster(map, p.to_stream(), {-20, -9}, 1, 1);
108  // for (int x = -20; x < 0; x++) {
109  // for (int y = -8; y < 10; y++) {
110  // map.update({x, y}, {false, {0, 0}, {0, 0}, 1});
111  // }
112  // }
113 
115  // TODO: dump scan
116  run_evaluation(map, 0.01);
117 }
118 
120  std::cout << "[3] Several Corridors" << std::endl;
121  auto map = UnboundedPlainGridMap{std::make_shared<LastWriteWinsGridCell>(),
122  {100, 100, 0.1}};
123  auto primitive = CecumTextRasterMapPrimitive{
125  GridMapPatcher{}.apply_text_raster(map, primitive.to_stream(), {0, 2}, 1, 1);
126  GridMapPatcher{}.apply_text_raster(map, primitive.to_stream(), {0, 7}, 1, 1);
127 
128 
130  // TODO: dump scan
131  run_evaluation(map, 0.01);
132 }
133 
134 int main(int argc, char **argv) {
138  return 0;
139 }
140 
141 void dump_scan(const LaserScan2D &scan, const RobotPose &pose) {
142  auto map = UnboundedPlainGridMap{std::make_shared<LastWriteWinsGridCell>(),
143  {100, 100, 0.1}};
144  auto scan_adder = WallDistanceBlurringScanAdder::builder()
145  .set_occupancy_estimator(
146  std::make_shared<ConstOccupancyEstimator>(Occupancy{1.0, 1.0},
147  Occupancy{0.0, 1.0}))
148  .build();
149  scan_adder->append_scan(map, pose, scan, 1.0);
151 }
152 
153 void run_evaluation(const GridMap &map, double resolution) {
154  auto sssb = std::make_shared<ScanMatcherSearchSpaceBuilder>(resolution);
155  auto tscan = TransformedLaserScan{};
156  tscan.pose_delta = RobotPoseDelta{};
157  // FIXME: scan generation from 0, 0
158  tscan.scan = LaserScanGenerator{to_lsp(100, 270, 1000)}
159  .laser_scan_2D(map, {0.05, 0.05, 0}, 1);
160  dump_scan(tscan.scan, {0.05, 0.05, 0});
161  // generate plan brute force search space map
162  auto bfsm = BruteForceScanMatcher{
163  std::make_shared<WeightedMeanPointProbabilitySPE>(
164  std::make_shared<ObstacleBasedOccupancyObservationPE>(),
165  std::make_shared<EvenSPW>()
166  ),
167  -1, 1, resolution,
168  -1, 1, resolution,
169  0, 0, 0.1}; // TODO: rotation; FIXME: hand if delta is 0; accurate poses
170  bfsm.subscribe(sssb);
171 
172  auto result = RobotPoseDelta{};
173  auto start_time = std::chrono::high_resolution_clock::now();
174  bfsm.process_scan(tscan, RobotPose{0.05, 0.05, 0}, map, result);
175  auto end_time = std::chrono::high_resolution_clock::now();
176  auto diff = std::chrono::duration<double>(end_time - start_time);
177  std::cout << "BF: " << diff.count() << std::endl;
178 
179  GridMapToPgmDumber<GridMap>{"sss_map"}
180  .on_map_update(*(sssb->map()));
181 
182  // TODO: generate testee search space map
183 }
void run_evaluation(const GridMap &map, double resolution)
static constexpr auto to_lsp(double max_dist, double fow_deg, unsigned pts_nm)
void subscribe(std::shared_ptr< GridScanMatcherObserver > obs)
void operator+=(const AreaOccupancyObservation &aoo) override
TFSIMD_FORCE_INLINE const tfScalar & y() const
static WallDistanceBlurringScanAdderBuilder builder()
void apply_text_raster(MapType &dst_map, std::istream &src_raster, const DiscretePoint2D &dst_offset, int w_zoom=1, int h_zoom=1)
void run_several_corridors_case()
void on_scan_test(const RobotPose &pose, const LaserScan2D &, double score) override
TFSIMD_FORCE_INLINE const tfScalar & x() const
Occupancy _occupancy
Definition: grid_cell.h:47
RobotPoseDelta pose_delta
Definition: sensor_data.h:177
void on_map_update(const GridMapType &map) override
Definition: map_dumpers.h:58
void dump_scan(const LaserScan2D &scan, const RobotPose &pose)
double y
Definition: robot_pose.h:131
void run_open_corridor_case()
std::unique_ptr< GridCell > clone() const override
int main(int argc, char **argv)
double x
Definition: robot_pose.h:131
void run_closed_corridor_case()


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25