|
Mod Library
Sun Devil Rocketry's hardware agnostic utility library
|
: Contains math and utility functions for SDR code. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <string.h>Go to the source code of this file.
Classes | |
| struct | _QUAT |
| struct | _VECTOR_3F |
| Three-dimensional floating-point vector. More... | |
Macros | |
| #define | GRAVITY 9.8f |
| #define | IDENTITY_QUAT ((QUAT) {1.0f, 0.0f, 0.0f, 0.0f }) |
| #define | util_set_bit(orig, idx) |
| Sets a certain bit and returns the new value. | |
| #define | rad_to_deg(x) |
| Convert a value in radians to degrees. | |
| #define | deg_to_rad(x) |
| Convert a value in degrees to radians. | |
| #define | array_size(array) |
| Returns the number of elements in an array where each element is a fixed size. | |
Typedefs | |
| typedef struct _QUAT | QUAT |
| typedef struct _VECTOR_3F | VECTOR_3F |
| Three-dimensional floating-point vector. | |
Functions | |
| uint32_t | crc32 (const uint8_t *data, size_t len) |
| Computes a CRC-32 checksum over a block of data. | |
| float | clamp_float (float value, float minimum, float maximum) |
| Clamps a floating-point value between minimum and maximum bounds. | |
| QUAT | eul_to_quat (float yaw, float pitch, float roll) |
| Converts ZYX Euler angles to a quaternion. | |
| QUAT | quat_mult (QUAT a, QUAT b) |
| Hamilton product of two quaternions. | |
| float | quat_dot (QUAT a, QUAT b) |
| Provides the dot product of two quaternions. | |
| QUAT | quat_add (QUAT a, QUAT b) |
| Adds two quaternions component-wise. | |
| QUAT | quat_scale (QUAT q, float s) |
| Scales a quaternion by a scalar value. | |
| QUAT | quat_normalize (QUAT q) |
| Normalizes a quaternion to unit length. | |
| QUAT | quat_conj (QUAT q) |
| Computes the conjugate of a quaternion. | |
| QUAT | quat_rotate_world_to_body (QUAT attitude, QUAT vector_world) |
| Rotates a vector from the world frame into the body frame. | |
| QUAT | quat_rotate_body_to_world (QUAT attitude, QUAT vector_body) |
| Rotates a vector from the body frame into the world frame. | |
| bool | quat_is_finite (QUAT quaternion) |
| Determines whether every quaternion component is finite. | |
| bool | vector_is_finite (VECTOR_3F vector) |
| Determines whether every vector component is finite. | |
| float | vector_magnitude (VECTOR_3F vector) |
| Calculates the magnitude of a three-dimensional vector. | |
| bool | vector_normalize (VECTOR_3F *vector) |
| Normalizes a three-dimensional vector in place. | |
| VECTOR_3F | vector_cross (VECTOR_3F a, VECTOR_3F b) |
| Calculates the cross product of two three-dimensional vectors. | |
| VECTOR_3F | vector_add (VECTOR_3F a, VECTOR_3F b) |
| Adds two three-dimensional vectors. | |
| VECTOR_3F | vector_scale (VECTOR_3F vector, float scalar) |
| Scales a three-dimensional vector by a scalar. | |
: Contains math and utility functions for SDR code.
Copyright (c) 2025 Sun Devil Rocketry. All rights reserved.
This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is covered under the BSD-3-Clause.
https://opensource.org/license/bsd-3-clause
==============================================================================
##### Math module features #####
==============================================================================
[..]
(+) Macros for common values, conversions, and utilities
(+) CRC-32 checksum of data
(+) Quaternion operations
******************************************************************************
| #define array_size | ( | array | ) |
Returns the number of elements in an array where each element is a fixed size.
| array | The array with desired element count. |
array. | #define deg_to_rad | ( | x | ) |
Convert a value in degrees to radians.
| x | Value in degrees. |
| #define rad_to_deg | ( | x | ) |
Convert a value in radians to degrees.
| x | Value in radians. |
| #define util_set_bit | ( | orig, | |
| idx ) |
Sets a certain bit and returns the new value.
| orig | The original value. |
| idx | Index of the bit to set. |
orig with bit idx set. | float clamp_float | ( | float | value, |
| float | minimum, | ||
| float | maximum ) |
Clamps a floating-point value between minimum and maximum bounds.
| value | Value to clamp. |
| minimum | Minimum value. |
| maximum | Maximum value. |
| uint32_t crc32 | ( | const uint8_t * | data, |
| size_t | len ) |
Computes a CRC-32 checksum over a block of data.
| [in] | data | Pointer to the input data buffer. |
| [in] | len | Number of bytes in the buffer. |
| QUAT eul_to_quat | ( | float | yaw, |
| float | pitch, | ||
| float | roll ) |
Converts ZYX Euler angles to a quaternion.
| yaw | Rotation about the Z axis in radians. |
| pitch | Rotation about the Y axis in radians. |
| roll | Rotation about the X axis in radians. |
| QUAT quat_add | ( | QUAT | a, |
| QUAT | b ) |
Adds two quaternions component-wise.
| a | The first quaternion. |
| b | The second quaternion. |
| QUAT quat_conj | ( | QUAT | q | ) |
Computes the conjugate of a quaternion.
| q | The input quaternion. |
| float quat_dot | ( | QUAT | a, |
| QUAT | b ) |
Provides the dot product of two quaternions.
| a | The left-hand quaternion. |
| b | The right-hand quaternion. |
| QUAT quat_mult | ( | QUAT | a, |
| QUAT | b ) |
Hamilton product of two quaternions.
| a | The left-hand quaternion. |
| b | The right-hand quaternion. |
| QUAT quat_normalize | ( | QUAT | q | ) |
Normalizes a quaternion to unit length.
| q | The quaternion to normalize. |
Divides each component by the quaternion's norm. If the norm is zero (e.g. a zero-initialized quaternion), returns the identity quaternion (1, 0, 0, 0) to avoid a divide-by-zero. Values near but not equal to zero are divided normally and may exhibit floating-point roundoff.
| QUAT quat_rotate_body_to_world | ( | QUAT | attitude, |
| QUAT | vector_body ) |
Rotates a vector from the body frame into the world frame.
The attitude quaternion represents the body-to-world rotation:
vector_world = q * vector_body * conjugate(q)
| attitude | Body-to-world attitude quaternion. |
| vector_body | Pure quaternion containing the body-frame vector. |
| QUAT quat_rotate_world_to_body | ( | QUAT | attitude, |
| QUAT | vector_world ) |
Rotates a vector from the world frame into the body frame.
The attitude quaternion represents the body-to-world rotation:
vector_body = conjugate(q) * vector_world * q
| attitude | Body-to-world attitude quaternion. |
| vector_world | Pure quaternion containing the world-frame vector. |
| QUAT quat_scale | ( | QUAT | q, |
| float | s ) |
Scales a quaternion by a scalar value.
| q | The quaternion to scale. |
| s | The scalar factor. |
q scaled by s (q * s).