15#include <px4_ros2/utils/geometry.hpp>
30template <
typename Type>
33 static constexpr Type kHalfSqrt2 =
static_cast<Type
>(0.7071067811865476);
34 const Eigen::Quaternion<Type> q_ned_to_enu{0.0, kHalfSqrt2, kHalfSqrt2,
36 const Eigen::Quaternion<Type> q_flu_to_frd{0.0, 1.0, 0.0, 0.0};
38 return q_ned_to_enu * q_ned * q_flu_to_frd;
49template <
typename Type>
52 static constexpr Type kHalfSqrt2 =
static_cast<Type
>(0.7071067811865476);
53 const Eigen::Quaternion<Type> q_enu_to_ned{0.0, kHalfSqrt2, kHalfSqrt2,
55 const Eigen::Quaternion<Type> q_frd_to_flu{0.0, 1.0, 0.0, 0.0};
57 return q_enu_to_ned * q_enu * q_frd_to_flu;
67template <
typename Type>
68Eigen::Matrix<Type, 3, 1>
yawBodyToWorld(Type yaw,
const Eigen::Matrix<Type, 3, 1>& point_body)
70 const Eigen::Quaternion<Type> q_z(
71 Eigen::AngleAxis<Type>(yaw, Eigen::Matrix<Type, 3, 1>::UnitZ()));
72 return q_z * point_body;
84 return wrapPi(
static_cast<T
>(M_PI / 2.0) - yaw_ned_rad);
96 return wrapPi(
static_cast<T
>(M_PI / 2.0) - yaw_enu_rad);
108 return -yaw_rate_ned;
120 return -yaw_rate_enu;
132 return {ned.y(), ned.x(), -ned.z()};
144 return {enu.y(), enu.x(), -enu.z()};
154static inline Eigen::Matrix<T, 3, 1>
frdToFlu(
const Eigen::Matrix<T, 3, 1>& frd)
156 return {frd.x(), -frd.y(), -frd.z()};
166static inline Eigen::Matrix<T, 3, 1>
fluToFrd(
const Eigen::Matrix<T, 3, 1>& flu)
168 return {flu.x(), -flu.y(), -flu.z()};
180 return {v_ned.y(), v_ned.x(), v_ned.z()};
192 return {v_enu.y(), v_enu.x(), v_enu.z()};
static T yawNedToEnu(const T yaw_ned_rad)
Converts yaw from NED to ENU frame.
Definition frame_conversion.hpp:82
static Eigen::Matrix< T, 3, 1 > fluToFrd(const Eigen::Matrix< T, 3, 1 > &flu)
Converts coordinates from FLU to FRD frame.
Definition frame_conversion.hpp:166
static Eigen::Matrix< T, 3, 1 > varianceNedToEnu(const Eigen::Matrix< T, 3, 1 > &v_ned)
Converts variance from NED to ENU frame.
Definition frame_conversion.hpp:178
static Eigen::Matrix< T, 3, 1 > positionEnuToNed(const Eigen::Matrix< T, 3, 1 > &enu)
Converts coordinates from ENU to NED frame.
Definition frame_conversion.hpp:142
static Eigen::Matrix< T, 3, 1 > positionNedToEnu(const Eigen::Matrix< T, 3, 1 > &ned)
Converts coordinates from NED to ENU frame.
Definition frame_conversion.hpp:130
Eigen::Quaternion< Type > attitudeNedToEnu(const Eigen::Quaternion< Type > &q_ned)
Converts attitude from NED to ENU frame. Performs reference frame change and quaternion rotation s....
Definition frame_conversion.hpp:31
static T yawRateNedToEnu(const T yaw_rate_ned)
Converts yaw rate from NED to ENU frame.
Definition frame_conversion.hpp:106
Eigen::Quaternion< Type > attitudeEnuToNed(const Eigen::Quaternion< Type > &q_enu)
Converts attitude from ENU to NED frame. Performs reference frame change and quaternion rotation s....
Definition frame_conversion.hpp:50
static Eigen::Matrix< T, 3, 1 > varianceEnuToNed(const Eigen::Matrix< T, 3, 1 > &v_enu)
Converts variance from ENU to NED frame.
Definition frame_conversion.hpp:190
static T yawEnuToNed(const T yaw_enu_rad)
Converts yaw from ENU to NED frame.
Definition frame_conversion.hpp:94
static Eigen::Matrix< T, 3, 1 > frdToFlu(const Eigen::Matrix< T, 3, 1 > &frd)
Converts coordinates from FRD to FLU frame.
Definition frame_conversion.hpp:154
static T yawRateEnuToNed(const T yaw_rate_enu)
Converts yaw rate from ENU to NED frame.
Definition frame_conversion.hpp:118
Eigen::Matrix< Type, 3, 1 > yawBodyToWorld(Type yaw, const Eigen::Matrix< Type, 3, 1 > &point_body)
Transforms a point from body frame to world frame given the yaw of the body's attitude.
Definition frame_conversion.hpp:68
Type wrapPi(Type angle)
Wraps an angle to the range [-pi, pi).
Definition geometry.hpp:70