AntiMicroX
Loading...
Searching...
No Matches
calibration.h
Go to the documentation of this file.
1/* antimicrox Gamepad to KB+M event mapper
2 * Copyright (C) 2020 Jagoda Górska <juliagoda.pl@protonmail.com>
3 * Copyright (C) 2022 Max Maisel <max.maisel@posteo.de>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#pragma once
19
20#include "pt1filter.h"
21#include "statisticsestimator.h"
22
23#include <QDateTime>
24#include <QDialog>
25#include <QElapsedTimer>
26
27class JoyControlStick;
28class JoySensor;
29class InputDevice;
30
31namespace Ui {
32class Calibration;
33}
34
40class Calibration : public QDialog
41{
43
44 public:
56
57 explicit Calibration(InputDevice *joystick, QDialog *parent = 0);
59
60 protected:
62 bool askConfirmation(QString message, bool confirmed);
63 void showSensorCalibrationValues(bool offsetXvalid, double offsetX, bool offsetYvalid, double offsetY, bool offsetZvalid,
64 double offsetZ);
65 void showStickCalibrationValues(bool offsetXvalid, double offsetX, bool gainXvalid, double gainX, bool offsetYvalid,
66 double offsetY, bool gainYvalid, double gainY);
68 void selectTypeIndex(unsigned int type_index);
69 static void stickRegression(double *offset, double *gain, double xoffset, double xmin, double xmax);
70
71 private:
72 Ui::Calibration *m_ui;
74 unsigned int m_index;
80
85 double m_last_slope[2];
90
91 static const int CAL_MIN_SAMPLES;
92 static const double CAL_ACCURACY_SQ;
93 static const double STICK_CAL_TAU;
94 static const int STICK_RATE_SAMPLES;
95 static const int CAL_TIMEOUT;
96
97 public slots:
98 void saveSettings();
105
106 protected slots:
107 void closeEvent(QCloseEvent *event) override;
108 void resetSettings();
109 void deviceSelectionChanged(int index);
110 void onSensorOffsetData(float x, float y, float z);
111 void onStickOffsetData(int x, int y);
112 void onStickGainData(int x, int y);
113
114 signals:
116};
Opens calibration window used for calibration.
Definition calibration.h:41
~Calibration()
Definition calibration.cpp:98
static const double CAL_ACCURACY_SQ
Definition calibration.h:92
Ui::Calibration * m_ui
Definition calibration.h:72
QElapsedTimer m_rate_timer
Definition calibration.h:87
void onStickGainData(int x, int y)
Stick data event handler. Performs stick gain estimation and stops itself if the value was found or t...
Definition calibration.cpp:539
void closeEvent(QCloseEvent *event) override
Ask for confirmation when the dialog is closed with unsafed changed.
Definition calibration.cpp:103
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.
Definition calibration.cpp:334
JoyControlStick * m_stick
Definition calibration.h:77
static const int STICK_RATE_SAMPLES
Definition calibration.h:94
void startGyroscopeCalibration()
Shows user instructions for gyroscope calibration and initializes estimators.
Definition calibration.cpp:669
static const int CAL_TIMEOUT
Definition calibration.h:95
void startAccelerometerAngleCalibration()
Show calibration message to the user and enable accelerometer data event handler.
Definition calibration.cpp:650
static const double STICK_CAL_TAU
Definition calibration.h:93
void saveSettings()
Save calibration values into the device object.
Definition calibration.cpp:596
JoySensor * m_sensor
Definition calibration.h:78
StatisticsEstimator m_offset[3]
Definition calibration.h:81
PT1Filter m_filter[2]
Definition calibration.h:84
StatisticsEstimator m_min[2]
Definition calibration.h:82
void resetSettings()
Asks for confirmation and resets calibration values of the selected device afterwards.
Definition calibration.cpp:122
int m_sample_count
Definition calibration.h:88
void onStickOffsetData(int x, int y)
Stick data event handler. Performs stick offset estimation and stops itself if the value was found or...
Definition calibration.cpp:474
static const int CAL_MIN_SAMPLES
Definition calibration.h:91
QDateTime m_end_time
Definition calibration.h:86
void startAccelerometerCalibration()
Shows user instructions for accelerometer calibration and initializes estimators.
Definition calibration.cpp:622
bool m_changed
Definition calibration.h:76
void propertyUpdated()
void onSensorOffsetData(float x, float y, float z)
Sensor data event handler. Performs gyroscope offset and accelerometer neutral orientation estimation...
Definition calibration.cpp:432
void startGyroscopeOffsetCalibration()
Show calibration message to the user and enable gyroscope data event handler.
Definition calibration.cpp:699
bool m_calibrated
Definition calibration.h:75
int m_phase
Definition calibration.h:89
void startStickOffsetCalibration()
Shows user instructions for stick offset calibration, initializes estimators and connects stick data ...
Definition calibration.cpp:717
StatisticsEstimator m_max[2]
Definition calibration.h:83
bool askConfirmation(QString message, bool confirmed)
Asks the user for confirmation with a given message if the given condition is false.
Definition calibration.cpp:377
void hideCalibrationData()
hides all calibration values and their labels.
Definition calibration.cpp:196
CalibrationType m_type
Definition calibration.h:73
unsigned int m_index
Definition calibration.h:74
void showSensorCalibrationValues(bool offsetXvalid, double offsetX, bool offsetYvalid, double offsetY, bool offsetZvalid, double offsetZ)
Shows the sensor offset calibration values to the user.
Definition calibration.cpp:146
double m_last_slope[2]
Definition calibration.h:85
void selectTypeIndex(unsigned int type_index)
Prepares calibration for the selected device type. Show all used values and labels and connect button...
Definition calibration.cpp:221
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.
Definition calibration.cpp:174
void startStickGainCalibration()
Shows user instructions for stick gain calibration, initializes estimators and connects stick data ev...
Definition calibration.cpp:754
InputDevice * m_joystick
Definition calibration.h:79
CalibrationType
Definition calibration.h:46
@ CAL_ACCELEROMETER
Definition calibration.h:49
@ CAL_INDEX_POS
Definition calibration.h:54
@ CAL_NONE
Definition calibration.h:47
@ CAL_TYPE_MASK
Definition calibration.h:52
@ CAL_GYROSCOPE
Definition calibration.h:50
@ CAL_STICK
Definition calibration.h:48
@ CAL_INDEX_MASK
Definition calibration.h:53
void deviceSelectionChanged(int index)
Device change event handler. Asks for confirmation if there are unsaved changes.
Definition calibration.cpp:403
void resetCalibrationValues()
Resets calibration values of the currently selected device and updates UI.
Definition calibration.cpp:351
Abstract class representing a hardware input device, e.g a joystick or controller.
Definition inputdevice.h:51
Represents stick of a joystick.
Definition joycontrolstick.h:38
Definition joydpadxml.h:27
Represents one sensor in a SetJoystick and its connections to other parts of the application....
Definition joysensor.h:40
Implementation of a first order lag or PT1 filter. Can be used for example to smooth noisy values a b...
Definition pt1filter.h:26
Estimates mean of a data stream using Welford's algorithm and calculates statistic properties.
Definition statisticsestimator.h:26
Definition aboutdialog.h:26