robot_pose.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_CORE_ROBOT_POSE_H_INCLUDED
2 #define SLAM_CTOR_CORE_ROBOT_POSE_H_INCLUDED
3 
4 #include <iostream>
5 #include <memory>
6 #include "../math_utils.h"
7 #include "../random_utils.h"
8 #include "../geometry_utils.h"
9 
11 public: // methods
13  constexpr RobotPoseDelta(double d_x, double d_y, double d_th) :
14  x(d_x), y(d_y), theta(d_th) {}
15  constexpr RobotPoseDelta(const Point2D &offset, double d_th) :
16  x(offset.x), y(offset.y), theta(d_th) {}
17 
19  x += delta.x;
20  y += delta.y;
21  theta += delta.theta;
22  return *this;
23  }
24 
25  bool operator==(const RobotPoseDelta &rhs) const {
26  return are_equal(x, rhs.x) && are_equal(y, rhs.y) &&
27  are_equal(theta, rhs.theta);
28  }
29 
31  return {x + rhs.x, y + rhs.y, theta + rhs.theta};
32  }
33 
34  bool is_abs_less(const RobotPoseDelta& that) const {
35  //TODO: use double EQ (in this case this is not strictly required)
36  #define LESS_ABS(comp) (std::fabs(comp) < std::fabs(that.comp))
37  return LESS_ABS(x) && LESS_ABS(y) && LESS_ABS(theta);
38  #undef LESS_ABS
39  }
40  explicit operator bool() const {
41  return !are_equal(x, 0) || !are_equal(y, 0) || !are_equal(theta, 0);
42  }
43 
44  RobotPoseDelta abs() const {
45  return RobotPoseDelta{std::abs(x), std::abs(y), std::abs(theta)};
46  }
47  double sq_dist() const { return x*x + y*y; }
48 
49  void reset() { x = y = theta = 0; }
50 public: // fields
51  double x, y, theta;
52 };
53 
54 inline std::ostream& operator<<(std::ostream& os, const RobotPoseDelta& rpd) {
55  os << "PoseDelta{ x: " << rpd.x << ", y: " << rpd.y;
56  return os << ", th: " << rpd.theta << "}";
57 }
58 
59 template <typename RandomEngineT>
61 public:
62 
66  : _x_rv{x_rv.clone()}, _y_rv{y_rv.clone()}, _th_rv{th_rv.clone()} {}
67 
69  : _x_rv{rpd_rv._x_rv->clone()}, _y_rv{rpd_rv._y_rv->clone()},
70  _th_rv{rpd_rv._th_rv->clone()} {}
72  RobotPoseDeltaRV tmp{rpd_rv};
73  std::swap(_x_rv, tmp._x_rv);
74  std::swap(_y_rv, tmp._y_rv);
75  std::swap(_th_rv, tmp._th_rv);
76  return *this;
77  }
78 
79  RobotPoseDeltaRV(RobotPoseDeltaRV &&rpd_rv) = default;
80  RobotPoseDeltaRV& operator=(RobotPoseDeltaRV &&rpd_rv) = default;
82 
83  RobotPoseDelta sample(RandomEngineT &re) {
84  return RobotPoseDelta{_x_rv->sample(re), _y_rv->sample(re),
85  _th_rv->sample(re)};
86  }
87 
88 private:
89  std::unique_ptr<RandomVariable1D<RandomEngineT>> _x_rv, _y_rv, _th_rv;
90 };
91 
92 class RobotPose {
93 public: // methods
94  RobotPose(double x, double y, double theta) : x(x), y(y), theta(theta) {}
95  RobotPose(const RobotPoseDelta& rpd) : RobotPose(rpd.x, rpd.y, rpd.theta) {}
96 
97  RobotPose() : RobotPose(0, 0, 0){}
98  RobotPose(const RobotPose& that) : RobotPose(that.x, that.y, that.theta){}
99  RobotPose(const RobotPose&& that) : RobotPose(that.x, that.y, that.theta){}
101 
102  RobotPose& operator=(const RobotPose& that) {
103  if (this == &that)
104  return *this;
105 
106  this->x = that.x;
107  this->y = that.y;
108  this->theta = that.theta;
109  return *this;
110  }
111 
112  const RobotPoseDelta operator-(const RobotPose& that) const {
113  return RobotPoseDelta(x - that.x, y - that.y, theta - that.theta);
114  }
115 
116  const RobotPose operator+(const RobotPoseDelta& delta) const {
117  return RobotPose(x + delta.x, y + delta.y, theta + delta.theta);
118  }
119 
120  const RobotPose& operator+=(const RobotPoseDelta& delta) {
121  // TODO: move update policy to Strategy.
122  // TODO: original gMapping adds a nose on udpate (motionmodel.cpp:13)
123  x += delta.x;
124  y += delta.y;
125  theta += delta.theta;
126  return *this;
127  }
128 
129  auto point() const { return Point2D{x, y}; }
130 public:
131  double x, y, theta;
132 };
133 
134 inline std::ostream& operator<<(std::ostream& os, const RobotPose& rp) {
135  return os << "Pose2D{ x: " << rp.x << ", y: " << rp.y
136  << ", th: " << rp.theta << "}";
137 }
138 
139 #endif
bool operator==(const RobotPoseDelta &rhs) const
Definition: robot_pose.h:25
std::unique_ptr< RandomVariable1D< RandomEngineT > > _y_rv
Definition: robot_pose.h:89
const RobotPose operator+(const RobotPoseDelta &delta) const
Definition: robot_pose.h:116
CONSTEXPR bool are_equal(const T &a, const T &b, const T &eps)
Definition: math_utils.h:17
double theta
Definition: robot_pose.h:131
RobotPoseDelta abs() const
Definition: robot_pose.h:44
const RobotPoseDelta operator-(const RobotPose &that) const
Definition: robot_pose.h:112
double theta
Definition: robot_pose.h:51
RobotPose(double x, double y, double theta)
Definition: robot_pose.h:94
constexpr RobotPoseDelta(double d_x, double d_y, double d_th)
Definition: robot_pose.h:13
RobotPoseDelta sample(RandomEngineT &re)
Definition: robot_pose.h:83
RobotPoseDelta & operator+=(const RobotPoseDelta &delta)
Definition: robot_pose.h:18
RobotPoseDelta operator+(const RobotPoseDelta &rhs) const
Definition: robot_pose.h:30
void reset()
Definition: robot_pose.h:49
RobotPoseDeltaRV(const RandomVariable1D< RandomEngineT > &x_rv, const RandomVariable1D< RandomEngineT > &y_rv, const RandomVariable1D< RandomEngineT > &th_rv)
Definition: robot_pose.h:63
RobotPose(const RobotPoseDelta &rpd)
Definition: robot_pose.h:95
virtual std::unique_ptr< RandomVariable1D< T > > clone() const =0
RobotPoseDeltaRV & operator=(const RobotPoseDeltaRV &rpd_rv)
Definition: robot_pose.h:71
RobotPoseDeltaRV(const RobotPoseDeltaRV &rpd_rv)
Definition: robot_pose.h:68
const RobotPose & operator+=(const RobotPoseDelta &delta)
Definition: robot_pose.h:120
RobotPose(const RobotPose &&that)
Definition: robot_pose.h:99
std::ostream & operator<<(std::ostream &os, const RobotPoseDelta &rpd)
Definition: robot_pose.h:54
double y
Definition: robot_pose.h:131
#define LESS_ABS(comp)
auto point() const
Definition: robot_pose.h:129
double sq_dist() const
Definition: robot_pose.h:47
std::unique_ptr< RandomVariable1D< RandomEngineT > > _x_rv
Definition: robot_pose.h:89
constexpr RobotPoseDelta(const Point2D &offset, double d_th)
Definition: robot_pose.h:15
double x
Definition: robot_pose.h:131
bool is_abs_less(const RobotPoseDelta &that) const
Definition: robot_pose.h:34
RobotPose & operator=(const RobotPose &that)
Definition: robot_pose.h:102
RobotPose(const RobotPose &that)
Definition: robot_pose.h:98


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