12#ifndef ATTITUDE_CONVERTER_H
13#define ATTITUDE_CONVERTER_H
19#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
57 double roll(
void)
const;
64 double pitch(
void)
const;
71 double yaw(
void)
const;
74 double roll_, pitch_, yaw_;
123 operator tf2::Vector3()
const;
130 operator Eigen::Vector3d()
const;
137 operator geometry_msgs::msg::Vector3()
const;
140 tf2::Vector3 vector3_;
157 const char* what()
const throw()
159 return "AttitudeConverter: can not calculate the heading, the rotated x-axis is parallel to the world's z-axis";
166 const char* what()
const throw()
168 return "AttitudeConverter: math error";
175 const char* what()
const throw()
177 return "AttitudeConverter: invalid attitude, the input probably constains NaNs";
184 const char* what()
const throw()
186 return "AttitudeConverter: invalid Euler angle format";
193 const char* what()
const throw()
195 return "AttitudeConverter: cannot set the desired heading, the thrust vector's Z component is 0";
211 AttitudeConverter(
const double& roll,
const double& pitch,
const double& yaw,
const RPY_convention_t& format = RPY_EXTRINSIC);
250 double angle = angle_axis.angle();
251 tf2::Vector3 axis(angle_axis.axis()[0], angle_axis.axis()[1], angle_axis.axis()[2]);
253 tf2_quaternion_.setRotation(axis, angle);
279 operator tf2::Quaternion()
const;
286 operator geometry_msgs::msg::Quaternion()
const;
303 operator Eigen::AngleAxis<T>()
const
306 double angle = tf2_quaternion_.getAngle();
307 Eigen::Vector3d axis(tf2_quaternion_.getAxis()[0], tf2_quaternion_.getAxis()[1], tf2_quaternion_.getAxis()[2]);
309 Eigen::AngleAxis<T> angle_axis(angle, axis);
323 operator Eigen::Quaternion<T>()
const
326 return Eigen::Quaternion<T>(tf2_quaternion_.w(), tf2_quaternion_.x(), tf2_quaternion_.y(), tf2_quaternion_.z());
329 operator Eigen::Matrix3d()
const;
336 operator std::tuple<double&, double&, double&>();
343 operator tf2::Matrix3x3()
const;
350 operator tf2::Transform()
const;
461 template <std::
size_t I>
462 constexpr auto get();
468 tf2::Quaternion tf2_quaternion_;
473 void calculateRPY(
void);
478 void validateOrientation(
void);
483 double roll_, pitch_, yaw_;
484 bool got_rpy_ =
false;
488 template <std::
size_t I>
489 constexpr auto AttitudeConverter::get()
495 static_assert(I <= 2);
498 if constexpr (I == 0)
500 return static_cast<double>(roll_);
501 }
else if constexpr (I == 1)
503 return static_cast<double>(pitch_);
504 }
else if constexpr (I == 2)
506 return static_cast<double>(yaw_);
513struct std::tuple_size<
mrs_lib::AttitudeConverter>
515 static constexpr int value = 3;
519struct std::tuple_element<0,
mrs_lib::AttitudeConverter>
525struct std::tuple_element<1,
mrs_lib::AttitudeConverter>
531struct std::tuple_element<2,
mrs_lib::AttitudeConverter>
The main convertor class. Instantiate with any type in constructor and get the value in any other typ...
Definition attitude_converter.h:150
AttitudeConverter(const Eigen::AngleAxis< T > angle_axis)
Eigen::AngleAxis constructor.
Definition attitude_converter.h:248
std::tuple< double, double, double > getExtrinsicRPY()
get the Roll, Pitch, Yaw angles in the Extrinsic convention. The same as the default AttitudeConverte...
Definition attitude_converter.cpp:391
Vector3Converter getVectorX(void)
get a unit vector pointing in the X direction
Definition attitude_converter.cpp:361
Vector3Converter getVectorZ(void)
get a unit vector pointing in the Z direction
Definition attitude_converter.cpp:381
double getPitch(void)
get the pitch angle
Definition attitude_converter.cpp:254
double getHeading(void)
get the angle of the rotated x-axis in the original XY plane, a.k.a
Definition attitude_converter.cpp:262
double getRoll(void)
get the roll angle
Definition attitude_converter.cpp:246
Vector3Converter getVectorY(void)
get a unit vector pointing in the Y direction
Definition attitude_converter.cpp:371
AttitudeConverter setYaw(const double &new_yaw)
Updates the extrinsic yaw of the current orientation.
Definition attitude_converter.cpp:415
double getYaw(void)
get the yaw angle
Definition attitude_converter.cpp:238
double getHeadingRate(const Vector3Converter &attitude_rate)
get heading rate base on the orientation and body-based attitude rate
Definition attitude_converter.cpp:326
std::tuple< double, double, double > getIntrinsicRPY()
get the Roll, Pitch, Yaw angles in the Intrinsic convention
Definition attitude_converter.cpp:401
AttitudeConverter setHeading(const double &heading)
Updates the heading of the current orientation by updating the intrinsic yaw.
Definition attitude_converter.cpp:425
double getYawRateIntrinsic(const double &heading_rate)
get the intrinsic yaw rate from a heading rate
Definition attitude_converter.cpp:277
A small class for storing the Euler angles.
Definition attitude_converter.h:41
double roll(void) const
get the roll angle
Definition attitude_converter.cpp:19
double yaw(void) const
get the yaw angle
Definition attitude_converter.cpp:29
double pitch(void) const
get the pitch angle
Definition attitude_converter.cpp:24
Converter of Vector3 representations. Instantiate it with any type of vector3 in constructor and conv...
Definition attitude_converter.h:86
Vector3Converter(const tf2::Vector3 &vector3)
Constructor with tf2::Vector3.
Definition attitude_converter.h:93
Defines useful geometry utilities and functions.
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition attitude_converter.h:24
is thrown when calculating of heading is not possible due to atan2 exception
Definition attitude_converter.h:156
is thrown when the internal attitude becomes invalid
Definition attitude_converter.h:174
is thrown when math breaks
Definition attitude_converter.h:165
is thrown when the heading cannot be set to an existing attitude
Definition attitude_converter.h:192