Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
pprz_orientation_conversion.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011-2012 The Paparazzi Team
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
56#ifndef PPRZ_ORIENTATION_CONVERSION_H
57#define PPRZ_ORIENTATION_CONVERSION_H
58
59#ifdef __cplusplus
60extern "C" {
61#endif
62
65
66#include "std.h"
67
68
69#define ORREP_QUAT_I 0
70#define ORREP_EULER_I 1
71#define ORREP_RMAT_I 2
72#define ORREP_QUAT_F 3
73#define ORREP_EULER_F 4
74#define ORREP_RMAT_F 5
75#define ORREP_EULER_ZXY_F 6
76
77/*
78 * @brief Struct with euler/rmat/quaternion orientation representations in BFP int and float
79 */
130
131/************* declaration of transformation functions ************/
132extern void orientationCalcQuat_i(struct OrientationReps *orientation);
133extern void orientationCalcRMat_i(struct OrientationReps *orientation);
134extern void orientationCalcEulers_i(struct OrientationReps *orientation);
135extern void orientationCalcQuat_f(struct OrientationReps *orientation);
136extern void orientationCalcRMat_f(struct OrientationReps *orientation);
137extern void orientationCalcEulers_f(struct OrientationReps *orientation);
138extern void orientationCalcEulersZxy_f(struct OrientationReps *orientation);
139
140
141/*********************** validity test functions ******************/
143static inline bool orienationCheckValid(struct OrientationReps *orientation)
144{
145 return (orientation->status);
146}
147
149static inline void orientationSetIdentity(struct OrientationReps *orientation)
150{
151 int32_quat_identity(&orientation->quat_i);
152 /* clear bits for all attitude representations and only set the new one */
153 orientation->status = (1 << ORREP_QUAT_I);
154}
155
157static inline void orientationSetQuat_i(struct OrientationReps *orientation, struct Int32Quat *quat)
158{
159 QUAT_COPY(orientation->quat_i, *quat);
160 /* clear bits for all attitude representations and only set the new one */
161 orientation->status = (1 << ORREP_QUAT_I);
162}
163
165static inline void orientationSetRMat_i(struct OrientationReps *orientation, struct Int32RMat *rmat)
166{
167 RMAT_COPY(orientation->rmat_i, *rmat);
168 /* clear bits for all attitude representations and only set the new one */
169 orientation->status = (1 << ORREP_RMAT_I);
170}
171
173static inline void orientationSetEulers_i(struct OrientationReps *orientation, struct Int32Eulers *eulers)
174{
175 EULERS_COPY(orientation->eulers_i, *eulers);
176 /* clear bits for all attitude representations and only set the new one */
177 orientation->status = (1 << ORREP_EULER_I);
178}
179
181static inline void orientationSetQuat_f(struct OrientationReps *orientation, struct FloatQuat *quat)
182{
183 QUAT_COPY(orientation->quat_f, *quat);
184 /* clear bits for all attitude representations and only set the new one */
185 orientation->status = (1 << ORREP_QUAT_F);
186}
187
189static inline void orientationSetRMat_f(struct OrientationReps *orientation, struct FloatRMat *rmat)
190{
191 RMAT_COPY(orientation->rmat_f, *rmat);
192 /* clear bits for all attitude representations and only set the new one */
193 orientation->status = (1 << ORREP_RMAT_F);
194}
195
197static inline void orientationSetEulers_f(struct OrientationReps *orientation, struct FloatEulers *eulers)
198{
199 EULERS_COPY(orientation->eulers_f, *eulers);
200 /* clear bits for all attitude representations and only set the new one */
201 orientation->status = (1 << ORREP_EULER_F);
202}
203
204
206static inline struct Int32Quat *orientationGetQuat_i(struct OrientationReps *orientation)
207{
208 if (!bit_is_set(orientation->status, ORREP_QUAT_I)) {
209 orientationCalcQuat_i(orientation);
210 }
211 return &orientation->quat_i;
212}
213
215static inline struct Int32RMat *orientationGetRMat_i(struct OrientationReps *orientation)
216{
217 if (!bit_is_set(orientation->status, ORREP_RMAT_I)) {
218 orientationCalcRMat_i(orientation);
219 }
220 return &orientation->rmat_i;
221}
222
224static inline struct Int32Eulers *orientationGetEulers_i(struct OrientationReps *orientation)
225{
226 if (!bit_is_set(orientation->status, ORREP_EULER_I)) {
227 orientationCalcEulers_i(orientation);
228 }
229 return &orientation->eulers_i;
230}
231
233static inline struct FloatQuat *orientationGetQuat_f(struct OrientationReps *orientation)
234{
235 if (!bit_is_set(orientation->status, ORREP_QUAT_F)) {
236 orientationCalcQuat_f(orientation);
237 }
238 return &orientation->quat_f;
239}
240
242static inline struct FloatRMat *orientationGetRMat_f(struct OrientationReps *orientation)
243{
244 if (!bit_is_set(orientation->status, ORREP_RMAT_F)) {
245 orientationCalcRMat_f(orientation);
246 }
247 return &orientation->rmat_f;
248}
249
251static inline struct FloatEulers *orientationGetEulers_f(struct OrientationReps *orientation)
252{
253 if (!bit_is_set(orientation->status, ORREP_EULER_F)) {
254 orientationCalcEulers_f(orientation);
255 }
256 return &orientation->eulers_f;
257}
258
260static inline struct FloatEulers *orientationGetEulersZxy_f(struct OrientationReps *orientation)
261{
262 if (!bit_is_set(orientation->status, ORREP_EULER_ZXY_F)) {
263 orientationCalcEulersZxy_f(orientation);
264 }
265 return &orientation->eulers_zxy_f;
266}
267
268#ifdef __cplusplus
269} /* extern "C" */
270#endif
271
272#endif /* PPRZ_ORIENTATION_CONVERSION_H */
euler angles
Roation quaternion.
rotation matrix
#define EULERS_COPY(_a, _b)
#define RMAT_COPY(_o, _i)
#define QUAT_COPY(_qo, _qi)
static void int32_quat_identity(struct Int32Quat *q)
initialises a quaternion to identity
euler angles
Rotation quaternion.
rotation matrix
struct FloatEulers eulers_f
Orienation in zyx euler angles.
struct Int32Quat quat_i
Orientation quaternion.
uint8_t status
Holds the status bits for all orientation representations.
struct FloatRMat rmat_f
Orientation rotation matrix.
struct Int32RMat rmat_i
Orientation rotation matrix.
struct FloatEulers eulers_zxy_f
Orientation in zxy euler angles.
struct Int32Eulers eulers_i
Orientation in zyx euler angles.
struct FloatQuat quat_f
Orientation as quaternion.
static void orientationSetIdentity(struct OrientationReps *orientation)
Set to identity orientation.
static void orientationSetRMat_f(struct OrientationReps *orientation, struct FloatRMat *rmat)
Set vehicle body attitude from rotation matrix (float).
void orientationCalcRMat_f(struct OrientationReps *orientation)
void orientationCalcQuat_f(struct OrientationReps *orientation)
static void orientationSetQuat_f(struct OrientationReps *orientation, struct FloatQuat *quat)
Set vehicle body attitude from quaternion (float).
static struct Int32Eulers * orientationGetEulers_i(struct OrientationReps *orientation)
Get vehicle body attitude euler angles (int).
#define ORREP_QUAT_I
Quaternion (BFP int)
#define ORREP_EULER_I
zyx Euler (BFP int)
#define ORREP_EULER_F
zyx Euler (float)
static bool orienationCheckValid(struct OrientationReps *orientation)
Test if orientations are valid.
static void orientationSetEulers_f(struct OrientationReps *orientation, struct FloatEulers *eulers)
Set vehicle body attitude from euler angles (float).
static struct FloatRMat * orientationGetRMat_f(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (float).
static struct FloatEulers * orientationGetEulersZxy_f(struct OrientationReps *orientation)
Get orientation as ZXY euler angles (float).
void orientationCalcEulersZxy_f(struct OrientationReps *orientation)
static void orientationSetQuat_i(struct OrientationReps *orientation, struct Int32Quat *quat)
Set vehicle body attitude from quaternion (int).
void orientationCalcEulers_f(struct OrientationReps *orientation)
void orientationCalcRMat_i(struct OrientationReps *orientation)
#define ORREP_EULER_ZXY_F
zxy Euler (float)
#define ORREP_QUAT_F
Quaternion (float)
static struct FloatQuat * orientationGetQuat_f(struct OrientationReps *orientation)
Get vehicle body attitude quaternion (float).
void orientationCalcEulers_i(struct OrientationReps *orientation)
void orientationCalcQuat_i(struct OrientationReps *orientation)
static void orientationSetEulers_i(struct OrientationReps *orientation, struct Int32Eulers *eulers)
Set vehicle body attitude from euler angles (int).
#define ORREP_RMAT_I
Rotation Matrix (BFP int)
static struct Int32Quat * orientationGetQuat_i(struct OrientationReps *orientation)
Get vehicle body attitude quaternion (int).
static void orientationSetRMat_i(struct OrientationReps *orientation, struct Int32RMat *rmat)
Set vehicle body attitude from rotation matrix (int).
static struct Int32RMat * orientationGetRMat_i(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (int).
static struct FloatEulers * orientationGetEulers_f(struct OrientationReps *orientation)
Get vehicle body attitude euler angles (float).
#define ORREP_RMAT_F
Rotation Matrix (float)
uint16_t foo
Definition main_demo5.c:58
Paparazzi floating point algebra.
Paparazzi fixed point algebra.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.