Add Orientation Tracker

This commit is contained in:
Florian Märkl 2021-01-06 15:47:42 +01:00
commit 32e1539c22
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
6 changed files with 182 additions and 8 deletions

View file

@ -0,0 +1,43 @@
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
#ifndef CHIAKI_ORIENTATION_H
#define CHIAKI_ORIENTATION_H
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Quaternion orientation from accelerometer and gyroscope
* using Madgwick's algorithm.
* See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms
*/
typedef struct chiaki_orientation_t
{
float x, y, z, w;
} ChiakiOrientation;
CHIAKI_EXPORT void chiaki_orientation_init(ChiakiOrientation *orient);
CHIAKI_EXPORT void chiaki_orientation_update(ChiakiOrientation *orient, float gx, float gy, float gz, float ax, float ay, float az, float time_step_sec);
/**
* Extension of ChiakiOrientation, also tracking an absolute timestamp
*/
typedef struct chiaki_orientation_tracker_t
{
ChiakiOrientation orient;
uint32_t timestamp;
bool first_sample;
} ChiakiOrientationTracker;
CHIAKI_EXPORT void chiaki_orientation_tracker_init(ChiakiOrientationTracker *tracker);
CHIAKI_EXPORT void chiaki_orientation_tracker_update(ChiakiOrientationTracker *tracker,
float gx, float gy, float gz, float ax, float ay, float az, uint32_t timestamp_us);
#ifdef __cplusplus
}
#endif
#endif // CHIAKI_ORIENTATION_H