AntiMicroX
Public Slots | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
JoyAccelerometerSensor Class Reference

Represents an accelerometer sensor. More...

#include <joyaccelerometersensor.h>

Inheritance diagram for JoyAccelerometerSensor:
[legend]
Collaboration diagram for JoyAccelerometerSensor:
[legend]

Public Slots

virtual void reset () override
 Resets internal variables back to default. More...
 
- Public Slots inherited from JoySensor
virtual void reset ()
 Resets internal variables back to default. More...
 
void setDeadZone (double value)
 Sets the dead zone of the sensor to the given value. More...
 
void setMaxZone (double value)
 Sets the maximum zone of the sensor to the given value. More...
 
void setDiagonalRange (double value)
 Set the diagonal range value for a sensor. More...
 
void setSensorDelay (unsigned int value)
 Sets the sensor input delaqy to the given value. More...
 
void setSensorName (QString tempName)
 Sets the name of this sensor. More...
 
void establishPropertyUpdatedConnection ()
 

Public Member Functions

 JoyAccelerometerSensor (double rate, int originset, SetJoystick *parent_set, QObject *parent)
 
virtual ~JoyAccelerometerSensor ()
 
virtual float getXCoordinate () const override
 Get the value for the corresponding X axis. More...
 
virtual float getYCoordinate () const override
 Get the value for the corresponding Y axis. More...
 
virtual float getZCoordinate () const override
 Get the value for the corresponding Z axis. More...
 
virtual QString sensorTypeName () const override
 Get the translated sensor type name. More...
 
virtual void getCalibration (double *offsetX, double *offsetY, double *offsetZ) const override
 Reads the calibration values of the sensor. More...
 
virtual void setCalibration (double offsetX, double offsetY, double offsetZ) override
 Sets the sensor calibration values and sets the calibration flag. More...
 
- Public Member Functions inherited from JoySensor
 JoySensor (JoySensorType type, int originset, SetJoystick *parent_set, QObject *parent)
 
virtual ~JoySensor ()
 
void joyEvent (float *values, bool ignoresets=false)
 Main sensor mapping function. When activated, it generates a "moved" QT event which updates various parts of the UI. Furthermore, it controls the sensor delay timer and calculates the current sensor direction and generates "active" and "released" QT events which enable/disable button highlights in the GUI. Finally, it calls createDeskEvent if the active/released button state has changed. More...
 
void queuePendingEvent (float *values, bool ignoresets=false)
 Queues next movement event from InputDaemon. More...
 
void activatePendingEvent ()
 Activates previously queued movement event This is called by InputDevice. More...
 
bool hasPendingEvent () const
 Checks if an event is queued. More...
 
void clearPendingEvent ()
 Clears a previously queued event. More...
 
void copyAssignments (JoySensor *dest_sensor)
 Copy slots from all sensor buttons and properties from a sensor onto another. More...
 
bool hasSlotsAssigned () const
 Check if any direction is mapped to a keyboard or mouse event. More...
 
QString getPartialName (bool forceFullFormat=false, bool displayNames=false) const
 Get the name of this sensor. More...
 
QString getSensorName () const
 Returns the sensor name. More...
 
JoySensorType getType () const
 Returns the sensor type. More...
 
JoySensorDirection getCurrentDirection () const
 Returns the current sensor direction. More...
 
double getDeadZone () const
 Get the assigned dead zone value. More...
 
double getDiagonalRange () const
 Get the assigned diagonal range value. More...
 
double getMaxZone () const
 Get the assigned max zone value. More...
 
unsigned int getSensorDelay () const
 Get the assigned input delay. More...
 
bool inDeadZone (float *values) const
 Checks if the sensor vector is currently in the dead zone. More...
 
double getDistanceFromDeadZone () const
 Get current radial distance of the sensor past the assigned dead zone. More...
 
double getDistanceFromDeadZone (double x, double y, double z) const
 Get radial distance of the sensor past the assigned dead zone based on the passed X, Y and Z axes values associated with the sensor. More...
 
double calculateXDistanceFromDeadZone () const
 Get current X distance of the sensor past the assigned dead zone. More...
 
double calculateXDistanceFromDeadZone (double x, double y, double z) const
 Get current X distance of the sensor past the assigned dead zone based on the passed X, Y and Z axes values associated with the sensor. The algorithm checks if an axis parallel line through the current sensor position intersects with the dead zone sphere and subtracts the line segment within the sphere from the distance. The resulting value is not normalized because there is no practical maximum value for a sensor as you can always move it a bit faster. More...
 
double calculateYDistanceFromDeadZone () const
 Get current Y distance of the sensor past the assigned dead zone. More...
 
double calculateYDistanceFromDeadZone (double x, double y, double z) const
 Get current Y distance of the sensor past the assigned dead zone based on the passed X, Y and Z axes values associated with the sensor. The algorithm checks if an axis parallel line through the current sensor position intersects with the dead zone sphere and subtracts the line segment within the sphere from the distance. The resulting value is not normalized because there is no practical maximum value for a sensor as you can always move it a bit faster. More...
 
double calculateZDistanceFromDeadZone () const
 Get current Z distance of the sensor past the assigned dead zone. More...
 
double calculateZDistanceFromDeadZone (double x, double y, double z) const
 Get current Z distance of the sensor past the assigned dead zone based on the passed X, Y and Z axes values associated with the sensor. The algorithm checks if an axis parallel line through the current sensor position intersects with the dead zone sphere and subtracts the line segment within the sphere from the distance. The resulting value is not normalized because there is no practical maximum value for a sensor as you can always move it a bit faster. More...
 
double calculateDistance () const
 Get the vector length of the sensor. More...
 
double calculateDistance (double x, double y, double z) const
 Get the vector length of the sensor based on the passed X, Y and Z axes values associated with the sensor. More...
 
double calculatePitch () const
 Calculate the pitch angle (in degrees) corresponding to the current position of controller. More...
 
double calculatePitch (double x, double y, double z) const
 Calculate the pitch angle (in degrees) corresponding to the current passed X, Y and Z axes values associated with the sensor. position of controller. See https://www.nxp.com/files-static/sensors/doc/app_note/AN3461.pdf for a description of the used algorithm. More...
 
double calculateRoll () const
 Calculate the roll angle (in degrees) corresponding to the current position of controller. More...
 
double calculateRoll (double x, double y, double z) const
 Calculate the roll angle (in degrees) corresponding to the current passed X, Y and Z axes values associated with the sensor. position of controller. See https://www.nxp.com/files-static/sensors/doc/app_note/AN3461.pdf for a description of the used algorithm. More...
 
double calculateDirectionalDistance (JoySensorDirection direction) const
 Used to calculate the distance value that should be used by the JoyButton in the given direction. More...
 
bool isCalibrated () const
 Check if the sensor is calibrated. More...
 
void resetCalibration ()
 Resets the calibration of the sensor back to uncalibrated state. More...
 
QHash< JoySensorDirection, JoySensorButton * > * getButtons ()
 Returns a QHash which maps the SensorDirection to the corresponding JoySensorButton. More...
 
JoySensorButtongetDirectionButton (JoySensorDirection direction)
 Get a pointer to the sensor direction button for the desired direction. More...
 
bool isDefault () const
 Checks if all sensor settings and button mappings are the their default values. This is used during XML serialization to skip unnecessary objects. More...
 
void readConfig (QXmlStreamReader *xml)
 Take a XML stream and set the sensor and direction button properties according to the values contained within the stream. More...
 
void writeConfig (QXmlStreamWriter *xml) const
 Write the status of the properties of a sensor and direction buttons to an XML stream. More...
 
SetJoystickgetParentSet () const
 Get pointer to the set that a sensor belongs to. More...
 

Protected Member Functions

virtual void populateButtons () override
 Initializes the JoySensorButton objects for this sensor. More...
 
virtual JoySensorDirection calculateSensorDirection () override
 Find the direction zone of the current sensor position. More...
 
virtual void applyCalibration () override
 Applies calibration to queued input values. More...
 
- Protected Member Functions inherited from JoySensor
void resetButtons ()
 Reset all the properties of the sensor direction buttons. More...
 
void determineSensorEvent (JoySensorButton **eventbutton) const
 Set buttons for current sensor direction zone. More...
 
void createDeskEvent (JoySensorDirection direction, bool ignoresets=false)
 Find the position of the three sensor axes, deactivate no longer used sensor direction button and then activate direction buttons for new direction. More...
 

Protected Attributes

double m_rate
 
PT1Filter m_shock_filter
 
size_t m_shock_suppress_count
 
double m_calibration_matrix [3][3]
 
- Protected Attributes inherited from JoySensor
JoySensorType m_type
 
double m_dead_zone
 
double m_diagonal_range
 
double m_max_zone
 
unsigned int m_sensor_delay
 
bool m_active
 
JoySensorButtonm_active_button [ACTIVE_BUTTON_COUNT]
 
float m_current_value [3]
 
float m_pending_value [3]
 
bool m_calibrated
 
double m_calibration_value [3]
 
bool m_pending_event
 
bool m_pending_ignore_sets
 
int m_originset
 
QString m_sensor_name
 
QTimer m_delay_timer
 
JoySensorDirection m_current_direction
 
SetJoystickm_parent_set
 
QHash< JoySensorDirection, JoySensorButton * > m_buttons
 

Static Protected Attributes

static const double SHOCK_DETECT_THRESHOLD = 20.0
 
static const double SHOCK_SUPPRESS_FACTOR = 0.5
 
static const double SHOCK_TAU = 0.05
 
- Static Protected Attributes inherited from JoySensor
static const size_t ACTIVE_BUTTON_COUNT = 3
 

Additional Inherited Members

- Signals inherited from JoySensor
void moved (float xaxis, float yaxis, float zaxis)
 
void active (float xaxis, float yaxis, float zaxis)
 
void released (float xaxis, float yaxis, float zaxis)
 
void deadZoneChanged (double value)
 
void diagonalRangeChanged (double value)
 
void maxZoneChanged (double value)
 
void sensorDelayChanged (int value)
 
void sensorNameChanged ()
 
void propertyUpdated ()
 
- Static Public Member Functions inherited from JoySensor
static double radToDeg (double value)
 Utility function which converts a given value from radians to degree. More...
 
static double degToRad (double value)
 Utility function which converts a given value from degree to radians. More...
 

Detailed Description

Represents an accelerometer sensor.

Constructor & Destructor Documentation

◆ JoyAccelerometerSensor()

JoyAccelerometerSensor::JoyAccelerometerSensor ( double  rate,
int  originset,
SetJoystick parent_set,
QObject *  parent 
)
explicit
Here is the call graph for this function:

◆ ~JoyAccelerometerSensor()

JoyAccelerometerSensor::~JoyAccelerometerSensor ( )
virtual

Member Function Documentation

◆ applyCalibration()

void JoyAccelerometerSensor::applyCalibration ( )
overrideprotectedvirtual

Applies calibration to queued input values.

This rotates the sensor coordinate system with the precalculated neutral position rotation matrix.

Implements JoySensor.

◆ calculateSensorDirection()

JoySensorDirection JoyAccelerometerSensor::calculateSensorDirection ( )
overrideprotectedvirtual

Find the direction zone of the current sensor position.

First, the pitch and roll angles on the unit sphere are calculated. Then, the unit sphere is divided into direction zones with the following algorithm:

  • Mark a spherical layer around the X axis at +/- the diagonal zone angle divided by two (called "range" in the code)
  • Generate another spherical layers by rotating the first layer around the Y axis. A third layer is not necessary because there are only two degrees of freedom. Check if a point is within each layer by comparing the absolute values of pitch and roll angles against the "range". If a point is in only one layer, it is in the orthogonal zone of one axis. If a point is in both or no zones, it is diagonal to both axes. There are two cases here because the spherical layers overlap if the diagonal angle is larger then 45 degree.

Perform shock detection by taking the first order lag filtered absolute sum of all axes from "joyEvent" and apply a threshold. Discard some samples after the shock is over to avoid spurious pitch/roll events.

Returns
JoySensorDirection bitfield for the current direction zone.

Implements JoySensor.

Here is the call graph for this function:

◆ getCalibration()

void JoyAccelerometerSensor::getCalibration ( double *  offsetX,
double *  offsetY,
double *  offsetZ 
) const
overridevirtual

Reads the calibration values of the sensor.

Parameters
[out]offsetXOffset angle around the X axis
[out]offsetYOffset angle around the Y axis
[out]offsetZOffset angle around the Z axis

Implements JoySensor.

◆ getXCoordinate()

float JoyAccelerometerSensor::getXCoordinate ( ) const
overridevirtual

Get the value for the corresponding X axis.

Returns
X axis value in m/s^2

Implements JoySensor.

◆ getYCoordinate()

float JoyAccelerometerSensor::getYCoordinate ( ) const
overridevirtual

Get the value for the corresponding Y axis.

Returns
Y axis value in m/s^2

Implements JoySensor.

◆ getZCoordinate()

float JoyAccelerometerSensor::getZCoordinate ( ) const
overridevirtual

Get the value for the corresponding Z axis.

Returns
Z axis value in m/s^2

Implements JoySensor.

◆ populateButtons()

void JoyAccelerometerSensor::populateButtons ( )
overrideprotectedvirtual

Initializes the JoySensorButton objects for this sensor.

Implements JoySensor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset

void JoyAccelerometerSensor::reset ( )
overridevirtualslot

Resets internal variables back to default.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensorTypeName()

QString JoyAccelerometerSensor::sensorTypeName ( ) const
overridevirtual

Get the translated sensor type name.

Returns
Translated sensor type name

Implements JoySensor.

◆ setCalibration()

void JoyAccelerometerSensor::setCalibration ( double  offsetX,
double  offsetY,
double  offsetZ 
)
overridevirtual

Sets the sensor calibration values and sets the calibration flag.

Parameters
[in]offsetXOffset angle around the X axis
[in]offsetYOffset angle around the Y axis
[in]offsetZOffset angle around the Z axis

This stores the orientation vector to store the calibration data later and calculates the neutral position rotation matrix from the orientation vector.

Implements JoySensor.

Field Documentation

◆ m_calibration_matrix

double JoyAccelerometerSensor::m_calibration_matrix[3][3]
protected

◆ m_rate

double JoyAccelerometerSensor::m_rate
protected

◆ m_shock_filter

PT1Filter JoyAccelerometerSensor::m_shock_filter
protected

◆ m_shock_suppress_count

size_t JoyAccelerometerSensor::m_shock_suppress_count
protected

◆ SHOCK_DETECT_THRESHOLD

const double JoyAccelerometerSensor::SHOCK_DETECT_THRESHOLD = 20.0
staticprotected

◆ SHOCK_SUPPRESS_FACTOR

const double JoyAccelerometerSensor::SHOCK_SUPPRESS_FACTOR = 0.5
staticprotected

◆ SHOCK_TAU

const double JoyAccelerometerSensor::SHOCK_TAU = 0.05
staticprotected

The documentation for this class was generated from the following files: