Mod Library
Sun Devil Rocketry's hardware agnostic utility library
Loading...
Searching...
No Matches
math_sdr.h
Go to the documentation of this file.
1
30
31
32/* Define to prevent recursive inclusion -------------------------------------*/
33#ifndef MATH_SDR_H
34#define MATH_SDR_H
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40
41/* Includes ------------------------------------------------------------------*/
42#include <stdbool.h>
43#include <stddef.h>
44#include <stdint.h>
45#include <string.h>
46
47
48/* Typedefs ------------------------------------------------------------------*/
49
50/* Quaternion */
51typedef struct _QUAT
52 {
53 float w, x, y, z;
54 } QUAT;
55
59typedef struct _VECTOR_3F
60 {
61 float x;
62 float y;
63 float z;
65
66/* Macros --------------------------------------------------------------------*/
67
68/* Constants */
69#define GRAVITY 9.8f
70#define IDENTITY_QUAT ((QUAT) {1.0f, 0.0f, 0.0f, 0.0f })
71
72
81#define util_set_bit( orig, idx ) ( orig | ( 1 << idx ) )
82
83
91#define rad_to_deg(x) ((x) * 57.29577951f)
92
93
101#define deg_to_rad(x) ((x) * 0.01745329252f)
102
103
114#define array_size( array ) ( sizeof( array ) / sizeof( array[0] ) )
115
116/* Function Prototypes -------------------------------------------------------*/
117
118uint32_t crc32
119 (
120 const uint8_t *data,
121 size_t len
122 );
123
124float clamp_float
125 (
126 float value,
127 float minimum,
128 float maximum
129 );
130
131/* Quaternions ---------------------------------------------------------------*/
132
133QUAT eul_to_quat
134 (
135 float yaw,
136 float pitch,
137 float roll
138 );
139
140QUAT quat_mult
141 (
142 QUAT a,
143 QUAT b
144 );
145
146float quat_dot
147 (
148 QUAT a,
149 QUAT b
150 );
151
152QUAT quat_add
153 (
154 QUAT a,
155 QUAT b
156 );
157
158QUAT quat_scale
159 (
160 QUAT q,
161 float s
162 );
163
165 (
166 QUAT q
167 );
168
169QUAT quat_conj
170 (
171 QUAT q
172 );
173
175 (
176 QUAT attitude,
177 QUAT vector_world
178 );
179
181 (
182 QUAT attitude,
183 QUAT vector_body
184 );
185
187 (
188 QUAT quaternion
189 );
190
191/* Vectors -------------------------------------------------------------------*/
192
194 (
195 VECTOR_3F vector
196 );
197
199 (
200 VECTOR_3F vector
201 );
202
204 (
205 VECTOR_3F *vector
206 );
207
209 (
210 VECTOR_3F a,
211 VECTOR_3F b
212 );
213
215 (
216 VECTOR_3F a,
217 VECTOR_3F b
218 );
219
221 (
222 VECTOR_3F vector,
223 float scalar
224 );
225
226#ifdef __cplusplus
227}
228#endif
229#endif /* MATH_SDR_H */
230
231/*******************************************************************************
232* END OF FILE *
233*******************************************************************************/
bool vector_normalize(VECTOR_3F *vector)
Normalizes a three-dimensional vector in place.
Definition math_sdr.c:403
QUAT quat_conj(QUAT q)
Computes the conjugate of a quaternion.
Definition math_sdr.c:279
QUAT eul_to_quat(float yaw, float pitch, float roll)
Converts ZYX Euler angles to a quaternion.
Definition math_sdr.c:99
bool quat_is_finite(QUAT quaternion)
Determines whether every quaternion component is finite.
Definition math_sdr.c:349
QUAT quat_rotate_body_to_world(QUAT attitude, QUAT vector_body)
Rotates a vector from the body frame into the world frame.
Definition math_sdr.c:330
uint32_t crc32(const uint8_t *data, size_t len)
Computes a CRC-32 checksum over a block of data.
Definition math_sdr.c:39
VECTOR_3F vector_scale(VECTOR_3F vector, float scalar)
Scales a three-dimensional vector by a scalar.
Definition math_sdr.c:479
QUAT quat_add(QUAT a, QUAT b)
Adds two quaternions component-wise.
Definition math_sdr.c:185
float clamp_float(float value, float minimum, float maximum)
Clamps a floating-point value between minimum and maximum bounds.
Definition math_sdr.c:63
float vector_magnitude(VECTOR_3F vector)
Calculates the magnitude of a three-dimensional vector.
Definition math_sdr.c:386
QUAT quat_mult(QUAT a, QUAT b)
Hamilton product of two quaternions.
Definition math_sdr.c:135
VECTOR_3F vector_cross(VECTOR_3F a, VECTOR_3F b)
Calculates the cross product of two three-dimensional vectors.
Definition math_sdr.c:439
QUAT quat_normalize(QUAT q)
Normalizes a quaternion to unit length.
Definition math_sdr.c:242
bool vector_is_finite(VECTOR_3F vector)
Determines whether every vector component is finite.
Definition math_sdr.c:369
VECTOR_3F vector_add(VECTOR_3F a, VECTOR_3F b)
Adds two three-dimensional vectors.
Definition math_sdr.c:459
QUAT quat_rotate_world_to_body(QUAT attitude, QUAT vector_world)
Rotates a vector from the world frame into the body frame.
Definition math_sdr.c:301
QUAT quat_scale(QUAT q, float s)
Scales a quaternion by a scalar value.
Definition math_sdr.c:211
float quat_dot(QUAT a, QUAT b)
Provides the dot product of two quaternions.
Definition math_sdr.c:163
struct _VECTOR_3F VECTOR_3F
Three-dimensional floating-point vector.
Definition math_sdr.h:52
Three-dimensional floating-point vector.
Definition math_sdr.h:60