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 {
89 };
90 
91 typedef struct {
92  uint16_t roll;
93  uint16_t pitch;
94  uint16_t yaw;
95 } rot_lookup_t;
96 
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  */
140 get_rot_matrix(enum Rotation rot);
141 
142 /**
143  * Get the rotation quaternion
144  */
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_ */
uint16_t roll
Definition: rotation.h:92
Definition: I2C.hpp:51
Quaternion class.
Definition: Dcm.hpp:24
uint16_t yaw
Definition: rotation.h:94
Rotation
Enum for board and external compass rotations.
Definition: rotation.h:51
uint16_t pitch
Definition: rotation.h:93
const rot_lookup_t rot_lookup[]
Definition: rotation.h:97
__EXPORT matrix::Dcmf get_rot_matrix(enum Rotation rot)
Get the rotation matrix.
Definition: rotation.cpp:45
__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
__EXPORT matrix::Quatf get_rot_quaternion(enum Rotation rot)
Get the rotation quaternion.
Definition: rotation.cpp:54