Firmware
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 
40 #ifndef ROTATION_H_
41 #define ROTATION_H_
42 
43 #include <unistd.h>
44 #include <mathlib/mathlib.h>
45 #include <matrix/math.hpp>
46 
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_MAX
88 };
89 
90 typedef struct {
91  uint16_t roll;
92  uint16_t pitch;
93  uint16_t yaw;
94 } rot_lookup_t;
95 
96 const rot_lookup_t rot_lookup[] = {
97  { 0, 0, 0 },
98  { 0, 0, 45 },
99  { 0, 0, 90 },
100  { 0, 0, 135 },
101  { 0, 0, 180 },
102  { 0, 0, 225 },
103  { 0, 0, 270 },
104  { 0, 0, 315 },
105  {180, 0, 0 },
106  {180, 0, 45 },
107  {180, 0, 90 },
108  {180, 0, 135 },
109  { 0, 180, 0 },
110  {180, 0, 225 },
111  {180, 0, 270 },
112  {180, 0, 315 },
113  { 90, 0, 0 },
114  { 90, 0, 45 },
115  { 90, 0, 90 },
116  { 90, 0, 135 },
117  {270, 0, 0 },
118  {270, 0, 45 },
119  {270, 0, 90 },
120  {270, 0, 135 },
121  { 0, 90, 0 },
122  { 0, 270, 0 },
123  {270, 0, 270 },
124  {180, 270, 0 },
125  { 0, 90, 180 },
126  { 90, 90, 0 },
127  { 90, 68, 293 },
128  {270, 90, 0 },
129  { 0, 9, 180 },
130  { 0, 45, 0 },
131  { 0, 315, 0 },
132 };
133 
138 __EXPORT matrix::Dcmf get_rot_matrix(enum Rotation rot);
139 
143 __EXPORT void
144 rotate_3f(enum Rotation rot, float &x, float &y, float &z);
145 
146 
147 #endif /* ROTATION_H_ */
Definition: rotation.h:90
Definition: I2C.hpp:51
Rotation
Enum for board and external compass rotations.
Definition: rotation.h:51
Common header for mathlib exports.
__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:54