QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RemoteControlCalibrationController.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QElapsedTimer>
4#include <QtQmlIntegration/QtQmlIntegration>
5#include <QtQuick/QQuickItem>
6
8#include "QGCMAVLink.h"
9
13{
14 Q_OBJECT
15
16 Q_PROPERTY(QQuickItem* statusText MEMBER _statusText REQUIRED)
17 Q_PROPERTY(QQuickItem* cancelButton MEMBER _cancelButton REQUIRED)
18 Q_PROPERTY(QQuickItem* nextButton MEMBER _nextButton REQUIRED)
19
20 Q_PROPERTY(int minChannelCount MEMBER _chanMinimum CONSTANT)
21 Q_PROPERTY(int channelCount READ channelCount NOTIFY channelCountChanged)
22 Q_PROPERTY(int channelValueMin MEMBER _calDefaultMinValue CONSTANT)
23 Q_PROPERTY(int channelValueMax MEMBER _calDefaultMaxValue CONSTANT)
27 Q_PROPERTY(bool joystickMode READ joystickMode WRITE setJoystickMode NOTIFY joystickModeChanged REQUIRED)
28 Q_PROPERTY(bool calibrating READ calibrating NOTIFY calibratingChanged)
31
44
53
66
79
80 Q_PROPERTY(int rollDeadband READ rollDeadband NOTIFY rollDeadbandChanged)
81 Q_PROPERTY(int pitchDeadband READ pitchDeadband NOTIFY pitchDeadbandChanged)
83 Q_PROPERTY(int yawDeadband READ yawDeadband NOTIFY yawDeadbandChanged)
92
93public:
94 RemoteControlCalibrationController(QObject *parent = nullptr);
96
114
115 Q_INVOKABLE void cancelButtonClicked();
116 Q_INVOKABLE void nextButtonClicked();
117 Q_INVOKABLE void oneSidedButtonClicked();
118 virtual Q_INVOKABLE void start();
119 Q_INVOKABLE void copyTrims();
120
133 bool rollChannelMapped();
134 bool pitchChannelMapped();
143 bool yawChannelMapped();
153 bool rollChannelReversed();
163 bool yawChannelReversed();
165 int rollDeadband();
166 int pitchDeadband();
175 int yawDeadband();
176 int throttleDeadband();
177 int channelCount() const { return _chanCount; }
178 int transmitterMode() const { return _transmitterMode; }
179 QList<int> stickDisplayPositions() const { return _stickDisplayPositions; }
180 bool centeredThrottle() const { return _centeredThrottle; }
181 bool joystickMode() const { return _joystickMode; }
182 bool calibrating() const { return _calibrating; }
183 bool singleStickDisplay() const { return _singleStickDisplay; }
184 bool oneSidedButtonVisible() const;
185
186 void setTransmitterMode(int mode);
187 void setCenteredThrottle(bool centered);
188 void setJoystickMode(bool joystickMode);
189
190signals:
192 void rawChannelValueChanged(int channel, int value);
193 void rollChannelMappedChanged(bool mapped);
194 void pitchChannelMappedChanged(bool mapped);
203 void yawChannelMappedChanged(bool mapped);
206 void rollExtensionEnabledChanged(bool enabled);
225 void rollChannelReversedChanged(bool reversed);
226 void pitchChannelReversedChanged(bool reversed);
235 void yawChannelReversedChanged(bool reversed);
237 void rollDeadbandChanged(int deadband);
238 void pitchDeadbandChanged(int deadband);
247 void yawDeadbandChanged(int deadband);
248 void throttleDeadbandChanged(int deadband);
257
258public slots:
259 void _rawChannelValuesChanged(QVector<int> channelValues) { _processChannelValues(channelValues); }
260 void _clampedChannelValuesChanged(QVector<int> channelValues) { _processChannelValues(channelValues); }
261
262protected:
264 static constexpr int _chanMax = QGCMAVLink::maxRcChannels;
274
275 // These values must be provided by the super class
285
286 int _chanCount = 0;
287 static constexpr int _chanMinimum = 4;
288
291
293 QString _stickFunctionToString(StickFunction stickFunction);
296
297 virtual bool _stickFunctionEnabled(StickFunction stickFunction);
298
299private:
300 void _processChannelValues(QVector<int> channelValues);
301
302 virtual void _saveStoredCalibrationValues() = 0;
303 virtual void _readStoredCalibrationValues() = 0;
304
305 // Stick display position in calibration image
306 // horizontal - -1 indicates left, 0 indicates centered, +1 indicates right
307 // vertical - -1 indicates down, 0 indicates centered, +1 indicates up
308 struct StickDisplayPosition {
309 int horizontal;
310 int vertical;
311 };
312
313 struct BothSticksDisplayPositions {
314 StickDisplayPosition leftStick;
315 StickDisplayPosition rightStick;
316 };
317
318 enum StateMachineStepFunction {
319 StateMachineStepStickNeutral,
320 StateMachineStepThrottleUp,
321 StateMachineStepThrottleDown,
322 StateMachineStepYawRight,
323 StateMachineStepYawLeft,
324 StateMachineStepRollRight,
325 StateMachineStepRollLeft,
326 StateMachineStepPitchUp,
327 StateMachineStepPitchDown,
328 StateMachineStepPitchCenter,
329 StateMachineStepSwitchMinMax,
330 StateMachineStepExtensionHighHorz,
331 StateMachineStepExtensionHighVert,
332 StateMachineStepExtensionLowHorz,
333 StateMachineStepExtensionLowVert,
334 StateMachineStepComplete
335 };
336
337 typedef void (RemoteControlCalibrationController::*inputFn)(enum StickFunction stickFunction, int chan, int value);
338 typedef void (RemoteControlCalibrationController::*buttonFn)(void);
339 struct StateMachineEntry {
340 enum StickFunction stickFunction;
341 enum StateMachineStepFunction stepFunction;
342 inputFn channelInputFn;
343 buttonFn nextButtonFn;
344 };
345
346 const StateMachineEntry &_getStateMachineEntry(int step) const;
347 void _advanceState();
348 void _setupCurrentState();
349 void _inputCenterWaitBegin(StickFunction stickFunction, int channel, int value);
350 void _inputStickDetect(StickFunction stickFunction, int channel, int value);
351 void _inputStickMin(StickFunction stickFunction, int channel, int value);
352 void _inputCenterWait(StickFunction stickFunction, int channel, int value);
353 void _inputSwitchMinMax(StickFunction stickFunction, int channel, int value);
354 void _applyOneSidedCalibration();
355 void _saveCalibrationValues();
356 void _saveAllTrims();
357 bool _stickSettleComplete(int value);
358 void _startCalibration();
359 void _stopCalibration();
360 void _saveCurrentRawValues();
361 void _loadCalibrationUISettings();
362 void _saveCalibrationUISettings();
363 int _deadbandForFunction(StickFunction stickFunction) const;
364 void _emitDeadbandChanged(StickFunction stickFunction);
365 void _setSingleStickDisplay(bool singleStickDisplay);
366 int _adjustChannelRawValue(const ChannelInfo& info, int rawValue) const;
367 bool _isOneSidedCalibrationStep(int step) const;
368
369 int _currentStep = -1;
370 int _transmitterMode = 2;
371
373 enum rcCalStates {
374 rcCalStateChannelWait,
375 rcCalStateBegin,
376 rcCalStateIdentify,
377 rcCalStateMinMax,
378 rcCalStateCenterThrottle,
379 rcCalStateDetectInversion,
380 rcCalStateTrims,
381 rcCalStateSave
382 };
383
384 int _channelValueSave[_chanMax]{};
385 int _channelRawValue[_chanMax]{};
386
387 int _stickDetectChannel = 0;
388 int _stickDetectValue = 0;
389 bool _stickDetectSettleStarted = false;
390 QElapsedTimer _stickDetectSettleElapsed;
391
392 QQuickItem *_statusText = nullptr;
393 QQuickItem *_cancelButton = nullptr;
394 QQuickItem *_nextButton = nullptr;
395
396 QList<int> _stickDisplayPositions;
397 bool _centeredThrottle = false;
398 bool _joystickMode = false;
399 bool _calibrating = false;
400 bool _singleStickDisplay = false;
401 QMap<StateMachineStepFunction, const char*> _stepFunctionToMsgStringMap;
402 QMap<StateMachineStepFunction, QMap<int, BothSticksDisplayPositions>> _bothStickDisplayPositionThrottleCenteredMap;
403 QMap<StateMachineStepFunction, QMap<int, BothSticksDisplayPositions>> _bothStickDisplayPositionThrottleDownMap;
404
405 QList<StateMachineEntry> _stateMachine;
406
407 static constexpr int _updateInterval = 150;
408
409 static constexpr const char *_settingsGroup = "RadioCalibration";
410 static constexpr const char *_settingsKeyTransmitterMode = "TransmitterMode";
411
412 // All the valid single stick positions used in calibration stick display
413 static constexpr StickDisplayPosition _stickDisplayPositionCentered = {0, 0};
414 static constexpr StickDisplayPosition _stickDisplayPositionXCenteredYDown = {0, -1};
415 static constexpr StickDisplayPosition _stickDisplayPositionXCenteredYUp = {0, 1};
416 static constexpr StickDisplayPosition _stickDisplayPositionXLeftYCentered = {-1, 0};
417 static constexpr StickDisplayPosition _stickDisplayPositionXRightYCentered = { 1, 0};
418 static constexpr StickDisplayPosition _stickDisplayPositionXLeftYDown = {-1, -1};
419 static constexpr StickDisplayPosition _stickDisplayPositionXRightYDown = { 1, -1};
420};
Used for handling missing Facts from C++ code.
Abstract base class for calibrating RC and Joystick controller.
void pitchDeadbandChanged(int deadband)
void additionalAxis2DeadbandChanged(int deadband)
QString _stickFunctionToString(StickFunction stickFunction)
void pitchChannelReversedChanged(bool reversed)
int _calValidMinValue
Largest valid minimum channel range value.
void joystickModeChanged(bool joystickMode)
void additionalAxis4EnabledChanged(bool enabled)
void pitchExtensionDeadbandChanged(int deadband)
void rollExtensionChannelReversedChanged(bool reversed)
void channelCountChanged(int channelCount)
void rollExtensionEnabledChanged(bool enabled)
void yawDeadbandChanged(int deadband)
void throttleDeadbandChanged(int deadband)
static constexpr int _chanMinimum
Minimum numner of channels required to run.
void pitchExtensionChannelReversedChanged(bool reversed)
void additionalAxis4ChannelMappedChanged(bool mapped)
StickFunction
These identify the various controls functions. They are also used as indices into the _rgFunctioInfo ...
int _calMoveDelta
Amount of delta past center which is considered stick movement.
void singleStickDisplayChanged(bool singleStickDisplay)
void oneSidedButtonVisibleChanged(bool visible)
void additionalAxis1ChannelMappedChanged(bool mapped)
void adjustedThrottleChannelValueChanged(int rcValue)
void adjustedAdditionalAxis4ChannelValueChanged(int rcValue)
void additionalAxis5ChannelReversedChanged(bool reversed)
void _resetInternalCalibrationValues()
Resets internal calibration values to their initial state in preparation for a new calibration sequen...
void additionalAxis3DeadbandChanged(int deadband)
void additionalAxis5ChannelMappedChanged(bool mapped)
static constexpr int _chanMax
A set of information associated with a radio channel.
int _calRoughCenterDelta
Delta around center point which is considered to be roughly centered.
void rollChannelMappedChanged(bool mapped)
void additionalAxis6ChannelMappedChanged(bool mapped)
int _stickDetectSettleMSecs
Time in ms stick must be stable before detection completes.
void additionalAxis2ChannelMappedChanged(bool mapped)
void additionalAxis6DeadbandChanged(int deadband)
void rollExtensionDeadbandChanged(int deadband)
void additionalAxis1EnabledChanged(bool enabled)
void additionalAxis2ChannelReversedChanged(bool reversed)
void yawChannelReversedChanged(bool reversed)
void rollExtensionChannelMappedChanged(bool mapped)
void _clampedChannelValuesChanged(QVector< int > channelValues)
void adjustedAdditionalAxis6ChannelValueChanged(int rcValue)
void adjustedRollChannelValueChanged(int rcValue)
void rollDeadbandChanged(int deadband)
void pitchExtensionEnabledChanged(bool enabled)
void adjustedYawChannelValueChanged(int rcValue)
virtual bool _stickFunctionEnabled(StickFunction stickFunction)
Returns true if the stick function is enabled.
void adjustedAdditionalAxis2ChannelValueChanged(int rcValue)
void additionalAxis3EnabledChanged(bool enabled)
void additionalAxis4ChannelReversedChanged(bool reversed)
void additionalAxis4DeadbandChanged(int deadband)
void additionalAxis6ChannelReversedChanged(bool reversed)
void adjustedPitchChannelValueChanged(int rcValue)
int _calValidMaxValue
Smallest valid maximum channel range value.
int _calDefaultMinValue
Default value for Min if not set.
void pitchChannelMappedChanged(bool mapped)
void additionalAxis3ChannelReversedChanged(bool reversed)
int _calSettleDelta
Amount of delta which is considered no stick movement.
void additionalAxis5DeadbandChanged(int deadband)
ChannelInfo _rgChannelInfo[_chanMax]
Information associated with each rc channel.
void additionalAxis1DeadbandChanged(int deadband)
void adjustedAdditionalAxis5ChannelValueChanged(int rcValue)
void additionalAxis1ChannelReversedChanged(bool reversed)
void calibratingChanged(bool calibrating)
void adjustedAdditionalAxis3ChannelValueChanged(int rcValue)
void rawChannelValueChanged(int channel, int value)
void adjustedRollExtensionChannelValueChanged(int rcValue)
void throttleChannelMappedChanged(bool mapped)
int _rgFunctionChannelMapping[stickFunctionMax]
Maps from StickFunction to channel index. _chanMax indicates channel not set for this function.
void additionalAxis6EnabledChanged(bool enabled)
int _chanCount
Number of actual rc channels available.
void additionalAxis5EnabledChanged(bool enabled)
void rollChannelReversedChanged(bool reversed)
int _calDefaultMaxValue
Default value for Max if not set.
void centeredThrottleChanged(bool centeredThrottle)
void throttleChannelReversedChanged(bool reversed)
void _rawChannelValuesChanged(QVector< int > channelValues)
void pitchExtensionChannelMappedChanged(bool mapped)
void additionalAxis2EnabledChanged(bool enabled)
void yawChannelMappedChanged(bool mapped)
void additionalAxis3ChannelMappedChanged(bool mapped)
void adjustedPitchExtensionChannelValueChanged(int rcValue)
void adjustedAdditionalAxis1ChannelValueChanged(int rcValue)
static constexpr uint8_t maxRcChannels
int channelTrim
Trim position (usually center for sticks)
enum StickFunction stickFunction
Function mapped to this channel, stickFunctionMax for none.