Paparazzi UAS v7.0_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
76/*
77 * @brief Struct with euler/rmat/quaternion orientation representations in BFP int and float
78 */
123
124/************* declaration of transformation functions ************/
125extern void orientationCalcQuat_i(struct OrientationReps *orientation);
126extern void orientationCalcRMat_i(struct OrientationReps *orientation);
127extern void orientationCalcEulers_i(struct OrientationReps *orientation);
128extern void orientationCalcQuat_f(struct OrientationReps *orientation);
129extern void orientationCalcRMat_f(struct OrientationReps *orientation);
130extern void orientationCalcEulers_f(struct OrientationReps *orientation);
131
132
133/*********************** validity test functions ******************/
135static inline bool orienationCheckValid(struct OrientationReps *orientation)
136{
137 return (orientation->status);
138}
139
141static inline void orientationSetIdentity(struct OrientationReps *orientation)
142{
143 int32_quat_identity(&orientation->quat_i);
144 /* clear bits for all attitude representations and only set the new one */
145 orientation->status = (1 << ORREP_QUAT_I);
146}
147
149static inline void orientationSetQuat_i(struct OrientationReps *orientation, struct Int32Quat *quat)
150{
151 QUAT_COPY(orientation->quat_i, *quat);
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 orientationSetRMat_i(struct OrientationReps *orientation, struct Int32RMat *rmat)
158{
159 RMAT_COPY(orientation->rmat_i, *rmat);
160 /* clear bits for all attitude representations and only set the new one */
161 orientation->status = (1 << ORREP_RMAT_I);
162}
163
165static inline void orientationSetEulers_i(struct OrientationReps *orientation, struct Int32Eulers *eulers)
166{
167 EULERS_COPY(orientation->eulers_i, *eulers);
168 /* clear bits for all attitude representations and only set the new one */
169 orientation->status = (1 << ORREP_EULER_I);
170}
171
173static inline void orientationSetQuat_f(struct OrientationReps *orientation, struct FloatQuat *quat)
174{
175 QUAT_COPY(orientation->quat_f, *quat);
176 /* clear bits for all attitude representations and only set the new one */
177 orientation->status = (1 << ORREP_QUAT_F);
178}
179
181static inline void orientationSetRMat_f(struct OrientationReps *orientation, struct FloatRMat *rmat)
182{
183 RMAT_COPY(orientation->rmat_f, *rmat);
184 /* clear bits for all attitude representations and only set the new one */
185 orientation->status = (1 << ORREP_RMAT_F);
186}
187
189static inline void orientationSetEulers_f(struct OrientationReps *orientation, struct FloatEulers *eulers)
190{
191 EULERS_COPY(orientation->eulers_f, *eulers);
192 /* clear bits for all attitude representations and only set the new one */
193 orientation->status = (1 << ORREP_EULER_F);
194}
195
196
198static inline struct Int32Quat *orientationGetQuat_i(struct OrientationReps *orientation)
199{
200 if (!bit_is_set(orientation->status, ORREP_QUAT_I)) {
201 orientationCalcQuat_i(orientation);
202 }
203 return &orientation->quat_i;
204}
205
207static inline struct Int32RMat *orientationGetRMat_i(struct OrientationReps *orientation)
208{
209 if (!bit_is_set(orientation->status, ORREP_RMAT_I)) {
210 orientationCalcRMat_i(orientation);
211 }
212 return &orientation->rmat_i;
213}
214
216static inline struct Int32Eulers *orientationGetEulers_i(struct OrientationReps *orientation)
217{
218 if (!bit_is_set(orientation->status, ORREP_EULER_I)) {
219 orientationCalcEulers_i(orientation);
220 }
221 return &orientation->eulers_i;
222}
223
225static inline struct FloatQuat *orientationGetQuat_f(struct OrientationReps *orientation)
226{
227 if (!bit_is_set(orientation->status, ORREP_QUAT_F)) {
228 orientationCalcQuat_f(orientation);
229 }
230 return &orientation->quat_f;
231}
232
234static inline struct FloatRMat *orientationGetRMat_f(struct OrientationReps *orientation)
235{
236 if (!bit_is_set(orientation->status, ORREP_RMAT_F)) {
237 orientationCalcRMat_f(orientation);
238 }
239 return &orientation->rmat_f;
240}
241
243static inline struct FloatEulers *orientationGetEulers_f(struct OrientationReps *orientation)
244{
245 if (!bit_is_set(orientation->status, ORREP_EULER_F)) {
246 orientationCalcEulers_f(orientation);
247 }
248 return &orientation->eulers_f;
249}
250
251#ifdef __cplusplus
252} /* extern "C" */
253#endif
254
255#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 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 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_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.