API Documentation
Loading...
Searching...
No Matches
MadgwickOrientationSensor.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/OrientationSensor.h>
3#include <NDEVR/QueueBuffer.h>
4#include <NDEVR/Quaternion.h>
5#include <NDEVR/IMU.h>
6#include <mutex>
7namespace NDEVR
8{
9 class IMUCalibrator;
10 /**--------------------------------------------------------------------------------------------------
11 \brief A single reading, typically used by a MadgwickOrientationSensor consisiting of input from all
12 IMU sensors. These might be interpolated values.
13 **/
28 struct RasterFrame;
29 /**--------------------------------------------------------------------------------------------------
30 \brief Used to calculate madgick orientation given sensor streams for gyro and optionally magnetometer(s) and accelerometer(s)
31 \ingroup Hardware Magnetometer Orientation Gyro Accelerometer
32 **/
34 {
35 public:
36 MadgwickOrientationSensor(const Model& model, ProgressInfo* log, QObject* parent = nullptr);
37 bool readyToSetupFrame() const;
38 #if _WIN32
39 bool collectRecentRecords(const Time& cutoff_time, Buffer<IMU::Point, uint04, ObjectAllocator<false>>& imu_points, const Time& offset_time);
40 #endif
42 void reset();
45 void setStoreReadings(bool store_readings);
46 bool supportsFixed() const override { return false; }
47 bool supportsRodded() const override { return false; }
48 void setRequestGyroCallback(const std::function<void()>& callback) { m_request_gyro_callback = callback; }
49 // Function to calculate the change in angle of motion based on data from gyro
50 void processGyro(Ray<3, fltp08> gyro_data, const Time& ts);
51 void processAcceleration(Ray<3, fltp08> accel_data, const Time& ts);
52 void processQuaternion(const Quaternion<fltp08>& quaternion, const Time& ts);
53 bool requestGyroCalibration() override;
57 Matrix<fltp08> orientationAt(const Time& time) const;
61 protected:
62 std::function<void()> m_request_gyro_callback;
66 Time m_prev_accel_timestamp = Time(0);
67 Vector<3, fltp08> m_prev_accel_data = { 0,0,0 };
68 // theta is the angle of camera rotation in x, y and z components
69 std::mutex m_theta_mtx;
70 Quaternion<fltp08> m_quaternion = Quaternion<fltp08>(1.0, 0.0, 0.0, 0.0);
74 Vector<3, fltp08> m_gyro_calibration = Vector<3, fltp08>(0.0);
76 Time m_start_calibration_time = Constant<Time>::Invalid;
77 TimeSpan m_calibration_time = TimeSpan(5.0);
78 fltp08 m_beta = 0.042;
79 Angle<fltp08> yaw_offset = Constant<Angle<fltp08>>::Invalid;
80 // Keeps the arrival time of previous gyro frame
81 Time m_last_timestamp = Constant<Time>::Invalid;
83 bool m_reset_gyro = true;
84 bool m_store_readings = false;
85 uint04 m_init_count = 0;
86 };
87}
#define HARDWARE_API
Definition DLLInfo.h:56
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Used to calculate madgick orientation given sensor streams for gyro and optionally magnetometer(s) an...
Definition MadgwickOrientationSensor.h:34
bool supportsRodded() const override
Definition MadgwickOrientationSensor.h:47
Buffer< Time > v_gyro_timestamp
Definition MadgwickOrientationSensor.h:64
Angle< fltp08 > angularVelocity() const
void processAcceleration(Ray< 3, fltp08 > accel_data, const Time &ts)
void setRequestGyroCallback(const std::function< void()> &callback)
Definition MadgwickOrientationSensor.h:48
bool requestGyroCalibration() override
void setPacketGyroState(sint02 state)
void setGyroState(GyroState state)
Buffer< Ray< 3, fltp08 > > v_accel_data_sync
Definition MadgwickOrientationSensor.h:63
MadgwickOrientationSensor(const Model &model, ProgressInfo *log, QObject *parent=nullptr)
QueueBuffer< OrientationReading, uint04, ObjectAllocator< true, uint04 > > m_historic_orientation
Definition MadgwickOrientationSensor.h:82
void updateFromQuaternion(Time time)
bool supportsFixed() const override
Definition MadgwickOrientationSensor.h:46
static void updateMadgwick(Vector< 3, fltp08 > g, Vector< 3, fltp08 > a, Vector< 3, fltp08 > m, Quaternion< fltp08 > &q, TimeSpan time_span, fltp08 beta)
Matrix< fltp08 > orientationAt(const Time &time) const
std::mutex m_theta_mtx
Definition MadgwickOrientationSensor.h:69
Vector< 3, Angle< fltp08 > > angleFromQuaternion(const Quaternion< fltp08 > &quaternion) const
void processQuaternion(const Quaternion< fltp08 > &quaternion, const Time &ts)
Buffer< Ray< 3, fltp08 > > v_gyro_data
Definition MadgwickOrientationSensor.h:65
TimeSpan m_total_ts
Definition MadgwickOrientationSensor.h:75
void processGyro(Ray< 3, fltp08 > gyro_data, const Time &ts)
bool collectRecentRecords(const Time &cutoff_time, Buffer< IMU::Point, uint04, ObjectAllocator< false > > &imu_points, const Time &offset_time)
void initialComputeMadgwick(Vector< 3, fltp08 > a, Vector< 3, fltp08 > m, Quaternion< fltp08 > &q, Time time)
std::function< void()> m_request_gyro_callback
Definition MadgwickOrientationSensor.h:62
void setStoreReadings(bool store_readings)
Definition Matrix.hpp:176
A core class that represents a node on model heirarchy. This node may contain a Geometry or one or mo...
Definition Model.h:58
Definition MemoryManager.h:261
Used to report the orientation of a Hardware object within 3D space.
Definition OrientationSensor.h:86
A light-weight base class for Log that allows processes to update, without the need for additional in...
Definition ProgressInfo.hpp:48
https://www.3dgep.com/understanding-quaternions/
Definition Quaternion.hpp:23
Stores objects in a first-in, first out queue based Buffer with push and pop functions.
Definition QueueBuffer.hpp:10
Definition Vertex.hpp:317
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
Definition ACIColor.h:37
int16_t sint02
-Defines an alias representing a 2 byte, signed integer. -Can represent exact integer values -32767 t...
Definition BaseValues.hpp:57
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
GyroState
Used by OrientationSensor to display the current state of any available gyro.
Definition OrientationSensor.h:43
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
A single reading, typically used by a MadgwickOrientationSensor consisiting of input from all IMU sen...
Definition MadgwickOrientationSensor.h:15
Vector< 3, fltp08 > accel
Definition MadgwickOrientationSensor.h:24
Vector< 3, fltp08 > magnet
Definition MadgwickOrientationSensor.h:25
OrientationReading()
Definition MadgwickOrientationSensor.h:16
HARDWARE_API OrientationReading(Quaternion< fltp08 > quaternion, Vector< 3, fltp08 > gyro, Vector< 3, fltp08 > accel, Vector< 3, fltp08 > magnet, const Time &time)
Time time
Definition MadgwickOrientationSensor.h:26
Vector< 3, fltp08 > gyro
Definition MadgwickOrientationSensor.h:23
Quaternion< fltp08 > quaternion
Definition MadgwickOrientationSensor.h:22