pose_enumerators.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_CORE_POSE_ENUMERATORS_H
2 #define SLAM_CTOR_CORE_POSE_ENUMERATORS_H
3 
4 #include <cmath>
5 #include "../states/robot_pose.h"
6 
8 public:
9  virtual bool has_next() const = 0;
10  virtual RobotPose next(const RobotPose &prev_pose) = 0;
11  virtual void reset() {};
12  virtual void feedback(bool /* pose_is_acceptable */) = 0;
13  virtual ~PoseEnumerator() {}
14 };
15 
17 public:
19  double from_dir, double to_dir, double step_dir,
20  double from_dst, double to_dst, double step_dst)
21  : _base_pose_is_set{false}
22  , _from_dir{from_dir}, _to_dir{to_dir}, _step_dir{step_dir}
23  , _from_dst{from_dst}, _to_dst{to_dst}, _step_dst{step_dst} {
24  assert(_from_dir <= _to_dir && _from_dst <= _to_dst);
25  assert(0 < step_dir && 0 < step_dst);
26  reset();
27  }
28 
29  bool has_next() const override {
30  return _dst <= _to_dst; // NB: "top-level" changing dimension
31  }
32 
33  RobotPose next(const RobotPose &prev_pose) override {
34  if (!_base_pose_is_set) {
35  _base_pose = prev_pose;
36  _base_pose_is_set = true;
37  }
38 
39  auto delta = RobotPoseDelta{std::cos(_dir) * _dst,
40  std::sin(_dir) * _dst, 0};
41  return _base_pose + delta;
42  }
43 
44  void reset() override {
45  _dir = _from_dir;
46  _dst = _from_dst;
47  }
48 
49  void feedback(bool pose_is_acceptable) override {
50  // HACK: use switch falls to simplify code (no nested ifs)
51  switch (0) {
52  case 0:
53  if (_dir < _to_dir) { _dir += _step_dir; break; }
54  else { _dir = _from_dir; /* to dst */ }
55  case 1:
56  _dst += _step_dst;
57  }
58  }
59 
60 private:
61  // TODO: use std::optional when C++17 is available
64 
65  double _from_dir, _dir, _to_dir, _step_dir;
66  double _from_dst, _dst, _to_dst, _step_dst;
67 };
68 
69 
70 #endif
virtual bool has_next() const =0
virtual void reset()
virtual ~PoseEnumerator()
void feedback(bool pose_is_acceptable) override
virtual RobotPose next(const RobotPose &prev_pose)=0
PolarCoordBruteForcePoseEnumerator(double from_dir, double to_dir, double step_dir, double from_dst, double to_dst, double step_dst)
RobotPose next(const RobotPose &prev_pose) override
virtual void feedback(bool)=0


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