PER Firmware
Loading...
Searching...
No Matches
orientation.h
Go to the documentation of this file.
1#ifndef ORIENTATION_H
2#define ORIENTATION_H
3
4#include <math.h>
5
7
8// ! SAE J670 Z-up convention: X+ forward, Y+ left, Z+ up
9// ! Pitch is rotation around Y, Roll is rotation around X, Yaw is rotation around Z
10
11typedef struct {
12 float roll;
13 float pitch;
14 float yaw;
16
23static inline mat3_t DCM_from_euler(const euler_angles_t angles) {
24 float cos_roll = cosf(angles.roll);
25 float sin_roll = sinf(angles.roll);
26 float cos_pitch = cosf(angles.pitch);
27 float sin_pitch = sinf(angles.pitch);
28 float cos_yaw = cosf(angles.yaw);
29 float sin_yaw = sinf(angles.yaw);
30
31 // ZYX Euler sequence (Yaw -> Pitch -> Roll)
32 // R = Rz(yaw) * Ry(pitch) * Rx(roll)
33 mat3_t dcm;
34 dcm.data[0][0] = cos_pitch * cos_yaw;
35 dcm.data[0][1] = cos_yaw * sin_pitch * sin_roll - cos_roll * sin_yaw;
36 dcm.data[0][2] = sin_roll * sin_yaw + cos_roll * cos_yaw * sin_pitch;
37
38 dcm.data[1][0] = cos_pitch * sin_yaw;
39 dcm.data[1][1] = cos_roll * cos_yaw + sin_roll * sin_pitch * sin_yaw;
40 dcm.data[1][2] = cos_roll * sin_pitch * sin_yaw - cos_yaw * sin_roll;
41
42 dcm.data[2][0] = -sin_pitch;
43 dcm.data[2][1] = cos_pitch * sin_roll;
44 dcm.data[2][2] = cos_pitch * cos_roll;
45
46 return dcm;
47}
48
49#endif // ORIENTATION_H
Basic floating point vector and matrix types and operations.
static mat3_t DCM_from_euler(const euler_angles_t angles)
Convert Euler angles to a direction cosine matrix.
Definition orientation.h:23
Definition orientation.h:11
float yaw
Definition orientation.h:14
float roll
Definition orientation.h:12
float pitch
Definition orientation.h:13
Definition linear_algebra.h:19
float data[3][3]
Definition linear_algebra.h:20