Math class
JPL quaternion math utilities.
Contents
- Reference
This file contains the common utility functions for operating on JPL quaternions. We need to take special care to handle edge cases when converting to and from other rotation formats. All equations are based on the following tech report:
Trawny, Nikolas, and Stergios I. Roumeliotis. "Indirect Kalman filter for 3D attitude estimation." University of Minnesota, Dept. of Comp. Sci. & Eng., Tech. Rep 2 (2005): 2005. http:/
/ mars.cs.umn.edu/ tr/ reports/ Trawny05b.pdf
Public static functions
- static auto rot_2_quat(const Eigen::Matrix<double, 3, 3>& rot) -> Eigen::Matrix<double, 4, 1>
- Returns a JPL quaternion from a rotation matrix.
- static auto skew_x(const Eigen::Matrix<double, 3, 1>& w) -> Eigen::Matrix<double, 3, 3>
- Skew-symmetric matrix from a given 3x1 vector.
- static auto quat_2_Rot(const Eigen::Matrix<double, 4, 1>& q) -> Eigen::Matrix<double, 3, 3>
- Converts JPL quaterion to SO(3) rotation matrix.
- static auto quat_multiply(const Eigen::Matrix<double, 4, 1>& q, const Eigen::Matrix<double, 4, 1>& p) -> Eigen::Matrix<double, 4, 1>
- Multiply two JPL quaternions.
- static auto vee(const Eigen::Matrix<double, 3, 3>& w_x) -> Eigen::Matrix<double, 3, 1>
- Returns vector portion of skew-symmetric.
- static auto exp_so3(const Eigen::Matrix<double, 3, 1>& w) -> Eigen::Matrix<double, 3, 3>
- SO(3) matrix exponential.
- static auto log_so3(const Eigen::Matrix<double, 3, 3>& R) -> Eigen::Matrix<double, 3, 1>
- SO(3) matrix logarithm.
- static auto exp_se3(Eigen::Matrix<double, 6, 1> vec) -> Eigen::Matrix4d
- SE(3) matrix exponential function.
- static auto log_se3(Eigen::Matrix4d mat) -> Eigen::Matrix<double, 6, 1>
- SE(3) matrix logarithm.
- static auto hat_se3(const Eigen::Matrix<double, 6, 1>& vec) -> Eigen::Matrix4d
- Hat operator for R^6 -> Lie Algebra se(3)
- static auto Inv(Eigen::Matrix<double, 4, 1> q) -> Eigen::Matrix<double, 4, 1>
- JPL Quaternion inverse.
- static auto Omega(Eigen::Matrix<double, 3, 1> w) -> Eigen::Matrix<double, 4, 4>
- Integrated quaternion from angular velocity.
- static auto quatnorm(Eigen::Matrix<double, 4, 1> q_t) -> Eigen::Matrix<double, 4, 1>
- Normalizes a quaternion to make sure it is unit norm.
- static auto rot2rpy(const Eigen::Matrix<double, 3, 3>& rot) -> Eigen::Matrix<double, 3, 1>
- Gets roll, pitch, yaw of argument rotation (in that order). To recover the matrix: R_input = R_z(yaw)*R_y(pitch)*R_x(roll)
- static auto rot_x(double t) -> Eigen::Matrix<double, 3, 3>
- Construct rotation matrix from given roll.
- static auto rot_y(double t) -> Eigen::Matrix<double, 3, 3>
- Construct rotation matrix from given pitch.
- static auto rot_z(double t) -> Eigen::Matrix<double, 3, 3>
- Construct rotation matrix from given yaw.
Function documentation
static Eigen::Matrix<double, 4, 1> ov_eval:: Math:: rot_2_quat(const Eigen::Matrix<double, 3, 3>& rot)
Returns a JPL quaternion from a rotation matrix.
| Parameters | |
|---|---|
| rot in | 3x3 rotation matrix |
| Returns | 4x1 quaternion |
This is based on the equation 74 in Indirect Kalman Filter for 3D Attitude Estimation. In the implementation, we have 4 statements so that we avoid a division by zero and instead always divide by the largest diagonal element. This all comes from the definition of a rotation matrix, using the diagonal elements and an off-diagonal.
static Eigen::Matrix<double, 3, 3> ov_eval:: Math:: skew_x(const Eigen::Matrix<double, 3, 1>& w)
Skew-symmetric matrix from a given 3x1 vector.
| Parameters | |
|---|---|
| w in | 3x1 vector to be made a skew-symmetric |
| Returns | 3x3 skew-symmetric matrix |
This is based on equation 6 in Indirect Kalman Filter for 3D Attitude Estimation:
static Eigen::Matrix<double, 3, 3> ov_eval:: Math:: quat_2_Rot(const Eigen::Matrix<double, 4, 1>& q)
Converts JPL quaterion to SO(3) rotation matrix.
| Parameters | |
|---|---|
| q in | JPL quaternion |
| Returns | 3x3 SO(3) rotation matrix |
This is based on equation 62 in Indirect Kalman Filter for 3D Attitude Estimation:
static Eigen::Matrix<double, 4, 1> ov_eval:: Math:: quat_multiply(const Eigen::Matrix<double, 4, 1>& q,
const Eigen::Matrix<double, 4, 1>& p)
Multiply two JPL quaternions.
| Parameters | |
|---|---|
| q in | First JPL quaternion |
| p in | Second JPL quaternion |
| Returns | 4x1 resulting p*q quaternion |
This is based on equation 9 in Indirect Kalman Filter for 3D Attitude Estimation. We also enforce that the quaternion is unique by having q_4 be greater than zero.
static Eigen::Matrix<double, 3, 3> ov_eval:: Math:: exp_so3(const Eigen::Matrix<double, 3, 1>& w)
SO(3) matrix exponential.
| Parameters | |
|---|---|
| w in | 3x1 vector we will take the exponential of |
| Returns | SO(3) rotation matrix |
SO(3) matrix exponential mapping from the vector to SO(3) lie group. This formula ends up being the Rodrigues formula. This definition was taken from "Lie Groups for 2D and 3D Transformations" by Ethan Eade equation 15. http:/
static Eigen::Matrix<double, 3, 1> ov_eval:: Math:: log_so3(const Eigen::Matrix<double, 3, 3>& R)
SO(3) matrix logarithm.
| Parameters | |
|---|---|
| R in | 3x3 SO(3) rotation matrix |
| Returns | 3x1 in the se(3) space [omegax, omegay, omegaz] |
This definition was taken from "Lie Groups for 2D and 3D Transformations" by Ethan Eade equation 17 & 18. http:/
static Eigen::Matrix4d ov_eval:: Math:: exp_se3(Eigen::Matrix<double, 6, 1> vec)
SE(3) matrix exponential function.
| Parameters | |
|---|---|
| vec | 6x1 in the se(3) space [omega, u] |
| Returns | 4x4 SE(3) matrix |
Equation is from Ethan Eade's reference: http:/
where we have the following definitions
static Eigen::Matrix<double, 6, 1> ov_eval:: Math:: log_se3(Eigen::Matrix4d mat)
SE(3) matrix logarithm.
| Parameters | |
|---|---|
| mat | 4x4 SE(3) matrix |
| Returns | 6x1 in the se(3) space [omega, u] |
Equation is from Ethan Eade's reference: http:/
where we have the following definitions
static Eigen::Matrix4d ov_eval:: Math:: hat_se3(const Eigen::Matrix<double, 6, 1>& vec)
Hat operator for R^6 -> Lie Algebra se(3)
| Parameters | |
|---|---|
| vec | 6x1 in the se(3) space [omega, u] |
| Returns | Lie algebra se(3) 4x4 matrix |
static Eigen::Matrix<double, 4, 1> ov_eval:: Math:: Inv(Eigen::Matrix<double, 4, 1> q)
JPL Quaternion inverse.
| Parameters | |
|---|---|
| q in | quaternion we want to change |
| Returns | inversed quaternion |
See equation 21 in Indirect Kalman Filter for 3D Attitude Estimation.
static Eigen::Matrix<double, 4, 4> ov_eval:: Math:: Omega(Eigen::Matrix<double, 3, 1> w)
Integrated quaternion from angular velocity.
See equation (48) of trawny tech report Indirect Kalman Filter for 3D Attitude Estimation.
static Eigen::Matrix<double, 4, 1> ov_eval:: Math:: quatnorm(Eigen::Matrix<double, 4, 1> q_t)
Normalizes a quaternion to make sure it is unit norm.
| Parameters | |
|---|---|
| q_t | Quaternion to normalized |
| Returns | Normalized quaterion |
static Eigen::Matrix<double, 3, 1> ov_eval:: Math:: rot2rpy(const Eigen::Matrix<double, 3, 3>& rot)
Gets roll, pitch, yaw of argument rotation (in that order). To recover the matrix: R_input = R_z(yaw)*R_y(pitch)*R_x(roll)
| Parameters | |
|---|---|
| rot | Rotation matrix |
static Eigen::Matrix<double, 3, 3> ov_eval:: Math:: rot_x(double t)
Construct rotation matrix from given roll.
| Parameters | |
|---|---|
| t | roll angle |
static Eigen::Matrix<double, 3, 3> ov_eval:: Math:: rot_y(double t)
Construct rotation matrix from given pitch.
| Parameters | |
|---|---|
| t | pitch angle |
static Eigen::Matrix<double, 3, 3> ov_eval:: Math:: rot_z(double t)
Construct rotation matrix from given yaw.
| Parameters | |
|---|---|
| t | yaw angle |