PX4 Firmware
PX4 Autopilot Software http://px4.io
rotation.h
Go to the documentation of this file.
1
/****************************************************************************
2
*
3
* Copyright (C) 2013 PX4 Development Team. All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
*
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in
13
* the documentation and/or other materials provided with the
14
* distribution.
15
* 3. Neither the name PX4 nor the names of its contributors may be
16
* used to endorse or promote products derived from this software
17
* without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
31
*
32
****************************************************************************/
33
34
/**
35
* @file rotation.h
36
*
37
* Vector rotation library
38
*/
39
40
#ifndef ROTATION_H_
41
#define ROTATION_H_
42
43
#include <unistd.h>
44
#include <mathlib/mathlib.h>
45
#include <
matrix/math.hpp
>
46
47
/**
48
* Enum for board and external compass rotations.
49
* This enum maps from board attitude to airframe attitude.
50
*/
51
enum
Rotation
{
52
ROTATION_NONE
= 0,
53
ROTATION_YAW_45
= 1,
54
ROTATION_YAW_90
= 2,
55
ROTATION_YAW_135
= 3,
56
ROTATION_YAW_180
= 4,
57
ROTATION_YAW_225
= 5,
58
ROTATION_YAW_270
= 6,
59
ROTATION_YAW_315
= 7,
60
ROTATION_ROLL_180
= 8,
61
ROTATION_ROLL_180_YAW_45
= 9,
62
ROTATION_ROLL_180_YAW_90
= 10,
63
ROTATION_ROLL_180_YAW_135
= 11,
64
ROTATION_PITCH_180
= 12,
65
ROTATION_ROLL_180_YAW_225
= 13,
66
ROTATION_ROLL_180_YAW_270
= 14,
67
ROTATION_ROLL_180_YAW_315
= 15,
68
ROTATION_ROLL_90
= 16,
69
ROTATION_ROLL_90_YAW_45
= 17,
70
ROTATION_ROLL_90_YAW_90
= 18,
71
ROTATION_ROLL_90_YAW_135
= 19,
72
ROTATION_ROLL_270
= 20,
73
ROTATION_ROLL_270_YAW_45
= 21,
74
ROTATION_ROLL_270_YAW_90
= 22,
75
ROTATION_ROLL_270_YAW_135
= 23,
76
ROTATION_PITCH_90
= 24,
77
ROTATION_PITCH_270
= 25,
78
ROTATION_ROLL_270_YAW_270
= 26,
79
ROTATION_ROLL_180_PITCH_270
= 27,
80
ROTATION_PITCH_90_YAW_180
= 28,
81
ROTATION_PITCH_90_ROLL_90
= 29,
82
ROTATION_YAW_293_PITCH_68_ROLL_90
= 30,
83
ROTATION_PITCH_90_ROLL_270
= 31,
84
ROTATION_PITCH_9_YAW_180
= 32,
85
ROTATION_PITCH_45
= 33,
86
ROTATION_PITCH_315
= 34,
87
ROTATION_ROLL_90_YAW_270
= 35,
88
ROTATION_MAX
89
};
90
91
typedef
struct
{
92
uint16_t
roll
;
93
uint16_t
pitch
;
94
uint16_t
yaw
;
95
}
rot_lookup_t
;
96
97
const
rot_lookup_t
rot_lookup
[] = {
98
{ 0, 0, 0 },
99
{ 0, 0, 45 },
100
{ 0, 0, 90 },
101
{ 0, 0, 135 },
102
{ 0, 0, 180 },
103
{ 0, 0, 225 },
104
{ 0, 0, 270 },
105
{ 0, 0, 315 },
106
{180, 0, 0 },
107
{180, 0, 45 },
108
{180, 0, 90 },
109
{180, 0, 135 },
110
{ 0, 180, 0 },
111
{180, 0, 225 },
112
{180, 0, 270 },
113
{180, 0, 315 },
114
{ 90, 0, 0 },
115
{ 90, 0, 45 },
116
{ 90, 0, 90 },
117
{ 90, 0, 135 },
118
{270, 0, 0 },
119
{270, 0, 45 },
120
{270, 0, 90 },
121
{270, 0, 135 },
122
{ 0, 90, 0 },
123
{ 0, 270, 0 },
124
{270, 0, 270 },
125
{180, 270, 0 },
126
{ 0, 90, 180 },
127
{ 90, 90, 0 },
128
{ 90, 68, 293 },
129
{270, 90, 0 },
130
{ 0, 9, 180 },
131
{ 0, 45, 0 },
132
{ 0, 315, 0 },
133
{ 90, 0, 270 },
134
};
135
136
/**
137
* Get the rotation matrix
138
*/
139
__EXPORT
matrix::Dcmf
140
get_rot_matrix
(
enum
Rotation
rot);
141
142
/**
143
* Get the rotation quaternion
144
*/
145
__EXPORT
matrix::Quatf
146
get_rot_quaternion
(
enum
Rotation
rot);
147
148
/**
149
* rotate a 3 element float vector in-place
150
*/
151
__EXPORT
void
152
rotate_3f
(
enum
Rotation
rot,
float
&x,
float
&y,
float
&z);
153
154
155
#endif
/* ROTATION_H_ */
ROTATION_PITCH_90_ROLL_270
Definition:
rotation.h:83
rot_lookup_t::roll
uint16_t roll
Definition:
rotation.h:92
ROTATION_ROLL_90_YAW_270
Definition:
rotation.h:87
ROTATION_YAW_45
Definition:
rotation.h:53
ROTATION_ROLL_270
Definition:
rotation.h:72
ROTATION_PITCH_90_YAW_180
Definition:
rotation.h:80
ROTATION_ROLL_180_YAW_135
Definition:
rotation.h:63
ROTATION_PITCH_9_YAW_180
Definition:
rotation.h:84
ROTATION_PITCH_180
Definition:
rotation.h:64
ROTATION_YAW_180
Definition:
rotation.h:56
matrix::Dcm< float >
__EXPORT
Definition:
I2C.hpp:51
ROTATION_MAX
Definition:
rotation.h:88
ROTATION_NONE
Definition:
rotation.h:52
ROTATION_YAW_135
Definition:
rotation.h:55
ROTATION_PITCH_90_ROLL_90
Definition:
rotation.h:81
rot_lookup_t
Definition:
rotation.h:91
ROTATION_ROLL_180_YAW_45
Definition:
rotation.h:61
matrix::Quaternion
Quaternion class.
Definition:
Dcm.hpp:24
rot_lookup_t::yaw
uint16_t yaw
Definition:
rotation.h:94
ROTATION_PITCH_315
Definition:
rotation.h:86
ROTATION_ROLL_270_YAW_45
Definition:
rotation.h:73
ROTATION_PITCH_45
Definition:
rotation.h:85
math.hpp
ROTATION_YAW_270
Definition:
rotation.h:58
Rotation
Rotation
Enum for board and external compass rotations.
Definition:
rotation.h:51
ROTATION_YAW_90
Definition:
rotation.h:54
ROTATION_ROLL_90
Definition:
rotation.h:68
ROTATION_YAW_315
Definition:
rotation.h:59
ROTATION_ROLL_90_YAW_45
Definition:
rotation.h:69
ROTATION_ROLL_180_PITCH_270
Definition:
rotation.h:79
ROTATION_ROLL_180_YAW_315
Definition:
rotation.h:67
ROTATION_YAW_225
Definition:
rotation.h:57
ROTATION_ROLL_180_YAW_270
Definition:
rotation.h:66
rot_lookup_t::pitch
uint16_t pitch
Definition:
rotation.h:93
ROTATION_ROLL_90_YAW_90
Definition:
rotation.h:70
ROTATION_YAW_293_PITCH_68_ROLL_90
Definition:
rotation.h:82
ROTATION_PITCH_90
Definition:
rotation.h:76
ROTATION_PITCH_270
Definition:
rotation.h:77
ROTATION_ROLL_180
Definition:
rotation.h:60
rot_lookup
const rot_lookup_t rot_lookup[]
Definition:
rotation.h:97
ROTATION_ROLL_180_YAW_225
Definition:
rotation.h:65
get_rot_matrix
__EXPORT matrix::Dcmf get_rot_matrix(enum Rotation rot)
Get the rotation matrix.
Definition:
rotation.cpp:45
ROTATION_ROLL_270_YAW_135
Definition:
rotation.h:75
ROTATION_ROLL_270_YAW_270
Definition:
rotation.h:78
rotate_3f
__EXPORT void rotate_3f(enum Rotation rot, float &x, float &y, float &z)
rotate a 3 element float vector in-place
Definition:
rotation.cpp:63
get_rot_quaternion
__EXPORT matrix::Quatf get_rot_quaternion(enum Rotation rot)
Get the rotation quaternion.
Definition:
rotation.cpp:54
ROTATION_ROLL_180_YAW_90
Definition:
rotation.h:62
ROTATION_ROLL_270_YAW_90
Definition:
rotation.h:74
ROTATION_ROLL_90_YAW_135
Definition:
rotation.h:71
src
lib
conversion
rotation.h
Generated by
1.8.13