MicroMouse Control Module  v1.3.2-2-ge2c6882
pose.h
[詳解]
1 
8 #pragma once
9 
10 #include <cmath>
11 #include <ostream>
12 
13 namespace ctrl {
14 
18 struct Pose {
19  float x;
20  float y;
21  float th;
23  public:
24  constexpr Pose(const float x = 0, const float y = 0, const float th = 0)
25  : x(x), y(y), th(th) {}
26  void clear() { x = y = th = 0; }
27  Pose mirror_x() const { return Pose(x, -y, -th); }
28  Pose rotate(const float angle) const {
29  const float cos_angle = std::cos(angle);
30  const float sin_angle = std::sin(angle);
31  return {x * cos_angle - y * sin_angle, x * sin_angle + y * cos_angle, th};
32  }
33  Pose homogeneous(const Pose& offset) const {
34  return offset + this->rotate(offset.th);
35  }
36  Pose& operator+=(const Pose& o) {
37  return x += o.x, y += o.y, th += o.th, *this;
38  }
39  Pose& operator-=(const Pose& o) {
40  return x -= o.x, y -= o.y, th -= o.th, *this;
41  }
42  Pose operator+(const Pose& o) const { return {x + o.x, y + o.y, th + o.th}; }
43  Pose operator-(const Pose& o) const { return {x - o.x, y - o.y, th - o.th}; }
44  friend std::ostream& operator<<(std::ostream& os, const Pose& o) {
45  return os << "(" << o.x << ", " << o.y << ", " << o.th << ")";
46  }
47 };
48 
49 } // namespace ctrl
制御関係の名前空間
Definition: accel_curve.h:54
位置姿勢の座標
Definition: pose.h:18
Pose homogeneous(const Pose &offset) const
Definition: pose.h:33
void clear()
Definition: pose.h:26
float y
y 成分 [m]
Definition: pose.h:20
Pose mirror_x() const
Definition: pose.h:27
Pose rotate(const float angle) const
Definition: pose.h:28
constexpr Pose(const float x=0, const float y=0, const float th=0)
Definition: pose.h:24
Pose & operator+=(const Pose &o)
Definition: pose.h:36
friend std::ostream & operator<<(std::ostream &os, const Pose &o)
Definition: pose.h:44
float x
x 成分 [m]
Definition: pose.h:19
Pose operator-(const Pose &o) const
Definition: pose.h:43
Pose & operator-=(const Pose &o)
Definition: pose.h:39
Pose operator+(const Pose &o) const
Definition: pose.h:42
float th
theta 成分 [rad]
Definition: pose.h:21