NDEVR
API Documentation
OrientationSensor.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Hardware
28File: OrientationSensor
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Device.h>
34#include <NDEVR/Matrix.h>
35#include <QObject>
36namespace NDEVR
37{
54
66
75
86 class StationModel;
87 class CalibrationData;
88 class Calibration;
89 class IMUCalibrator;
90 class DesignObjectLookup;
91
98 class HARDWARE_API OrientationSensor : public Device
99 {
100 Q_OBJECT
101 public:
106 OrientationSensor(const Model& model, LogPtr log, QObject* parent = nullptr);
109 [[nodiscard]] virtual Time getGyroAlignmentTime() const;
112 [[nodiscard]] virtual MagnetometerState magnetometerState() const { return m_magnetometer_state; };
115 [[nodiscard]] virtual GyroState gyroState() const;
118 [[nodiscard]] virtual Matrix<fltp08> lastOrientation() const;
124 [[nodiscard]] static Matrix<fltp08, 3, 3> calculateDeviation(TimeSpan time, const Vector<4, fltp08>& start, const Vector<4, fltp08>& end);
128 [[nodiscard]] static Angle<fltp08> calculateNorthFacing(const Matrix<fltp08, 3, 3>& offset_mat);
134 [[nodiscard]] static Matrix<fltp08, 3, 3> offsetCalibration(TimeSpan time_since_calibration, const Matrix<fltp08, 3, 3>& current_orientation, const Matrix<fltp08, 3, 3>& dev_matrix);
137 [[nodiscard]] virtual bool usingAccelerometer() const { return m_using_accelerometer; }
140 [[nodiscard]] virtual bool usingCompass() const { return m_using_compass; }
143 [[nodiscard]] virtual bool usingGyro() const { return m_using_gyro; }
146 [[nodiscard]] virtual bool isGyroUpdating() const { return m_is_gyro_updating; }
149 [[nodiscard]] virtual bool hasLockedYaw() const;
152 [[nodiscard]] virtual bool hasLockedRoll() const;
155 [[nodiscard]] const Vector<3, Angle<fltp08>>& driftRate() const { return m_angle_drift_rate; }
158 [[nodiscard]] Vector<3, Angle<fltp08>> driftValue() const;
167 [[nodiscard]] virtual bool isLocked() const { return m_is_locked; }
170 [[nodiscard]] virtual TranslatedString calibrationMessage() const;
175 void setUserSpecifiedOffsets(const Vector<3, Angle<fltp08>>& user_specified_offsets) { m_user_specified_offsets = user_specified_offsets; }
178 void setDeviceOffsets(Vector<3, Angle<fltp08>> device_offsets) { m_device_specified_offsets = device_offsets; }
182 virtual bool requestAccelerationBiasLimit(fltp04 bias_limit) { UNUSED(bias_limit); return false; }
186 virtual bool requestUsingAccelerometer(bool using_accelerometer);
189 virtual Ray<3, fltp08> calibratedMagnetometerVector() const { return m_magnetometer_dir; };
192 virtual Ray<3, fltp08> rawMagnetometerVector() const { return m_raw_magnetometer_vector; };
195 virtual Angle<fltp08> compassAngle() const { return Constant<Angle<fltp08>>::Invalid; };
199 virtual bool requestUsingCompass(bool using_compass);
204 virtual bool requestUsingGyro(bool using_gyro, bool reset_state);
208 virtual bool requestGyroAlignment(bool reference_previous) { UNUSED(reference_previous); return false; }
213 virtual void lockRoll(bool lock_roll, Angle<fltp08> roll = Constant<Angle<fltp08>>::Invalid, Angle<fltp08> yaw = Constant<Angle<fltp08>>::Invalid);
217 virtual void lockYaw(bool lock_yaw, Angle<fltp08> lock_heading = Constant<Angle<fltp08>>::Invalid);
220 virtual bool supportsFixed() const { return true; }
223 virtual bool supportsModes() const { return false; }
226 virtual bool supportsRodded() const { return true; }
229 virtual void setLevelingLimit(Angle<fltp08> limit);
232 virtual void setUseGyro(bool use_gyro) { m_using_gyro = use_gyro; };
234 virtual void clearLevelingLimit();
237 virtual void setLevelingRange(Angle<fltp08> limit);
239 virtual void clearLevelingRange();
251 virtual void setDriftRate(const Vector<3, Angle<fltp08>>& drift_rate);
254 virtual void setCalibrator(IMUCalibrator* imu_calibrator);
260 [[nodiscard]] Angle<fltp08> magneticHeading() const;
261#if NDEVR_CALIBRATION
266 virtual Calibration createAlignmentObject(DesignObjectLookup* lookup, bool reference_previous);
267#endif
270 virtual CalibrationData* magnetometerCalibrationObject() { return nullptr; }
273 virtual bool requestMagnetometerCalibration(bool) { return false; }
276 virtual bool requestApplyMagnetometerCalibration() { return false; }
279 virtual bool needsMagnetometerCalibration() const { return false; }
282 virtual bool hasCalibratedDrift() const { return m_has_calibrated_drift; }
293 void setFromGravityAcceleration(const Vector<3, fltp08>& acceleration_vector);
296 virtual void setFromQuaternion(const Vector<4, fltp08>& quaternion);
303 void createCalibrationOffset(const Matrix<fltp08>& map_from, const Matrix<fltp08>& map_to);
306 void setFromAngles(const Vector<3, Angle<fltp08>>& angles);
311 virtual void clearCurrentDrift();
317 [[nodiscard]] virtual Ray<3, fltp08> referenceDirection() const { return Ray<3, fltp08>(1.0, 0.0, 0.0); }
320 [[nodiscard]] virtual UUID alignmentID() const { return m_alignment_id; };
321 protected:
324 [[nodiscard]] virtual Vector<3, Angle<fltp08>> lastOrientationAngle() const;
325 signals:
330 protected:
333 Ray<3, fltp08> m_magnetometer_dir = Constant<Ray<3, fltp08>>::Invalid;
334 Ray<3, fltp08> m_acceleration_dir = Constant<Ray<3, fltp08>>::Invalid;
354 bool m_using_gyro = false;
355 bool m_using_compass = false;
357 bool m_is_gyro_updating = false;
358 bool m_is_locked = false;
362 };
363}
Stores an angle in an optimized internal format with support for efficient trigonometric operations.
Definition Angle.h:83
A core class where all Design Objects including models, materials, and geometries are stored.
Device(const Model &model, LogPtr log, QObject *parent=nullptr)
Constructs a Device from a Model with the given log and optional Qt parent.
Logic and storage for IMU calibration.
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
A core class that represents a node on model hierarchy.
Definition Model.h:292
virtual bool supportsModes() const
Returns whether this sensor supports multiple deployment modes.
bool m_using_compass
Whether the compass/magnetometer is currently in use.
virtual Ray< 3, fltp08 > calibratedMagnetometerVector() const
Returns the calibrated magnetometer direction vector.
static Angle< fltp08 > calculateNorthFacing(const Matrix< fltp08, 3, 3 > &offset_mat)
Calculates the north-facing angle from an offset calibration matrix.
IMUCalibrator * m_imu_calibrator
Pointer to the IMU calibrator, if assigned.
virtual void clearCurrentDrift()
Clears the accumulated drift compensation, resetting drift tracking.
const Vector< 3, Angle< fltp08 > > & driftRate() const
Returns the angular drift rate per minute for each axis.
virtual bool requestMagnetometerCalibration(bool)
Requests starting or stopping a magnetometer calibration procedure.
Vector< 3, Angle< fltp08 > > m_angle_drift_rate
The angular drift rate per minute for each axis.
Vector< 3, Angle< fltp08 > > driftValue() const
Returns the accumulated angular drift value based on the current drift rate and elapsed time.
Vector< 3, Angle< fltp08 > > quaternionToAngle(const Vector< 4, fltp08 > &quaternion) const
Converts a quaternion orientation to Euler angles.
Vector< 3, Angle< fltp08 > > m_tilt_angle
The current tilt angles (pitch, roll, yaw).
virtual Time getGyroAlignmentTime() const
Returns the time at which the gyroscope alignment was established.
GyroState m_gyro_state
The current state of the gyroscope.
virtual void setDriftRate(const Vector< 3, Angle< fltp08 > > &drift_rate)
Sets the angular drift rate per minute for each axis.
Angle< fltp08 > m_roll_lock
The angle at which roll is locked, if applicable.
virtual UUID alignmentID() const
Returns the unique identifier for the current alignment.
Time m_angle_drift_start_time
The time when drift tracking started.
Vector< 3, Angle< fltp08 > > deviceOffsets() const
Returns the device-specified angular offsets applied to orientation readings.
virtual bool supportsRodded() const
Returns whether this sensor supports rodded deployment mode.
void deploymentModeOptionsUpdatedSignal()
Emitted when deployment mode options have changed.
virtual MagnetometerState magnetometerState() const
Returns the current state of the magnetometer.
virtual bool usingGyro() const
Returns whether the gyroscope is currently in use.
AccelerometerState m_accelerometer_state
The current state of the accelerometer.
virtual Ray< 3, fltp08 > referenceDirection() const
Returns the reference direction used for orientation calculations.
void setFromAngles(const Vector< 3, Angle< fltp08 > > &angles)
Sets the orientation from Euler angles.
virtual void clearLevelingLimit()
Clears the leveling limit, disabling tilt-based validation.
virtual bool isLocked() const
Returns whether the orientation sensor is currently locked and not updating.
Ray< 3, fltp08 > m_magnetometer_dir
The calibrated magnetometer direction vector.
Angle< fltp08 > m_leveling_limit
The maximum tilt before leveling is invalid.
void setUserSpecifiedOffsets(const Vector< 3, Angle< fltp08 > > &user_specified_offsets)
Sets the user-specified angular offsets for orientation correction.
OrientationSensor(const Model &model, LogPtr log, QObject *parent=nullptr)
Constructs an OrientationSensor with the given model, log, and optional parent.
MagnetometerState m_magnetometer_state
The current state of the magnetometer.
virtual bool hasLockedYaw() const
Returns whether the yaw axis is currently locked to a fixed value.
virtual bool hasCalibratedDrift() const
Returns whether the drift has been calibrated.
virtual bool requestUsingCompass(bool using_compass)
Requests enabling or disabling the compass/magnetometer.
virtual bool requestUsingAccelerometer(bool using_accelerometer)
Requests enabling or disabling the accelerometer.
void magnetometerCalibrationUpdatedSignal()
Emitted when magnetometer calibration data has changed.
bool m_using_accelerometer
Whether the accelerometer is currently in use.
virtual GyroState gyroState() const
Returns the current state of the gyroscope.
virtual bool hasLockedRoll() const
Returns whether the roll axis is currently locked to a fixed value.
void calibrationChangedSignal()
Emitted when the calibration state has changed.
virtual void setLevelingLimit(Angle< fltp08 > limit)
Sets the maximum tilt angle allowed before the leveling state becomes invalid.
bool m_using_gyro
Whether the gyroscope is currently in use.
Angle< fltp08 > magneticHeading() const
Returns the current magnetic heading angle.
virtual Ray< 3, fltp08 > rawMagnetometerVector() const
Returns the raw, uncalibrated magnetometer direction vector.
Angle< fltp08 > m_leveling_range
The tilt range at which a warning is issued.
bool m_is_magnet_field_acceptable
Whether the magnetic field strength is within acceptable limits.
bool m_is_gyro_updating
Whether the gyroscope is currently receiving updates.
Angle< fltp08 > m_roll_lock_reference_yaw
The yaw reference angle used when roll is locked.
virtual void lockYaw(bool lock_yaw, Angle< fltp08 > lock_heading=Constant< Angle< fltp08 > >::Invalid)
Locks or unlocks the yaw axis to a specified heading.
virtual bool requestAccelerationBiasLimit(fltp04 bias_limit)
Requests a change to the acceleration bias limit used for filtering.
virtual CalibrationData * magnetometerCalibrationObject()
Returns the magnetometer calibration data object, if available.
Angle< fltp08 > m_magnetic_azimuth
The current magnetic azimuth heading.
virtual Matrix< fltp08 > lastOrientation() const
Returns the last known orientation as a transformation matrix.
bool m_has_calibrated_drift
Whether drift calibration has been performed.
virtual void setLevelingRange(Angle< fltp08 > limit)
Sets the tilt angle range within which a warning is reported.
void setFromGravityAcceleration(const Vector< 3, fltp08 > &acceleration_vector)
Sets the orientation from a gravity acceleration vector.
virtual bool needsMagnetometerCalibration() const
Returns whether the magnetometer currently needs calibration.
Ray< 3, fltp08 > m_raw_acceleration_vector
The raw acceleration direction vector before calibration.
bool m_gyro_calibration_requested
Whether a gyro calibration has been requested.
virtual TranslatedString calibrationMessage() const
Returns a human-readable message describing the current calibration status.
Vector< 3, Angle< fltp08 > > m_user_specified_offsets
Angular offsets specified by the user.
virtual bool usingAccelerometer() const
Returns whether the accelerometer is currently in use.
Ray< 3, fltp08 > m_raw_magnetometer_vector
The raw magnetometer direction vector before calibration.
virtual bool requestUsingGyro(bool using_gyro, bool reset_state)
Requests enabling or disabling the gyroscope, optionally resetting state.
bool m_is_locked
Whether the orientation sensor is locked.
void checkForSetMagneticDeclination()
Checks for and applies the magnetic declination setting if available.
virtual void setFromQuaternion(const Vector< 4, fltp08 > &quaternion)
Sets the orientation from a quaternion.
fltp04 m_calibration_percent
The current calibration progress as a percentage.
IMUCalibrator * calibrator() const
Returns the current IMU calibrator.
virtual void lockRoll(bool lock_roll, Angle< fltp08 > roll=Constant< Angle< fltp08 > >::Invalid, Angle< fltp08 > yaw=Constant< Angle< fltp08 > >::Invalid)
Locks or unlocks the roll axis to a specified value.
virtual bool usingCompass() const
Returns whether the compass/magnetometer is currently in use.
Angle< fltp08 > m_yaw_lock
The angle at which yaw is locked, if applicable.
virtual bool usedForLeveling() const
Returns whether this sensor is being used for leveling validation.
Matrix< fltp08 > m_calibration_offset
The calibration offset matrix applied to orientation.
virtual LevelingState levelingState() const
Returns the current leveling state based on the current tilt and configured limits.
Angle< fltp08 > levelingRange() const
Returns the configured leveling range angle for warnings.
virtual bool supportsFixed() const
Returns whether this sensor supports fixed deployment mode.
Angle< fltp08 > levelingLimit() const
Returns the configured leveling limit angle.
static Matrix< fltp08, 3, 3 > offsetCalibration(TimeSpan time_since_calibration, const Matrix< fltp08, 3, 3 > &current_orientation, const Matrix< fltp08, 3, 3 > &dev_matrix)
Applies drift compensation to an orientation using a deviation matrix over time.
void driftRateUpdatedSignal()
Emitted when the drift rate has been updated.
static Matrix< fltp08, 3, 3 > calculateDeviation(TimeSpan time, const Vector< 4, fltp08 > &start, const Vector< 4, fltp08 > &end)
Calculates the angular deviation between two quaternion orientations over a time span.
Vector< 3, Angle< fltp08 > > gravityAccelerationToAngle(const Vector< 3, fltp08 > &acceleration_vector)
Converts a gravity acceleration vector to tilt angles.
void createCalibrationOffset(const Matrix< fltp08 > &map_from, const Matrix< fltp08 > &map_to)
Creates a calibration offset by computing the transformation between two matrices.
virtual bool requestGyroAlignment(bool reference_previous)
Requests a gyro alignment operation, optionally referencing a previous alignment.
Vector< 3, Angle< fltp08 > > userSpecifiedOffsets() const
Returns the user-specified angular offsets applied to orientation readings.
virtual void setUseGyro(bool use_gyro)
Sets whether the gyroscope should be used for orientation computation.
virtual Angle< fltp08 > compassAngle() const
Returns the compass heading angle from the magnetometer.
void setCalibrationOffset(const Matrix< fltp08 > &offset)
Sets the calibration offset matrix directly.
virtual Vector< 3, Angle< fltp08 > > lastOrientationAngle() const
Returns the last known orientation as Euler angles.
fltp04 calibrationPercent() const
Returns the current calibration progress as a percentage.
virtual bool isGyroUpdating() const
Returns whether the gyroscope is currently receiving updates.
UUID m_alignment_id
Unique identifier for the current alignment.
void setDeviceOffsets(Vector< 3, Angle< fltp08 > > device_offsets)
Sets the device-specified angular offsets for orientation correction.
virtual bool requestApplyMagnetometerCalibration()
Requests applying the current magnetometer calibration results.
virtual void clearLevelingRange()
Clears the leveling range, disabling tilt warning reporting.
virtual void setCalibrator(IMUCalibrator *imu_calibrator)
Sets the IMU calibrator to use for orientation calibration.
Ray< 3, fltp08 > m_acceleration_dir
The calibrated acceleration direction vector.
Time m_alignment_time
The time when the current alignment was created.
Vector< 3, Angle< fltp08 > > m_device_specified_offsets
Angular offsets specified by the device.
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
MagnetometerState
Used by OrientationSensor to display the current state of any available magnetometer.
@ e_compass_valid
The magnetometer is present and reporting valid data.
@ e_calculating_bias
The magnetometer is currently calculating its bias offset.
@ e_no_compass
No magnetometer/compass is available on this device.
@ e_compass_invalid
The magnetometer is present but reporting invalid data.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
Definition Angle.h:398
AccelerometerState
Reports the state of an accelerometer within a OrientationSensor.
@ e_accelerometer_invalid
The accelerometer is present but reporting invalid data.
@ e_no_accelerometer
No accelerometer is available on this device.
@ e_accelerometer_valid
The accelerometer is present and reporting valid data.
LevelingState
Reports the current leveling state of the orientation sensor, indicating whether the device is within...
@ e_level_valid
The current level reading is within acceptable bounds.
@ e_not_used
Leveling is not being used by this sensor.
@ e_level_warning
The current level reading is approaching the limit threshold.
@ e_level_invalid
The current level reading is invalid or outside acceptable bounds.
GyroState
Used by OrientationSensor to display the current state of any available gyro.
@ e_disabled
The gyroscope is present but has been disabled.
@ e_validating_drift
The gyroscope is validating its drift calculation.
@ e_calculating_drift
The gyroscope is calculating its drift compensation.
@ e_no_gyro
No gyroscope is available on this device.
@ e_stabalizing_temp
The gyroscope is stabilizing its temperature before reporting.
@ e_needs_reset
The gyroscope needs to be reset before further use.
@ e_gyro_invalid
The gyroscope is present but reporting invalid data.
@ e_initializing
The gyroscope is currently initializing.
@ e_gyro_valid
The gyroscope is present and reporting valid data.
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...