base
Pose.hpp
Go to the documentation of this file.
1 #ifndef __BASE_POSE_HH__
2 #define __BASE_POSE_HH__
3 
4 #include "Eigen.hpp"
5 #include "Angle.hpp"
6 
7 namespace base
8 {
12 
15  typedef double Orientation2D;
16 
17  /*
18  * Decomposes the orientation in euler angles (non-proper, Tait-Bryan angles)
19  * so that this can be obtained by applying the following rotations in order:
20  *
21  * rotation of a2 around x-axis
22  * rotation of a1 around y-axis
23  * rotation of a0 around z-axis
24  *
25  * assuming angles in range of: a0:(-pi,pi), a1:(-pi/2,pi/2), a2:(-pi/2,pi/2)
26  *
27  */
28  base::Vector3d getEuler(const base::Orientation &orientation);
29 
30  /*
31  * Decomposes the orientation in euler angles so that this can be
32  * obtained by applying the following rotations in order:
33  *
34  * rotation of a2 around x-axis
35  * rotation of a1 around y-axis
36  * rotation of a0 around z-axis
37  *
38  * assuming angles in range of: a0:(-pi,pi), a1:(-pi/2,pi/2), a2:(-pi/2,pi/2)
39  *
40  */
41  base::Vector3d getEuler(const base::AngleAxisd &orientation);
42 
43  double getYaw(const base::Orientation& orientation);
44 
45 
46  double getYaw(const base::AngleAxisd& orientation);
47 
48  double getPitch(const base::Orientation& orientation);
49 
50  double getPitch(const base::AngleAxisd& orientation);
51 
52  double getRoll(const base::Orientation& orientation);
53 
54  double getRoll(const base::AngleAxisd& orientation);
55 
56  base::Orientation removeYaw(const base::Orientation& orientation);
57 
58  base::Orientation removeYaw(const base::AngleAxisd& orientation);
59 
61 
63 
65 
66  base::Orientation removeRoll(const base::AngleAxisd& orientation);
67 
73  {
75 
79  PoseUpdateThreshold( double _distance, double _angle );
80 
85  bool test( double other_distance, double other_angle );
86 
91  bool test( const Eigen::Affine3d& pdelta );
92 
102  bool test( const Eigen::Affine3d& a2b, const Eigen::Affine3d& aprime2b );
103 
104  double distance;
105  double angle;
106  };
107 
115  struct Pose
116  {
117  Position position;
118  Orientation orientation;
119 
124  : position(Position::Zero()), orientation(Orientation::Identity()) {}
125 
126  Pose(Position const& p, Orientation const& o)
127  : position(p), orientation(o) {}
128 
136  {
137  fromTransform( t );
138  }
139 
140  Pose(const Vector6d &v)
141  {
142  fromVector6d( v );
143  }
144 
152  {
153  position = t.translation();
154  orientation = t.linear();
155  }
156 
164  {
165  Eigen::Affine3d t;
166  t = orientation;
167  t.pretranslate( position );
168  return t;
169  }
170 
177  void fromVector6d( const Vector6d &v );
178 
185  Vector6d toVector6d() const;
186 
190  double getYaw() const
191  {
192  return base::getYaw(orientation);
193  }
194  };
195 
196  std::ostream& operator << (std::ostream& io, base::Pose const& pose);
197 
201  struct Pose2D
202  {
203  Position2D position;
204  Orientation2D orientation;
205 
207  : position(Position2D::Zero()), orientation(0) {}
208 
209  Pose2D(Position2D const& p, Orientation2D const& o)
210  : position(p), orientation(o) {}
211 
212  Pose2D(Position const& p, Orientation const& o)
213  : position(Vector2d(p.x(), p.y())), orientation(base::getYaw(o)) {}
214 
215  Pose2D( const Pose &p)
216  : position(Vector2d(p.position.x(), p.position.y())), orientation(p.getYaw()) {}
217 
218  bool isApprox(const Pose2D &other, double distPecision, double anglePrecision) const
219  {
220  return ((other.position - position).norm() < distPecision) &&
221  (Angle::fromRad(other.orientation).isApprox(Angle::fromRad(orientation), anglePrecision));
222  }
223 
224  };
225 
226  std::ostream& operator << (std::ostream& io, base::Pose2D const& pose);
227 }
228 
229 #endif
230 
std::ostream & operator<<(std::ostream &os, Angle angle)
Definition: Angle.cpp:25
Position2D position
Definition: Pose.hpp:203
double getPitch(const Orientation &orientation)
Definition: Pose.cpp:46
Definition: Pose.hpp:72
Eigen::Matrix< double, 6, 1, Eigen::DontAlign > Vector6d
Definition: Eigen.hpp:22
Vector3d getEuler(const Orientation &orientation)
Definition: Pose.cpp:6
Representation for a pose in 3D.
Definition: Pose.hpp:115
base::Quaterniond Orientation
Definition: Pose.hpp:11
double getYaw() const
Definition: Pose.hpp:190
double getYaw(const Orientation &orientation)
Definition: Pose.cpp:36
Definition: Pose.hpp:201
Pose()
Default constructor will initialize to zero.
Definition: Pose.hpp:123
double Orientation2D
Definition: Pose.hpp:15
Eigen::Affine3d toTransform() const
transform matrix which represents the pose transform as a 4x4 homogenous matrix
Definition: Pose.hpp:163
Orientation2D orientation
Definition: Pose.hpp:204
Pose(Position const &p, Orientation const &o)
Definition: Pose.hpp:126
base::Vector3d Position
Definition: Pose.hpp:10
void fromTransform(const Eigen::Affine3d &t)
set the pose based on a 4x4 matrix
Definition: Pose.hpp:151
Pose2D(Position2D const &p, Orientation2D const &o)
Definition: Pose.hpp:209
bool isApprox(const Pose2D &other, double distPecision, double anglePrecision) const
Definition: Pose.hpp:218
Eigen::AngleAxis< double > AngleAxisd
Definition: Eigen.hpp:34
Position position
Definition: Pose.hpp:117
Eigen::Quaternion< double, Eigen::DontAlign > Quaterniond
Definition: Eigen.hpp:33
static Angle fromRad(double rad)
Definition: Angle.hpp:85
bool test(double other_distance, double other_angle)
Definition: Pose.cpp:105
double getRoll(const Orientation &orientation)
Definition: Pose.cpp:56
Pose(const Eigen::Affine3d &t)
constructor based on a 4x4 transform matrix
Definition: Pose.hpp:135
Orientation orientation
Definition: Pose.hpp:118
double distance
Definition: Pose.hpp:104
Definition: LinearAngular6DCommand.hpp:8
Pose(const Vector6d &v)
Definition: Pose.hpp:140
PoseUpdateThreshold()
Definition: Pose.cpp:97
double angle
Definition: Pose.hpp:105
Pose2D(Position const &p, Orientation const &o)
Definition: Pose.hpp:212
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vector3d
Definition: Eigen.hpp:20
Pose2D()
Definition: Pose.hpp:206
Eigen::Transform< double, 3, Eigen::Affine > Affine3d
Definition: Eigen.cpp:20
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vector2d
Definition: Eigen.hpp:19
bool isApprox(Angle other, double prec=1e-5) const
Definition: Angle.hpp:147
Pose2D(const Pose &p)
Definition: Pose.hpp:215
Orientation removeYaw(const Orientation &orientation)
Definition: Pose.cpp:66
Orientation removeRoll(const Orientation &orientation)
Definition: Pose.cpp:86
base::Vector2d Position2D
Definition: Pose.hpp:14
Orientation removePitch(const Orientation &orientation)
Definition: Pose.cpp:76