OpenWalker Project
Documentation of the ROS Packages
conversions.h
Go to the documentation of this file.
1 
34 #ifndef OPEN_WALKER_CORE_CONVERSIONS_H
35 #define OPEN_WALKER_CORE_CONVERSIONS_H
36 
37 #include <Eigen/Dense>
38 
39 #include <tf/LinearMath/Matrix3x3.h>
40 #include <tf/LinearMath/Quaternion.h>
41 #include <tf_conversions/tf_eigen.h>
42 
43 #include <geometry_msgs/Quaternion.h>
44 #include <geometry_msgs/Point.h>
45 #include <geometry_msgs/Vector3.h>
46 
47 #include <ow_core/quaternion_ref.h>
48 
59 namespace ow_core
60 {
64 void matrixTFToEigenQuaterniond(const tf::Matrix3x3& t, Eigen::Quaterniond& e);
65 
69 template <typename _Derived>
70 void matrixTFToEigenQuaternion(const tf::Matrix3x3& t, Eigen::QuaternionBase<_Derived>& e)
71 {
72  typedef typename Eigen::internal::traits<_Derived>::Scalar Scalar;
73  Eigen::Quaterniond ed;
75  e = ed.cast<Scalar>();
76 }
77 
81 template <typename _Derived>
82 void matrixTFToEigenMatrix(const tf::Matrix3x3& t, Eigen::MatrixBase<_Derived>& e)
83 {
84  typedef typename Eigen::internal::traits<_Derived>::Scalar Scalar;
85  typedef Eigen::Matrix<double, _Derived::ColsAtCompileTime, _Derived::RowsAtCompileTime> Base;
86  Base ed;
87  tf::matrixTFToEigen(t, ed);
88  e = ed.template cast<Scalar>();
89 }
90 
94 void quaterniondEigenToMatrixTF(const Eigen::Quaterniond& e, tf::Matrix3x3& t);
95 
99 template <typename _Derived>
100 void quaternionEigenToMatrixTF(const Eigen::QuaternionBase<_Derived>& e, tf::Matrix3x3& t)
101 {
102  Eigen::Quaterniond ed;
103  ed = e.cast();
104  quaterniondEigenToMatrixTF(ed, t);
105 }
106 
110 template <typename _Derived>
111 void matrixEigenToMatrixTF(const Eigen::MatrixBase<_Derived>& e, tf::Matrix3x3& t)
112 {
113  typedef Eigen::Matrix<double, _Derived::ColsAtCompileTime, _Derived::RowsAtCompileTime> Base;
114  Base ed;
115  ed = e.template cast<double>();
116  tf::matrixEigenToTF(ed, t);
117 }
118 
122 template <typename _Derived>
123 void quaternionTFToEigenQuaternion(const tf::Quaternion& t, Eigen::QuaternionBase<_Derived>& e)
124 {
125  typedef typename Eigen::internal::traits<_Derived>::Scalar Scalar;
126  Eigen::Quaterniond ed;
127  tf::quaternionTFToEigen(t, ed);
128  e = ed.cast<Scalar>();
129 }
130 
134 template <typename _Derived>
135 void quaternionTFToEigenMatrix(const tf::Quaternion& t, Eigen::MatrixBase<_Derived>& e)
136 {
137  typedef typename Eigen::internal::traits<_Derived>::Scalar Scalar;
138  Eigen::Quaternion<Scalar> eq;
140  e = eq.toRotationMatrix();
141 }
142 
146 template <typename _Derived>
147 void quaternionEigenToQuaternionTF(const Eigen::QuaternionBase<_Derived>& e, tf::Quaternion& t)
148 {
149  // typedef typename Eigen::internal::traits<_Derived>::Scalar Scalar;
150  Eigen::Quaterniond ed;
151  ed = e.template cast<double>();
152  tf::quaternionEigenToTF(ed, t);
153 }
154 
155 template <typename _Derived>
156 void matrixEigenToQuaternionTF(const Eigen::MatrixBase<_Derived>& e, tf::Quaternion& t)
157 {
158  typedef typename Eigen::internal::traits<_Derived>::Scalar Scalar;
159  Eigen::Quaternion<Scalar> eq(e);
161 }
162 
166 void quaternionMsgToEigenQuaterniond(const geometry_msgs::Quaternion& t, Eigen::Quaterniond& e);
167 
171 template <typename _Derived>
172 void quaternionMsgToEigenQuaternion(const geometry_msgs::Quaternion& t, Eigen::QuaternionBase<_Derived>& e)
173 {
174  typedef typename Eigen::internal::traits<_Derived>::Scalar Scalar;
175  Eigen::Quaterniond ed;
176  quaternionMsgToEigenQuaterniond(t, ed);
177  e = ed.cast<Scalar>();
178 }
179 
183 template <typename _Derived>
184 void quaternionMsgToEigenMatrix(const geometry_msgs::Quaternion& t, Eigen::MatrixBase<_Derived>& e)
185 {
186  typedef typename Eigen::internal::traits<_Derived>::Scalar Scalar;
187  Eigen::Quaternion<Scalar> eq;
189  e = eq.toRotationMatrix();
190 }
191 
195 void quaterniondEigenToQuaternionMsg(const Eigen::Quaterniond& e, geometry_msgs::Quaternion& t);
196 
200 template <typename _Derived>
201 void quaternionEigenToQuaternionMsg(const Eigen::QuaternionBase<_Derived>& e, geometry_msgs::Quaternion& t)
202 {
203  // typedef typename Eigen::internal::traits<_Derived>::Scalar Scalar;
204  Eigen::Quaterniond ed;
205  ed = e.template cast<double>();
206  quaterniondEigenToQuaternionMsg(ed, t);
207 }
208 
212 template <typename _Derived>
213 void matrixEigenToQuaternionMsg(const Eigen::MatrixBase<_Derived>& e, geometry_msgs::Quaternion& t)
214 {
215  typedef typename Eigen::internal::traits<_Derived>::Scalar Scalar;
216  Eigen::Quaternion<Scalar> eq(e);
218 }
219 
223 void vector3dEigenToPointMsg(const Eigen::Vector3d& e, geometry_msgs::Point& t);
224 
228 template <typename _Derived>
229 void vector3EigenToPointMsg(const Eigen::MatrixBase<_Derived>& e, geometry_msgs::Point& t)
230 {
231  typedef Eigen::Matrix<double, _Derived::ColsAtCompileTime, _Derived::RowsAtCompileTime> Base;
232  Base ed = e.template cast<double>();
233  vector3dEigenToPointMsg(ed, t);
234 }
235 
239 void vector3dEigenToVector3Msg(const Eigen::Vector3d& e, geometry_msgs::Vector3& t);
240 
246 template <typename _Derived>
247 void vector3EigenToVector3Msg(const Eigen::MatrixBase<_Derived>& e, geometry_msgs::Vector3& t)
248 {
249  typedef Eigen::Matrix<double, _Derived::ColsAtCompileTime, _Derived::RowsAtCompileTime> Base;
250  Base ed = e.template cast<double>();
251  vector3dEigenToVector3Msg(ed, t);
252 }
253 
257 void pointMsgToEigenVector3d(const geometry_msgs::Point& t, Eigen::Vector3d& e);
258 
262 template <typename _Derived>
263 void pointMsgToEigenVector3(const geometry_msgs::Point& t, Eigen::MatrixBase<_Derived>& e)
264 {
265  typedef typename Eigen::MatrixBase<_Derived>::Scalar Scalar;
266  Eigen::Vector3d ed;
267  pointMsgToEigenVector3d(t, ed);
268  e = ed.cast<Scalar>();
269 }
270 
274 void vector3MsgToEigenVector3d(const geometry_msgs::Vector3& t, Eigen::Vector3d& e);
275 
279 template <typename _Derived>
280 void vector3MsgToEigenVector3(const geometry_msgs::Vector3& t, Eigen::MatrixBase<_Derived>& e)
281 {
282  typedef typename Eigen::MatrixBase<_Derived>::Scalar Scalar;
283  Eigen::Vector3d ed;
284  vector3MsgToEigenVector3d(t, ed);
285  e = ed.cast<Scalar>();
286 }
287 
291 template <typename _Derived>
292 void vector3EigenToVector3TF(const Eigen::MatrixBase<_Derived>& e, tf::Vector3& t)
293 {
294  Eigen::Vector3d ed;
295  ed = e.template cast<double>();
296  tf::vectorEigenToTF(ed, t);
297 }
298 
302 template <typename _Derived>
303 void vector3TFToVector3Eigen(const tf::Vector3& t, Eigen::MatrixBase<_Derived>& e)
304 {
305  typedef typename Eigen::MatrixBase<_Derived>::Scalar Scalar;
306  Eigen::Vector3d ed;
307  tf::vectorTFToEigen(t, ed);
308  e = ed.cast<Scalar>();
309 }
310 
311 } // namespace ow_core
312 
313 #endif // OPEN_WALKER_CORE_CONVERSIONS_H
void quaternionEigenToQuaternionMsg(const Eigen::QuaternionBase< _Derived > &e, geometry_msgs::Quaternion &t)
Converts an Eigen::QuaternionBase to a geometry_msgs::Quaternion.
Definition: conversions.h:201
void vector3EigenToVector3TF(const Eigen::MatrixBase< _Derived > &e, tf::Vector3 &t)
Converts an Eigen::EigenBase into a tf::Vector3.
Definition: conversions.h:292
void vector3MsgToEigenVector3(const geometry_msgs::Vector3 &t, Eigen::MatrixBase< _Derived > &e)
Converts a geometry_msgs::Vector3 into an Eigen::EigenBase.
Definition: conversions.h:280
void quaternionEigenToMatrixTF(const Eigen::QuaternionBase< _Derived > &e, tf::Matrix3x3 &t)
Converts an Eigen::QuaternionBase into a tf::Matrix3x3.
Definition: conversions.h:100
void vector3EigenToVector3Msg(const Eigen::MatrixBase< _Derived > &e, geometry_msgs::Vector3 &t)
Converts an Eigen::EigenBase to a geometry_msgs::Point.
Definition: conversions.h:247
void pointMsgToEigenVector3d(const geometry_msgs::Point &t, Eigen::Vector3d &e)
Converts a geometry_msgs::Point into an Eigen::Vector3d.
void matrixTFToEigenMatrix(const tf::Matrix3x3 &t, Eigen::MatrixBase< _Derived > &e)
Converts a tf::Matrix3x3 into an Eigen::Matrix3.
Definition: conversions.h:82
void pointMsgToEigenVector3(const geometry_msgs::Point &t, Eigen::MatrixBase< _Derived > &e)
Converts a geometry_msgs::Point into an Eigen::EigenBase.
Definition: conversions.h:263
void matrixEigenToQuaternionMsg(const Eigen::MatrixBase< _Derived > &e, geometry_msgs::Quaternion &t)
Converts an Eigen::Matrix3 to a geometry_msgs::Quaternion.
Definition: conversions.h:213
void vector3EigenToPointMsg(const Eigen::MatrixBase< _Derived > &e, geometry_msgs::Point &t)
Converts an Eigen::EigenBase to a geometry_msgs::Point.
Definition: conversions.h:229
void quaternionMsgToEigenQuaternion(const geometry_msgs::Quaternion &t, Eigen::QuaternionBase< _Derived > &e)
Converts a geometry_msgs::Quaternion into an Eigen::QuaternionBase.
Definition: conversions.h:172
void quaterniondEigenToQuaternionMsg(const Eigen::Quaterniond &e, geometry_msgs::Quaternion &t)
Converts an Eigen::Quaterniond into a geometry_msgs::Quaternion.
void quaterniondEigenToMatrixTF(const Eigen::Quaterniond &e, tf::Matrix3x3 &t)
Converts an Eigen::Quaterniond into a tf::Matrix3x3.
void quaternionMsgToEigenMatrix(const geometry_msgs::Quaternion &t, Eigen::MatrixBase< _Derived > &e)
Converts a geometry_msgs::Quaternion into an Eigen::Matrix3.
Definition: conversions.h:184
Definition: angular_acceleration.h:39
void quaternionMsgToEigenQuaterniond(const geometry_msgs::Quaternion &t, Eigen::Quaterniond &e)
Converts a geometry_msgs::Quaternion into an Eigen::Quaterniond.
void matrixEigenToMatrixTF(const Eigen::MatrixBase< _Derived > &e, tf::Matrix3x3 &t)
Converts an Eigen::MatrixBase into a tf::Matrix3x3.
Definition: conversions.h:111
void quaternionTFToEigenQuaternion(const tf::Quaternion &t, Eigen::QuaternionBase< _Derived > &e)
Converts a tf::Quaternion into an Eigen::QuaternionBase.
Definition: conversions.h:123
void vector3MsgToEigenVector3d(const geometry_msgs::Vector3 &t, Eigen::Vector3d &e)
Converts a geometry_msgs::Vector3 into an Eigen::Vector3d.
void matrixTFToEigenQuaternion(const tf::Matrix3x3 &t, Eigen::QuaternionBase< _Derived > &e)
Converts a tf::Matrix3x3 into an Eigen::QuaternionBase.
Definition: conversions.h:70
void vector3dEigenToVector3Msg(const Eigen::Vector3d &e, geometry_msgs::Vector3 &t)
Converts an Eigen::Vector3d into a geometry_msgs::Point.
void vector3TFToVector3Eigen(const tf::Vector3 &t, Eigen::MatrixBase< _Derived > &e)
Converts an tf::Vector3 into Eigen::EigenBase.
Definition: conversions.h:303
void quaternionEigenToQuaternionTF(const Eigen::QuaternionBase< _Derived > &e, tf::Quaternion &t)
Converts a tf::Quaternion into an Eigen::QuaternionBase.
Definition: conversions.h:147
void matrixTFToEigenQuaterniond(const tf::Matrix3x3 &t, Eigen::Quaterniond &e)
Converts a tf::Matrix3x3 into an Eigen::Quaterniond.
void quaternionTFToEigenMatrix(const tf::Quaternion &t, Eigen::MatrixBase< _Derived > &e)
Converts a tf::Quaternion into an Eigen::MatrixBase.
Definition: conversions.h:135
void vector3dEigenToPointMsg(const Eigen::Vector3d &e, geometry_msgs::Point &t)
Converts an Eigen::Vector3d into a geometry_msgs::Point.