OpenWalker Project
Documentation of the ROS Packages
cartesian_position.h
Go to the documentation of this file.
1 
34 #ifndef OPEN_WALKER_CORE_CARTESIAN_POSITION_REF_H
35 #define OPEN_WALKER_CORE_CARTESIAN_POSITION_REF_H
36 
39 #include <geometry_msgs/Pose.h>
40 
41 namespace ow_core
42 {
55 template <typename _Scalar>
57  public Eigen::Matrix<_Scalar, 7, 1>
58 {
59 public:
60  typedef _Scalar Scalar;
61  typedef Eigen::Matrix<Scalar, 7, 1> Base;
62  typedef Eigen::Transform<Scalar, 3, Eigen::Affine> Transform;
63 
69  static const CartesianPosition& Identity()
70  {
71  static const CartesianPosition v = (Base() << 0,0,0,1,0,0,0).finished();
72  return v;
73  }
74 
80  static const CartesianPosition& Default()
81  {
82  return Identity();
83  }
84 
85 public:
89  explicit CartesianPosition()
90  : Base(Default())
91  {
92  }
93 
100  template <typename OtherDerived>
101  CartesianPosition(const Eigen::EigenBase<OtherDerived>& other) :
102  Base(other.derived())
103  {
104  }
105 
111  CartesianPosition(const Transform& other)
112  {
113  operator=(other);
114  }
115 
119  explicit CartesianPosition(const Scalar& x, const Scalar& y, const Scalar& z,
120  const Scalar& qw, const Scalar& qx, const Scalar& qy, const Scalar& qz)
121  {
122  position().x() = x;
123  position().y() = y;
124  position().z() = z;
125  orientation().w() = qw;
126  orientation().x() = qx;
127  orientation().y() = qy;
128  orientation().z() = qz;
129  }
130 
136  explicit CartesianPosition(const typename Transform::TranslationType& other)
137  {
138  operator=(other);
139  }
140 
146  template <typename OtherDerived>
147  explicit CartesianPosition(const Eigen::RotationBase<OtherDerived, 3>& other)
148  {
149  operator=(other);
150  }
151 
156  explicit CartesianPosition(const tf::Transform& other)
157  {
158  operator=(other);
159  }
160 
165  explicit CartesianPosition(const geometry_msgs::Pose& other)
166  {
167  operator=(other);
168  }
169 
173  void setIdentity()
174  {
175  *this = Identity();
176  }
177 
181  using Base::operator=;
182 
187  void operator=(const Transform& T)
188  {
189  position() = T.translation();
190  orientation() = T.linear();
191  }
192 
197  void operator=(const tf::Transform& T)
198  {
199  position() = T.getOrigin();
200  orientation() = T.getRotation();
201  }
202 
207  void operator=(const geometry_msgs::Pose& T)
208  {
209  position() = T.position;
210  orientation() = T.orientation;
211  }
212 
217  template <typename OtherDerived>
218  void operator=(const Eigen::RotationBase<OtherDerived, 3>& R)
219  {
220  position().setZero();
221  orientation() = R.toRotationMatrix();
222  }
223 
228  void operator=(const typename Transform::TranslationType& t)
229  {
230  position() = t.vector();
231  orientation().setIdentity();
232  }
233 
238  operator Transform() const
239  {
240  return typename Transform::TranslationType(position())*orientation();
241  }
242 
247  operator tf::Transform() const
248  {
249  return tf::Transform(orientation().toQuaternionTF(), position());
250  }
251 
256  operator geometry_msgs::Pose() const
257  {
258  geometry_msgs::Pose X;
259  X.position = position();
260  X.orientation = orientation();
261  return X;
262  }
263 
268  Transform toTransformEigen()
269  {
270  return static_cast<Transform>(*this);
271  }
272 
277  tf::Transform toTransformTf()
278  {
279  return static_cast<tf::Transform>(*this);
280  }
281 
286  geometry_msgs::Pose toPoseMsg()
287  {
288  return static_cast<geometry_msgs::Pose>(*this);
289  }
290 
295  {
296  return LinearPositionRef<Base>(*this);
297  }
298 
303  {
304  return LinearPositionRef<const Base>(*this);
305  }
306 
311  {
312  return AngularPositionRef<Base>(*this,3);
313  }
314 
319  {
320  return AngularPositionRef<const Base>(*this,3);
321  }
322 
326  std::string toString() const
327  {
328  std::ostringstream out;
329  out << this->transpose();
330  return out.str();
331  }
332 };
333 
334 } // namespace ow_core
335 
336 #endif // OPEN_WALKER_CORE_CARTESIAN_POSITION_REF_H
The CartesianPosition class.
Definition: cartesian_position.h:56
static const CartesianPosition & Identity()
Construct as Identity.
Definition: cartesian_position.h:69
LinearPositionRef< Base > position()
access to position part
Definition: cartesian_position.h:294
CartesianPosition(const Eigen::RotationBase< OtherDerived, 3 > &other)
Copy constructor from Eigen::RotationBase.
Definition: cartesian_position.h:147
The LinearPositionRef class.
Definition: linear_position_ref.h:52
void operator=(const typename Transform::TranslationType &t)
Assignment form Eigen::Translation.
Definition: cartesian_position.h:228
void operator=(const Eigen::RotationBase< OtherDerived, 3 > &R)
Assignment form Eigen::RotationBase.
Definition: cartesian_position.h:218
void setIdentity()
set to identity.
Definition: cartesian_position.h:173
geometry_msgs::Pose toPoseMsg()
Conversion to geometry_msgs::Pose.
Definition: cartesian_position.h:286
CartesianPosition(const Eigen::EigenBase< OtherDerived > &other)
Copy constructor.
Definition: cartesian_position.h:101
CartesianPosition(const geometry_msgs::Pose &other)
Copy constructor from geometry_msgs::Pose.
Definition: cartesian_position.h:165
void operator=(const Transform &T)
Assignment form Eigen::Transformation.
Definition: cartesian_position.h:187
Definition: angular_acceleration.h:39
The AngularPositionRef class.
Definition: angular_position_ref.h:56
AngularPositionRef< Base > orientation()
access to orientation part
Definition: cartesian_position.h:310
Transform toTransformEigen()
Conversion to Eigen::Transformation.
Definition: cartesian_position.h:268
void operator=(const geometry_msgs::Pose &T)
Assignment form geometry_msgs::Pose.
Definition: cartesian_position.h:207
AngularPositionRef< const Base > orientation() const
const access to orientation part
Definition: cartesian_position.h:318
CartesianPosition(const tf::Transform &other)
Copy constructor from tf::Transform.
Definition: cartesian_position.h:156
void operator=(const tf::Transform &T)
Assignment form tf::Transform.
Definition: cartesian_position.h:197
tf::Transform toTransformTf()
Conversion to tf::Transform.
Definition: cartesian_position.h:277
CartesianPosition(const typename Transform::TranslationType &other)
Copy constructor from Eigen::Translation.
Definition: cartesian_position.h:136
CartesianPosition(const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &qw, const Scalar &qx, const Scalar &qy, const Scalar &qz)
Constructor from Scalars.
Definition: cartesian_position.h:119
CartesianPosition(const Transform &other)
Copy constructor from Eigen::Transform.
Definition: cartesian_position.h:111
LinearPositionRef< const Base > position() const
const access to position part
Definition: cartesian_position.h:302
static const CartesianPosition & Default()
Construct as Default.
Definition: cartesian_position.h:80
CartesianPosition()
Default Constructor.
Definition: cartesian_position.h:89
std::string toString() const
Conversion to std::string.
Definition: cartesian_position.h:326