AntiMicroX
Public Types | Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Static Protected Member Functions | Private Attributes | Static Private Attributes
Calibration Class Reference

Opens calibration window used for calibration. More...

#include <calibration.h>

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

Public Types

enum  CalibrationType {
  CAL_NONE, CAL_STICK, CAL_ACCELEROMETER, CAL_GYROSCOPE,
  CAL_TYPE_MASK = 0x0000FFFF, CAL_INDEX_MASK = 0xFFFF0000, CAL_INDEX_POS = 16
}
 

Public Slots

void saveSettings ()
 Save calibration values into the device object. More...
 
void startAccelerometerCalibration ()
 Shows user instructions for accelerometer calibration and initializes estimators. More...
 
void startAccelerometerAngleCalibration ()
 Show calibration message to the user and enable accelerometer data event handler. More...
 
void startGyroscopeCalibration ()
 Shows user instructions for gyroscope calibration and initializes estimators. More...
 
void startGyroscopeOffsetCalibration ()
 Show calibration message to the user and enable gyroscope data event handler. More...
 
void startStickOffsetCalibration ()
 Shows user instructions for stick offset calibration, initializes estimators and connects stick data event handlers. More...
 
void startStickGainCalibration ()
 Shows user instructions for stick gain calibration, initializes estimators and connects stick data event handlers. More...
 

Signals

void propertyUpdated ()
 

Public Member Functions

 Calibration (InputDevice *joystick, QDialog *parent=0)
 
 ~Calibration ()
 

Protected Slots

void closeEvent (QCloseEvent *event) override
 Ask for confirmation when the dialog is closed with unsafed changed. More...
 
void resetSettings ()
 Asks for confirmation and resets calibration values of the selected device afterwards. More...
 
void deviceSelectionChanged (int index)
 Device change event handler. Asks for confirmation if there are unsaved changes. More...
 
void onSensorOffsetData (float x, float y, float z)
 Sensor data event handler. Performs gyroscope offset and accelerometer neutral orientation estimation and stops itself if the value was found or the process timed out. More...
 
void onStickOffsetData (int x, int y)
 Stick data event handler. Performs stick offset estimation and stops itself if the value was found or the process timed out. More...
 
void onStickGainData (int x, int y)
 Stick data event handler. Performs stick gain estimation and stops itself if the value was found or the process timed out. More...
 

Protected Member Functions

void resetCalibrationValues ()
 Resets calibration values of the currently selected device and updates UI. More...
 
bool askConfirmation (QString message, bool confirmed)
 Asks the user for confirmation with a given message if the given condition is false. More...
 
void showSensorCalibrationValues (bool offsetXvalid, double offsetX, bool offsetYvalid, double offsetY, bool offsetZvalid, double offsetZ)
 Shows the sensor offset calibration values to the user. More...
 
void showStickCalibrationValues (bool offsetXvalid, double offsetX, bool gainXvalid, double gainX, bool offsetYvalid, double offsetY, bool gainYvalid, double gainY)
 Shows the stick offset and gain calibration values to the user. More...
 
void hideCalibrationData ()
 hides all calibration values and their labels. More...
 
void selectTypeIndex (unsigned int type_index)
 Prepares calibration for the selected device type. Show all used values and labels and connect buttons to the corresponding event handlers. More...
 

Static Protected Member Functions

static void stickRegression (double *offset, double *gain, double xoffset, double xmin, double xmax)
 Performs linear regression on the measurement values of one axis to determine offset and gain. More...
 

Private Attributes

Ui::Calibration * m_ui
 
CalibrationType m_type
 
unsigned int m_index
 
bool m_calibrated
 
bool m_changed
 
JoyControlStickm_stick
 
JoySensorm_sensor
 
InputDevicem_joystick
 
StatisticsEstimator m_offset [3]
 
StatisticsEstimator m_min [2]
 
StatisticsEstimator m_max [2]
 
PT1Filter m_filter [2]
 
double m_last_slope [2]
 
QDateTime m_end_time
 
QElapsedTimer m_rate_timer
 
int m_sample_count
 
int m_phase
 

Static Private Attributes

static const int CAL_MIN_SAMPLES = 10
 
static const double CAL_ACCURACY_SQ = 1e-4
 
static const double STICK_CAL_TAU = 0.045
 
static const int STICK_RATE_SAMPLES = 100
 
static const int CAL_TIMEOUT = 30
 

Detailed Description

Opens calibration window used for calibration.

Class used for calibration of joysticks, gyroscopes etc.

Member Enumeration Documentation

◆ CalibrationType

Enumerator
CAL_NONE 
CAL_STICK 
CAL_ACCELEROMETER 
CAL_GYROSCOPE 
CAL_TYPE_MASK 
CAL_INDEX_MASK 
CAL_INDEX_POS 

Constructor & Destructor Documentation

◆ Calibration()

Calibration::Calibration ( InputDevice joystick,
QDialog *  parent = 0 
)
explicit
Here is the call graph for this function:

◆ ~Calibration()

Calibration::~Calibration ( )

Member Function Documentation

◆ askConfirmation()

bool Calibration::askConfirmation ( QString  message,
bool  confirmed 
)
protected

Asks the user for confirmation with a given message if the given condition is false.

Parameters
[in]messageThe message to show.
[in]confirmedTrue, if the action is already confirmed or no confirmation is necessary.
Returns
True, if the action was confirmed. False otherwise.
Here is the caller graph for this function:

◆ closeEvent

void Calibration::closeEvent ( QCloseEvent *  event)
overrideprotectedslot

Ask for confirmation when the dialog is closed with unsafed changed.

Here is the call graph for this function:

◆ deviceSelectionChanged

void Calibration::deviceSelectionChanged ( int  index)
protectedslot

Device change event handler. Asks for confirmation if there are unsaved changes.

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

◆ hideCalibrationData()

void Calibration::hideCalibrationData ( )
protected

hides all calibration values and their labels.

Here is the caller graph for this function:

◆ onSensorOffsetData

void Calibration::onSensorOffsetData ( float  x,
float  y,
float  z 
)
protectedslot

Sensor data event handler. Performs gyroscope offset and accelerometer neutral orientation estimation and stops itself if the value was found or the process timed out.

The gyroscope is only offset calibrated since gain calibration would require an accurate turntable to apply a known rotation rate on all axes. The offset is determined by calculating the mean output value at rest.

The accelerometer calibration only rotates the coordinate system to the desired neutral orientation. Calibrating offset and gain would require an accurate fixture to align all axes parallel to gravity. The neutral angles are determined by calculating the mean output value at the desired position.

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

◆ onStickGainData

void Calibration::onStickGainData ( int  x,
int  y 
)
protectedslot

Stick data event handler. Performs stick gain estimation and stops itself if the value was found or the process timed out.

It looks for local minima and maxima outside the sticks dead zone which are used to estimate the sticks minimum and maximum position.

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

◆ onStickOffsetData

void Calibration::onStickOffsetData ( int  x,
int  y 
)
protectedslot

Stick data event handler. Performs stick offset estimation and stops itself if the value was found or the process timed out.

At the beginning, it waits for the first stick moved event and calculates the event rate for the denoise lag filter. Then it looks for local minima and maxima within the sticks dead zone which are used to estimate the sticks center position.

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

◆ propertyUpdated

void Calibration::propertyUpdated ( )
signal

◆ resetCalibrationValues()

void Calibration::resetCalibrationValues ( )
protected

Resets calibration values of the currently selected device and updates UI.

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

◆ resetSettings

void Calibration::resetSettings ( )
protectedslot

Asks for confirmation and resets calibration values of the selected device afterwards.

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

◆ saveSettings

void Calibration::saveSettings ( )
slot

Save calibration values into the device object.

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

◆ selectTypeIndex()

void Calibration::selectTypeIndex ( unsigned int  type_index)
protected

Prepares calibration for the selected device type. Show all used values and labels and connect buttons to the corresponding event handlers.

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

◆ showSensorCalibrationValues()

void Calibration::showSensorCalibrationValues ( bool  offsetXvalid,
double  offsetX,
bool  offsetYvalid,
double  offsetY,
bool  offsetZvalid,
double  offsetZ 
)
protected

Shows the sensor offset calibration values to the user.

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

◆ showStickCalibrationValues()

void Calibration::showStickCalibrationValues ( bool  offsetXvalid,
double  offsetX,
bool  gainXvalid,
double  gainX,
bool  offsetYvalid,
double  offsetY,
bool  gainYvalid,
double  gainY 
)
protected

Shows the stick offset and gain calibration values to the user.

Here is the caller graph for this function:

◆ startAccelerometerAngleCalibration

void Calibration::startAccelerometerAngleCalibration ( )
slot

Show calibration message to the user and enable accelerometer data event handler.

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

◆ startAccelerometerCalibration

void Calibration::startAccelerometerCalibration ( )
slot

Shows user instructions for accelerometer calibration and initializes estimators.

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

◆ startGyroscopeCalibration

void Calibration::startGyroscopeCalibration ( )
slot

Shows user instructions for gyroscope calibration and initializes estimators.

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

◆ startGyroscopeOffsetCalibration

void Calibration::startGyroscopeOffsetCalibration ( )
slot

Show calibration message to the user and enable gyroscope data event handler.

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

◆ startStickGainCalibration

void Calibration::startStickGainCalibration ( )
slot

Shows user instructions for stick gain calibration, initializes estimators and connects stick data event handlers.

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

◆ startStickOffsetCalibration

void Calibration::startStickOffsetCalibration ( )
slot

Shows user instructions for stick offset calibration, initializes estimators and connects stick data event handlers.

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

◆ stickRegression()

void Calibration::stickRegression ( double *  offset,
double *  gain,
double  xoffset,
double  xmin,
double  xmax 
)
staticprotected

Performs linear regression on the measurement values of one axis to determine offset and gain.

Parameters
[out]offsetThe calculated offset.
[out]gainThe calculated gain.
[in]xoffsetThe measured X value at the point (x, 0)
[in]xminThe measured X value at the point (x, AXISMIN)
[in]xmaxThe measured X value at the point (x, AXISMAX)

Since the sum (AXISMIN + 0 + AXISMAX) is 0, the calculation below could be simplified.

Here is the caller graph for this function:

Field Documentation

◆ CAL_ACCURACY_SQ

const double Calibration::CAL_ACCURACY_SQ = 1e-4
staticprivate

◆ CAL_MIN_SAMPLES

const int Calibration::CAL_MIN_SAMPLES = 10
staticprivate

◆ CAL_TIMEOUT

const int Calibration::CAL_TIMEOUT = 30
staticprivate

◆ m_calibrated

bool Calibration::m_calibrated
private

◆ m_changed

bool Calibration::m_changed
private

◆ m_end_time

QDateTime Calibration::m_end_time
private

◆ m_filter

PT1Filter Calibration::m_filter[2]
private

◆ m_index

unsigned int Calibration::m_index
private

◆ m_joystick

InputDevice* Calibration::m_joystick
private

◆ m_last_slope

double Calibration::m_last_slope[2]
private

◆ m_max

StatisticsEstimator Calibration::m_max[2]
private

◆ m_min

StatisticsEstimator Calibration::m_min[2]
private

◆ m_offset

StatisticsEstimator Calibration::m_offset[3]
private

◆ m_phase

int Calibration::m_phase
private

◆ m_rate_timer

QElapsedTimer Calibration::m_rate_timer
private

◆ m_sample_count

int Calibration::m_sample_count
private

◆ m_sensor

JoySensor* Calibration::m_sensor
private

◆ m_stick

JoyControlStick* Calibration::m_stick
private

◆ m_type

CalibrationType Calibration::m_type
private

◆ m_ui

Ui::Calibration* Calibration::m_ui
private

◆ STICK_CAL_TAU

const double Calibration::STICK_CAL_TAU = 0.045
staticprivate

◆ STICK_RATE_SAMPLES

const int Calibration::STICK_RATE_SAMPLES = 100
staticprivate

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