|
mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
|
Go to the documentation of this file.
12 #ifndef ATTITUDE_CONVERTER_H
13 #define ATTITUDE_CONVERTER_H
17 #include <Eigen/Dense>
20 #include <tf2_ros/transform_listener.h>
21 #include <tf2_ros/buffer.h>
22 #include <tf2_eigen/tf2_eigen.h>
23 #include <tf2_geometry_msgs/tf2_geometry_msgs.h>
24 #include <tf/transform_datatypes.h>
25 #include <tf_conversions/tf_eigen.h>
62 double roll(
void)
const;
69 double pitch(
void)
const;
76 double yaw(
void)
const;
79 double roll_, pitch_, yaw_;
127 operator tf2::Vector3()
const;
134 operator Eigen::Vector3d()
const;
141 operator geometry_msgs::Vector3()
const;
144 tf2::Vector3 vector3_;
160 const char* what()
const throw() {
161 return "AttitudeConverter: can not calculate the heading, the rotated x-axis is parallel to the world's z-axis";
168 const char* what()
const throw() {
169 return "AttitudeConverter: math error";
176 const char* what()
const throw() {
177 return "AttitudeConverter: invalid attitude, the input probably constains NaNs";
184 const char* what()
const throw() {
185 return "AttitudeConverter: invalid Euler angle format";
192 const char* what()
const throw() {
193 return "AttitudeConverter: cannot set the desired heading, the thrust vector's Z component is 0";
209 AttitudeConverter(
const double& roll,
const double& pitch,
const double& yaw,
const RPY_convention_t& format = RPY_EXTRINSIC);
254 double angle = angle_axis.angle();
255 tf2::Vector3 axis(angle_axis.axis()[0], angle_axis.axis()[1], angle_axis.axis()[2]);
257 tf2_quaternion_.setRotation(axis, angle);
283 operator tf2::Quaternion()
const;
290 operator tf::Quaternion()
const;
297 operator geometry_msgs::Quaternion()
const;
314 operator Eigen::AngleAxis<T>()
const {
316 double angle = tf2_quaternion_.getAngle();
317 Eigen::Vector3d axis(tf2_quaternion_.getAxis()[0], tf2_quaternion_.getAxis()[1], tf2_quaternion_.getAxis()[2]);
319 Eigen::AngleAxis<T> angle_axis(angle, axis);
333 operator Eigen::Quaternion<T>()
const {
335 return Eigen::Quaternion<T>(tf2_quaternion_.w(), tf2_quaternion_.x(), tf2_quaternion_.y(), tf2_quaternion_.z());
338 operator Eigen::Matrix3d()
const;
345 operator std::tuple<double&, double&, double&>();
352 operator tf2::Matrix3x3()
const;
359 operator tf2::Transform()
const;
470 template <std::
size_t I>
471 constexpr
auto get();
477 tf2::Quaternion tf2_quaternion_;
482 void calculateRPY(
void);
487 void validateOrientation(
void);
492 double roll_, pitch_, yaw_;
493 bool got_rpy_ =
false;
497 template <std::
size_t I>
498 constexpr
auto AttitudeConverter::get() {
503 static_assert(I <= 2);
506 if constexpr (I == 0) {
507 return static_cast<double>(roll_);
508 }
else if constexpr (I == 1) {
509 return static_cast<double>(pitch_);
510 }
else if constexpr (I == 2) {
511 return static_cast<double>(yaw_);
518 struct std::tuple_size<
mrs_lib::AttitudeConverter>
519 {
static constexpr
int value = 3; };
522 struct std::tuple_element<0,
mrs_lib::AttitudeConverter>
523 {
using type = double; };
526 struct std::tuple_element<1,
mrs_lib::AttitudeConverter>
527 {
using type = double; };
530 struct std::tuple_element<2,
mrs_lib::AttitudeConverter>
531 {
using type = double; };
AttitudeConverter(const double &roll, const double &pitch, const double &yaw, const RPY_convention_t &format=RPY_EXTRINSIC)
Euler angles constructor.
Definition: attitude_converter.cpp:78
double getHeading(void)
get the angle of the rotated x-axis in the original XY plane, a.k.a
Definition: attitude_converter.cpp:254
Vector3Converter getVectorY(void)
get a unit vector pointing in the Y direction
Definition: attitude_converter.cpp:354
is thrown when calculating of heading is not possible due to atan2 exception
Definition: attitude_converter.h:158
Vector3Converter(const tf2::Vector3 &vector3)
Constructor with tf2::Vector3.
Definition: attitude_converter.h:97
AttitudeConverter(const Eigen::AngleAxis< T > angle_axis)
Eigen::AngleAxis constructor.
Definition: attitude_converter.h:253
std::tuple< double, double, double > getIntrinsicRPY()
get the Roll, Pitch, Yaw angles in the Intrinsic convention
Definition: attitude_converter.cpp:381
double getYawRateIntrinsic(const double &heading_rate)
get the intrinsic yaw rate from a heading rate
Definition: attitude_converter.cpp:267
double getYaw(void)
get the yaw angle
Definition: attitude_converter.cpp:233
is thrown when math breaks
Definition: attitude_converter.h:166
double getRoll(void)
get the roll angle
Definition: attitude_converter.cpp:240
The main convertor class. Instantiate with any type in constructor and get the value in any other typ...
Definition: attitude_converter.h:153
double pitch(void) const
get the pitch angle
Definition: attitude_converter.cpp:20
Vector3Converter getVectorZ(void)
get a unit vector pointing in the Z direction
Definition: attitude_converter.cpp:363
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:372
Defines useful geometry utilities and functions.
AttitudeConverter setYaw(const double &new_yaw)
Updates the extrinsic yaw of the current orientation.
Definition: attitude_converter.cpp:394
double roll(void) const
get the roll angle
Definition: attitude_converter.cpp:16
EulerAttitude(const double &roll, const double &pitch, const double &yaw)
A simple class for storing the Euler angles.
Definition: attitude_converter.cpp:13
Vector3Converter getVectorX(void)
get a unit vector pointing in the X direction
Definition: attitude_converter.cpp:345
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition: attitude_converter.h:29
double yaw(void) const
get the yaw angle
Definition: attitude_converter.cpp:24
A small class for storing the Euler angles.
Definition: attitude_converter.h:46
double getPitch(void)
get the pitch angle
Definition: attitude_converter.cpp:247
Converter of Vector3 representations. Instantiate it with any type of vector3 in constructor and conv...
Definition: attitude_converter.h:90
AttitudeConverter setHeading(const double &heading)
Updates the heading of the current orientation by updating the intrinsic yaw.
Definition: attitude_converter.cpp:403
double getHeadingRate(const Vector3Converter &attitude_rate)
get heading rate base on the orientation and body-based attitude rate
Definition: attitude_converter.cpp:312
is thrown when the heading cannot be set to an existing attitude
Definition: attitude_converter.h:190
is thrown when the internal attitude becomes invalid
Definition: attitude_converter.h:174