API Documentation
Loading...
Searching...
No Matches
MadgwikOrientationSensor.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 <mutex>
6namespace NDEVR
7{
8 namespace IMU
9 {
10 class Point;
11 }
12 class IMUCalibrator;
27 struct RasterFrame;
28 /**--------------------------------------------------------------------------------------------------
29 Class: MadgwikOrientationSensor
30
31 \brief Used to calculate madgick orientation given sensor streams for gyro and optionally magnetometer(s) and accelerometer(s)
32 \ingroup Hardware Magnetometer Orientation Gyro Accelerometer
33 *-----------------------------------------------------------------------------------------------**/
35 {
36 public:
37 MadgwikOrientationSensor(const Model& model, ProgressInfo* log, QObject* parent = nullptr);
38 bool readyToSetupFrame() const;
39 #if _WIN32
40 bool collectRecentRecords(const Time& cutoff_time, Buffer<IMU::Point, uint04, ObjectAllocator<false>>& imu_points, const Time& offset_time);
41 #endif
42 sint02 getPacketGyroState() const;
43 void reset();
44 void setGyroState(GyroState state);
45 void setPacketGyroState(sint02 state);
46 void setStoreReadings(bool store_readings);
47 bool supportsFixed() const override { return false; }
48 bool supportsRodded() const override { return false; }
49 void setRequestGyroCallback(const std::function<void()>& callback) { m_request_gyro_callback = callback; }
50 // Function to calculate the change in angle of motion based on data from gyro
51 void processGyro(Ray<3, fltp08> gyro_data, const Time& ts);
52 void processAcceleration(Ray<3, fltp08> accel_data, const Time& ts);
53 void processQuaternion(const Quaternion<fltp08>& quaternion, const Time& ts);
54 bool requestGyroCalibration() override;
55 void processMadgwick(Time time);
56 void updateFromQuaternion(Time time);
57 Vector<3, Angle<fltp08>> angleFromQuaternion(const Quaternion<fltp08>& quaternion) const;
58 Matrix<fltp08> orientationAt(const Time& time) const;
59 Angle<fltp08> angularVelocity() const;
60 void initialComputeMadgwick(Vector<3, fltp08> a, Vector<3, fltp08> m, Quaternion<fltp08>& q, Time time);
61 static void updateMadgwick(Vector<3, fltp08> g, Vector<3, fltp08> a, Vector<3, fltp08> m, Quaternion<fltp08>& q, TimeSpan time_span, fltp08 beta);
62 protected:
63 std::function<void()> m_request_gyro_callback;
67 Time m_prev_accel_timestamp = Time(0);
68 Vector<3, fltp08> m_prev_accel_data = { 0,0,0 };
69 // theta is the angle of camera rotation in x, y and z components
70 std::mutex m_theta_mtx;
71 Quaternion<fltp08> m_quaternion = Quaternion<fltp08>(1.0, 0.0, 0.0, 0.0);
75 Vector<3, fltp08> m_gyro_calibration = Vector<3, fltp08>(0.0);
77 Time m_start_calibration_time = Constant<Time>::NaN;
78 TimeSpan m_calibration_time = TimeSpan(5.0);
79 fltp08 m_beta = 0.042;
81 // Keeps the arrival time of previous gyro frame
82 Time m_last_timestamp = Constant<Time>::NaN;
84 bool m_reset_gyro = true;
85 bool m_store_readings = false;
86 uint04 m_init_count = 0;
87 };
88}
#define HARDWARE_API
Definition DLLInfo.h:74
Stores an angle in an optimized format.
Definition StringStream.h:352
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition IMUCalibrator.h:27
Used to calculate madgick orientation given sensor streams for gyro and optionally magnetometer(s) an...
Definition MadgwikOrientationSensor.h:35
bool supportsRodded() const override
Definition MadgwikOrientationSensor.h:48
Buffer< Time > v_gyro_timestamp
Definition MadgwikOrientationSensor.h:65
void setRequestGyroCallback(const std::function< void()> &callback)
Definition MadgwikOrientationSensor.h:49
Buffer< Ray< 3, fltp08 > > v_accel_data_sync
Definition MadgwikOrientationSensor.h:64
QueueBuffer< OrientationReading, uint04, ObjectAllocator< true, uint04 > > m_historic_orientation
Definition MadgwikOrientationSensor.h:83
bool supportsFixed() const override
Definition MadgwikOrientationSensor.h:47
std::mutex m_theta_mtx
Definition MadgwikOrientationSensor.h:70
Buffer< Ray< 3, fltp08 > > v_gyro_data
Definition MadgwikOrientationSensor.h:66
TimeSpan m_total_ts
Definition MadgwikOrientationSensor.h:76
std::function< void()> m_request_gyro_callback
Definition MadgwikOrientationSensor.h:63
Definition Matrix.hpp:173
Definition Model.h:54
Definition MemoryManager.h:283
Used to report the orientation of a Hardware object within 3D space.
Definition OrientationSensor.h:88
Definition ProgressInfo.hpp:43
Definition Quaternion.hpp:20
Definition QueueBuffer.hpp:7
Definition Vertex.hpp:341
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition TimeSpan.h:40
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
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:66
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
GyroState
Definition OrientationSensor.h:39
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition BaseValues.hpp:272
Definition MadgwikOrientationSensor.h:14
Vector< 3, fltp08 > accel
Definition MadgwikOrientationSensor.h:23
Vector< 3, fltp08 > magnet
Definition MadgwikOrientationSensor.h:24
OrientationReading()
Definition MadgwikOrientationSensor.h:15
Time time
Definition MadgwikOrientationSensor.h:25
Vector< 3, fltp08 > gyro
Definition MadgwikOrientationSensor.h:22
Quaternion< fltp08 > quaternion
Definition MadgwikOrientationSensor.h:21