Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Fusion/FusionConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @file FusionConfig.h
* @author Seb Madgwick
* @brief Library configuration.
*/

#ifndef FUSION_CONFIG_H
#define FUSION_CONFIG_H

//------------------------------------------------------------------------------
// Definitions

/**
* @brief Uncomment this definition or add as a preprocessor definition to use
* normal square root operations.
*/
//#define FUSION_USE_NORMAL_SQRT

/**
* @brief Uncomment this definition or add as a preprocessor definition to
* disable inline functions.
*/
//#define FUSION_NO_INLINE

#endif

//------------------------------------------------------------------------------
// End of file
9 changes: 8 additions & 1 deletion Fusion/FusionInline.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
#ifndef FUSION_INLINE_H
#define FUSION_INLINE_H

//------------------------------------------------------------------------------
// Includes

#include "FusionConfig.h"

//------------------------------------------------------------------------------
// Definitions

#if defined _MSC_VER
#if defined FUSION_NO_INLINE
#define FUSION_INLINE inline
#elif defined _MSC_VER
#define FUSION_INLINE __forceinline
#elif defined __GNUC__
#define FUSION_INLINE inline __attribute__((always_inline))
Expand Down
7 changes: 1 addition & 6 deletions Fusion/FusionMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//------------------------------------------------------------------------------
// Includes

#include "FusionConfig.h"
#include "FusionInline.h"
#include <math.h>
#include <stdbool.h>
Expand Down Expand Up @@ -111,12 +112,6 @@ typedef union {
#define M_PI (3.14159265358979323846)
#endif

/**
* @brief Include this definition or add as a preprocessor definition to use
* normal square root operations.
*/
//#define FUSION_USE_NORMAL_SQRT

//------------------------------------------------------------------------------
// Inline functions - Degrees and radians conversion

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ where:

Sensors are often mounted such that their axes are not aligned with the body axes. The library provides the `FusionRemap` function to remap sensor axes to the body frame using one of the 24 possible orthogonal axis permutations defined by `FusionRemapAlignment`.

## Fast inverse square root
## Optimisations

Fusion uses [Pizer's implementation](https://pizer.wordpress.com/2008/10/12/fast-inverse-square-root/) of the [fast inverse square root](https://en.wikipedia.org/wiki/Fast_inverse_square_root) algorithm for vector and quaternion normalisation. Including the definition `FUSION_USE_NORMAL_SQRT` in [FusionMath.h](https://github.com/xioTechnologies/Fusion/blob/main/Fusion/FusionMath.h) or adding this as a preprocessor definition will use normal square root operations for all normalisation calculations. This will slow down execution speed for a small increase in accuracy. The increase in accuracy will typically be too small to observe on any practical system.
### Inline functions

The `FUSION_INLINE` macro implements either `__forceinline` or `inline __attribute__((always_inline))` to inline functions and optimise for speed at the cost of program size. This can be disabled by uncommenting the `FUSION_NO_INLINE` in [FusionConfig.h](https://github.com/xioTechnologies/Fusion/blob/main/Fusion/FusionConfig.h) or adding this as a preprocessor definition.

### Fast inverse square root

Vector and quaternion normalisation operations use [Pizer's implementation](https://pizer.wordpress.com/2008/10/12/fast-inverse-square-root/) of the [fast inverse square root](https://en.wikipedia.org/wiki/Fast_inverse_square_root) algorithm. This increases speed for devices without an FPU, at a negligible cost to accuracy. Uncommenting `FUSION_USE_NORMAL_SQRT` in [FusionConfig.h](https://github.com/xioTechnologies/Fusion/blob/main/Fusion/FusionConfig.h) or adding this as a preprocessor definition will use normal square root for all operations.