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 "linear_algebra.h"
5
6// ! SAE J670 Z-up convention: X+ forward, Y+ left, Z+ up
7// ! Pitch is rotation around Y, Roll is rotation around X, Yaw is rotation around Z
8
9typedef struct {
10 float roll;
11 float pitch;
12 float yaw;
14
21static inline matrix3x3_t DCM_from_euler(const euler_angles_t angles) {
22 float cos_roll = cosf(angles.roll);
23 float sin_roll = sinf(angles.roll);
24 float cos_pitch = cosf(angles.pitch);
25 float sin_pitch = sinf(angles.pitch);
26 float cos_yaw = cosf(angles.yaw);
27 float sin_yaw = sinf(angles.yaw);
28
29 // ZYX Euler sequence (Yaw -> Pitch -> Roll)
30 // R = Rz(yaw) * Ry(pitch) * Rx(roll)
31 matrix3x3_t dcm;
32 dcm.data[0][0] = cos_pitch * cos_yaw;
33 dcm.data[0][1] = cos_yaw * sin_pitch * sin_roll - cos_roll * sin_yaw;
34 dcm.data[0][2] = sin_roll * sin_yaw + cos_roll * cos_yaw * sin_pitch;
35
36 dcm.data[1][0] = cos_pitch * sin_yaw;
37 dcm.data[1][1] = cos_roll * cos_yaw + sin_roll * sin_pitch * sin_yaw;
38 dcm.data[1][2] = cos_roll * sin_pitch * sin_yaw - cos_yaw * sin_roll;
39
40 dcm.data[2][0] = -sin_pitch;
41 dcm.data[2][1] = cos_pitch * sin_roll;
42 dcm.data[2][2] = cos_pitch * cos_roll;
43
44 return dcm;
45}
46
47#endif // ORIENTATION_H
Linear algebra functions utility header.
static matrix3x3_t DCM_from_euler(const euler_angles_t angles)
Convert Euler angles to a direction cosine matrix.
Definition orientation.h:21
Definition orientation.h:9
float yaw
Definition orientation.h:12
float roll
Definition orientation.h:10
float pitch
Definition orientation.h:11
Definition linear_algebra.h:21
float data[3][3]
Definition linear_algebra.h:22