Drake
roll_pitch_yaw.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cmath>
4 
5 #include <Eigen/Dense>
6 
8 
9 namespace drake {
10 namespace math {
11 
12 template <typename Derived>
14  const Eigen::MatrixBase<Derived>& rpy) {
15  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Eigen::MatrixBase<Derived>, 3);
16  auto rpy_2 = (rpy / 2.0).array();
17  auto s = rpy_2.sin();
18  auto c = rpy_2.cos();
19 
20  Eigen::Vector4d q;
21  q << c(0) * c(1) * c(2) + s(0) * s(1) * s(2),
22  s(0) * c(1) * c(2) - c(0) * s(1) * s(2),
23  c(0) * s(1) * c(2) + s(0) * c(1) * s(2),
24  c(0) * c(1) * s(2) - s(0) * s(1) * c(2);
25 
26  q /= q.norm() + std::numeric_limits<typename Derived::Scalar>::epsilon();
27  return q;
28 }
29 
30 template <typename Derived>
32  const Eigen::MatrixBase<Derived>& rpy) {
33  return quat2axis(rpy2quat(rpy));
34 }
35 
36 template <typename Derived>
38  const Eigen::MatrixBase<Derived>& rpy) {
39  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Eigen::MatrixBase<Derived>, 3);
40  auto rpy_array = rpy.array();
41  auto s = rpy_array.sin();
42  auto c = rpy_array.cos();
43 
45  R.row(0) << c(2) * c(1), c(2) * s(1) * s(0) - s(2) * c(0),
46  c(2) * s(1) * c(0) + s(2) * s(0);
47  R.row(1) << s(2) * c(1), s(2) * s(1) * s(0) + c(2) * c(0),
48  s(2) * s(1) * c(0) - c(2) * s(0);
49  R.row(2) << -s(1), c(1) * s(0), c(1) * c(0);
50 
51  return R;
52 }
53 
54 template <typename Derived>
55 Eigen::Matrix<typename Derived::Scalar, 9, 3> drpy2rotmat(
56  const Eigen::MatrixBase<Derived>& rpy) {
57  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Eigen::MatrixBase<Derived>, 3);
58  auto rpy_array = rpy.array();
59  auto s = rpy_array.sin();
60  auto c = rpy_array.cos();
61 
62  Eigen::Matrix<typename Derived::Scalar, 9, 3> dR;
63  dR.row(0) << 0, c(2) * -s(1), c(1) * -s(2);
64  dR.row(1) << 0, -s(1) * s(2), c(2) * c(1);
65  dR.row(2) << 0, -c(1), 0;
66  dR.row(3) << c(2) * s(1) * c(0) - s(2) * -s(0), c(2) * c(1) * s(0),
67  -s(2) * s(1) * s(0) - c(2) * c(0);
68  dR.row(4) << s(2) * s(1) * c(0) + c(2) * -s(0), s(2) * c(1) * s(0),
69  c(2) * s(1) * s(0) - s(2) * c(0);
70  dR.row(5) << c(1) * c(0), -s(1) * s(0), 0;
71  dR.row(6) << c(2) * s(1) * -s(0) + s(2) * c(0), c(2) * c(1) * c(0),
72  -s(2) * s(1) * c(0) + c(2) * s(0);
73  dR.row(7) << s(2) * s(1) * -s(0) - c(2) * c(0), s(2) * c(1) * c(0),
74  c(2) * s(1) * c(0) + s(2) * s(0);
75  dR.row(8) << c(1) * -s(0), -s(1) * c(0), 0;
76 
77  return dR;
78 }
79 
80 } // namespace math
81 } // namespace drake
This file contains abbreviated definitions for certain specializations of Eigen::Matrix that are comm...
Eigen::Matrix< Scalar, 4, 1 > Vector4
A column vector of size 4, templated on scalar type.
Definition: eigen_types.h:28
Definition: constants.h:3
Vector4< typename Derived::Scalar > rpy2axis(const Eigen::MatrixBase< Derived > &rpy)
Definition: roll_pitch_yaw.h:31
Vector4< typename Derived::Scalar > rpy2quat(const Eigen::MatrixBase< Derived > &rpy)
Definition: roll_pitch_yaw.h:13
Vector4< typename Derived::Scalar > quat2axis(const Eigen::MatrixBase< Derived > &q)
Definition: quaternion.h:136
Eigen::Matrix< Scalar, 3, 3 > Matrix3
A matrix of 3 rows and 3 columns, templated on scalar type.
Definition: eigen_types.h:40
Matrix3< typename Derived::Scalar > rpy2rotmat(const Eigen::MatrixBase< Derived > &rpy)
Definition: roll_pitch_yaw.h:37
Eigen::Matrix< typename Derived::Scalar, 9, 3 > drpy2rotmat(const Eigen::MatrixBase< Derived > &rpy)
Definition: roll_pitch_yaw.h:55