mars_lib 0.1.0.2abe2576fe7f
Modular and Robust Sensor-Fusion
Loading...
Searching...
No Matches
attitude_conversion.h
Go to the documentation of this file.
1// Copyright (C) 2021 Martin Scheiber, Control of Networked Systems, University of Klagenfurt, Austria.
2//
3// All rights reserved.
4//
5// This software is licensed under the terms of the BSD-2-Clause-License with
6// no commercial use allowed, the full terms of which are made available
7// in the LICENSE file. No license in patents is granted.
8//
9// You can contact the author at <martin.scheiber@ieee.org>
10
11#ifndef ATTITUDE_CONVERSION_H
12#define ATTITUDE_CONVERSION_H
13
15#include <Eigen/Dense>
16
17namespace mars
18{
23{
24 Attitude() = default;
25 Attitude(const Eigen::Quaterniond& quaternion) : quaternion_(quaternion)
26 {
27 }
28 Attitude(const Eigen::Matrix3d& rotation_matrix) : quaternion_(rotation_matrix)
29 {
30 }
31 Attitude(const Eigen::Vector3d& vec, const std::string& order = "XYZ")
32 {
33 // scoping
34 using AAd = Eigen::AngleAxisd;
35 using v3d = Eigen::Vector3d;
36
38 if (order == "XYZ")
39 {
40 quaternion_ = AAd(vec(0), v3d::UnitX()) * AAd(vec(1), v3d::UnitY()) * AAd(vec(2), v3d::UnitZ());
41 }
42 else if (order == "ZYX")
43 {
44 quaternion_ = AAd(vec(2), v3d::UnitZ()) * AAd(vec(1), v3d::UnitY()) * AAd(vec(0), v3d::UnitX());
45 }
46 }
47
48 Eigen::Quaterniond quaternion_;
49
50 Eigen::Matrix3d get_rotation_matrix()
51 {
52 return quaternion_.toRotationMatrix();
53 }
54
55 Eigen::Vector2d get_rp()
56 {
57 Eigen::Vector3d rpy = mars::Utils::RPYFromRotMat(quaternion_.toRotationMatrix());
58 return { rpy(0), rpy(1) };
59 }
60
61 friend std::ostream& operator<<(std::ostream& out, const Attitude& attitude);
62};
63
64} // namespace mars
65#endif // ATTITUDE_CONVERSION_H
static Eigen::Vector3d RPYFromRotMat(const Eigen::Matrix3d &rot_mat)
RPYFromRotMat derives the roll pitch and yaw angle from a rotation matrix (in that order)
Definition buffer.h:27
The Attitude struct.
Definition attitude_conversion.h:23
Attitude()=default
friend std::ostream & operator<<(std::ostream &out, const Attitude &attitude)
Eigen::Matrix3d get_rotation_matrix()
Definition attitude_conversion.h:50
Attitude(const Eigen::Vector3d &vec, const std::string &order="XYZ")
Definition attitude_conversion.h:31
Attitude(const Eigen::Quaterniond &quaternion)
Definition attitude_conversion.h:25
Eigen::Quaterniond quaternion_
Definition attitude_conversion.h:48
Attitude(const Eigen::Matrix3d &rotation_matrix)
Definition attitude_conversion.h:28
Eigen::Vector2d get_rp()
Definition attitude_conversion.h:55