trajectory_follower
Motion2D.hpp
Go to the documentation of this file.
1 #ifndef TRAJECTORY_FOLLOWER_MOTION2D
2 #define TRAJECTORY_FOLLOWER_MOTION2D
3 
4 #include <base/Eigen.hpp>
5 #include <base/commands/Motion2D.hpp>
6 #include <base/Angle.hpp>
7 
8 namespace trajectory_follower {
9 
10 enum DriveMode {
15 };
16 
17 struct Motion2D {
18  double translation;
19  double rotation;
20  double heading; // relative to current robot heading
21  // zero means no variation of heading
22 
24  : translation(0.)
25  , rotation(0.)
26  , heading(0.)
27  {
28  }
29 
30  Motion2D(const Eigen::Vector2d &translation, double rotation)
31  : translation((Eigen::Vector2d(translation.x(), 0) + Eigen::Vector2d(0, translation.y())).norm())
32  , rotation(rotation)
33  {
34  this->heading = atan2(translation.y(), translation.x());
35  }
36 
37  Motion2D(double translation, double rotation, double orientation)
38  : translation(translation)
39  , rotation(rotation)
40  , heading(orientation)
41  {
42  }
43 
45  {
46  if (translation == 0)
47  {
48  return ModeTurnOnTheSpot;
49  }
50  else
51  {
52  return ModeAckermann;
53  }
54  }
55 
56  base::commands::Motion2D toBaseMotion2D()
57  {
58  base::commands::Motion2D cmd;
59  cmd.rotation = this->rotation;
60  cmd.translation = this->translation;
61  return cmd;
62  }
63 
64  bool operator==(const Motion2D &m) const
65  {
66  return (m.translation == translation &&
67  m.rotation == rotation &&
68  m.heading == heading);
69  }
70 
71  bool operator!=(const Motion2D &m) const
72  {
73  return !operator==(m);
74  }
75 };
76 
77 }
78 
79 #endif
Motion2D(const Eigen::Vector2d &translation, double rotation)
Definition: Motion2D.hpp:30
double heading
Definition: Motion2D.hpp:20
Motion2D(double translation, double rotation, double orientation)
Definition: Motion2D.hpp:37
Definition: Motion2D.hpp:12
Definition: Motion2D.hpp:13
Definition: Motion2D.hpp:14
Motion2D()
Definition: Motion2D.hpp:23
Definition: Motion2D.hpp:8
bool operator!=(const Motion2D &m) const
Definition: Motion2D.hpp:71
Definition: Motion2D.hpp:11
double translation
Definition: Motion2D.hpp:18
base::commands::Motion2D toBaseMotion2D()
Definition: Motion2D.hpp:56
Definition: Motion2D.hpp:17
double rotation
Definition: Motion2D.hpp:19
DriveMode
Definition: Motion2D.hpp:10
bool operator==(const Motion2D &m) const
Definition: Motion2D.hpp:64
DriveMode getDriveMode()
Definition: Motion2D.hpp:44