8#include <QtCore/QSettings>
11QGC_LOGGING_CATEGORY(RemoteControlCalibrationControllerLog,
"RemoteControl.RemoteControlCalibrationController")
15 "* Lower the Throttle stick all the way down as shown in diagram\n"
16 "* Please ensure all motor power is disconnected AND all props are removed from the vehicle.\n"
17 "* Click Next to continue"
20 "* Center all sticks as shown in diagram.\n"
21 "* Please ensure all motor power is disconnected from the vehicle.\n"
22 "* Click Next to continue"
24static constexpr const
char *
msgThrottleUp = QT_TR_NOOP("Move the Throttle stick all the way up and hold it there...");
25static constexpr const
char *
msgThrottleDown = QT_TR_NOOP("Move the Throttle stick all the way down and leave it there...");
26static constexpr const
char *
msgYawLeft = QT_TR_NOOP("Move the Yaw stick all the way to the left and hold it there...");
27static constexpr const
char *
msgYawRight = QT_TR_NOOP("Move the Yaw stick all the way to the right and hold it there...");
28static constexpr const
char *
msgRollLeft = QT_TR_NOOP("Move the Roll stick all the way to the left and hold it there...");
29static constexpr const
char *
msgRollRight = QT_TR_NOOP("Move the Roll stick all the way to the right and hold it there...");
30static constexpr const
char *
msgPitchDown = QT_TR_NOOP("Move the Pitch stick all the way down and hold it there...");
31static constexpr const
char *
msgPitchUp = QT_TR_NOOP("Move the Pitch stick all the way up and hold it there...");
32static constexpr const
char *
msgPitchCenter = QT_TR_NOOP("Allow the Pitch stick to move back to center...");
33static constexpr const
char *
msgExtensionHigh = QT_TR_NOOP("Move the %1 Extension stick to its high value position and hold it there...");
34static constexpr const
char *
msgExtensionLow = QT_TR_NOOP("Move the %1 Extension stick to its low value position and hold it there...");
35static constexpr const
char *
msgSwitchMinMaxRC = QT_TR_NOOP("Move all the transmitter switches and/or dials back and forth to their extreme positions.");
36static constexpr const
char *
msgComplete = QT_TR_NOOP("All settings have been captured. Click Next to write the new parameters to your board.");
42 { stickFunctionMax, StateMachineStepStickNeutral, &RemoteControlCalibrationController::_inputCenterWaitBegin, &RemoteControlCalibrationController::_saveAllTrims },
43 { stickFunctionThrottle, StateMachineStepThrottleUp, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
44 { stickFunctionThrottle, StateMachineStepThrottleDown, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
45 { stickFunctionYaw, StateMachineStepYawRight, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
46 { stickFunctionYaw, StateMachineStepYawLeft, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
47 { stickFunctionRoll, StateMachineStepRollRight, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
48 { stickFunctionRoll, StateMachineStepRollLeft, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
49 { stickFunctionPitch, StateMachineStepPitchUp, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
50 { stickFunctionPitch, StateMachineStepPitchDown, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
51 { stickFunctionPitchExtension, StateMachineStepExtensionHighVert, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
52 { stickFunctionPitchExtension, StateMachineStepExtensionLowVert, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
53 { stickFunctionRollExtension, StateMachineStepExtensionHighHorz, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
54 { stickFunctionRollExtension, StateMachineStepExtensionLowHorz, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
55 { stickFunctionAux1Extension, StateMachineStepExtensionHighHorz, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
56 { stickFunctionAux1Extension, StateMachineStepExtensionLowHorz, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
57 { stickFunctionAux2Extension, StateMachineStepExtensionHighHorz, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
58 { stickFunctionAux2Extension, StateMachineStepExtensionLowHorz, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
59 { stickFunctionAux3Extension, StateMachineStepExtensionHighHorz, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
60 { stickFunctionAux3Extension, StateMachineStepExtensionLowHorz, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
61 { stickFunctionAux4Extension, StateMachineStepExtensionHighHorz, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
62 { stickFunctionAux4Extension, StateMachineStepExtensionLowHorz, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
63 { stickFunctionAux5Extension, StateMachineStepExtensionHighHorz, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
64 { stickFunctionAux5Extension, StateMachineStepExtensionLowHorz, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
65 { stickFunctionAux6Extension, StateMachineStepExtensionHighHorz, &RemoteControlCalibrationController::_inputStickDetect,
nullptr },
66 { stickFunctionAux6Extension, StateMachineStepExtensionLowHorz, &RemoteControlCalibrationController::_inputStickMin,
nullptr },
68 { stickFunctionMax, StateMachineStepSwitchMinMax, &RemoteControlCalibrationController::_inputSwitchMinMax, &RemoteControlCalibrationController::_advanceState },
69 { stickFunctionMax, StateMachineStepComplete,
nullptr, &RemoteControlCalibrationController::_saveCalibrationValues },
72 _resetInternalCalibrationValues();
73 _loadCalibrationUISettings();
75 _stickDisplayPositions = { _stickDisplayPositionCentered.horizontal, _stickDisplayPositionCentered.vertical,
76 _stickDisplayPositionCentered.horizontal, _stickDisplayPositionCentered.vertical };
78 if (_vehicle->rover()) {
79 _centeredThrottle =
true;
82 _stepFunctionToMsgStringMap = {
102 _bothStickDisplayPositionThrottleCenteredMap = {
103 { StateMachineStepStickNeutral, {
104 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
105 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
106 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
107 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
109 { StateMachineStepThrottleUp, {
110 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYUp } },
111 { 2, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionCentered } },
112 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYUp } },
113 { 4, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionCentered } },
115 { StateMachineStepThrottleDown, {
116 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYDown } },
117 { 2, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
118 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYDown } },
119 { 4, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
121 { StateMachineStepYawRight, {
122 { 1, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
123 { 2, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
124 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionXRightYCentered } },
125 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionXRightYCentered } },
127 { StateMachineStepYawLeft, {
128 { 1, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
129 { 2, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
130 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionXLeftYCentered } },
131 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionXLeftYCentered } },
133 { StateMachineStepRollRight, {
134 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionXRightYCentered } },
135 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionXRightYCentered } },
136 { 3, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
137 { 4, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
139 { StateMachineStepRollLeft, {
140 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionXLeftYCentered } },
141 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionXLeftYCentered } },
142 { 3, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
143 { 4, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
145 { StateMachineStepPitchUp, {
146 { 1, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionCentered } },
147 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYUp } },
148 { 3, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionCentered } },
149 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYUp } },
151 { StateMachineStepPitchDown, {
152 { 1, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
153 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYDown } },
154 { 3, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
155 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYDown } },
157 { StateMachineStepPitchCenter, {
158 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
159 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
160 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
161 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
163 { StateMachineStepExtensionHighHorz, {
164 { 1, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
165 { 2, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
166 { 3, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
167 { 4, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
169 { StateMachineStepExtensionHighVert, {
170 { 1, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionXCenteredYUp } },
171 { 2, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionXCenteredYUp } },
172 { 3, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionXCenteredYUp } },
173 { 4, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionXCenteredYUp } },
175 { StateMachineStepExtensionLowHorz, {
176 { 1, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
177 { 2, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
178 { 3, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
179 { 4, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
181 { StateMachineStepExtensionLowVert, {
182 { 1, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
183 { 2, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
184 { 3, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
185 { 4, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
187 { StateMachineStepSwitchMinMax, {
188 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
189 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
190 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
191 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
193 { StateMachineStepComplete, {
194 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
195 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
196 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
197 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
202 _bothStickDisplayPositionThrottleDownMap = {
203 { StateMachineStepStickNeutral, {
204 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYDown } },
205 { 2, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
206 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYDown } },
207 { 4, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
209 { StateMachineStepThrottleUp, {
210 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYUp } },
211 { 2, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionCentered } },
212 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYUp } },
213 { 4, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionCentered } },
215 { StateMachineStepThrottleDown, {
216 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYDown } },
217 { 2, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
218 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYDown } },
219 { 4, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
221 { StateMachineStepYawRight, {
222 { 1, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
223 { 2, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
224 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionXRightYCentered } },
225 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionXRightYCentered } },
227 { StateMachineStepYawLeft, {
228 { 1, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
229 { 2, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
230 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionXLeftYCentered } },
231 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionXLeftYCentered } },
233 { StateMachineStepRollRight, {
234 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionXRightYCentered } },
235 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionXRightYCentered } },
236 { 3, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
237 { 4, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
239 { StateMachineStepRollLeft, {
240 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionXLeftYCentered } },
241 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionXLeftYCentered } },
242 { 3, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
243 { 4, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
245 { StateMachineStepPitchUp, {
246 { 1, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionCentered } },
247 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYUp } },
248 { 3, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionCentered } },
249 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYUp } },
251 { StateMachineStepPitchDown, {
252 { 1, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
253 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYDown } },
254 { 3, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
255 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionXCenteredYDown } },
257 { StateMachineStepPitchCenter, {
258 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
259 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
260 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
261 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
263 { StateMachineStepExtensionHighHorz, {
264 { 1, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
265 { 2, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
266 { 3, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
267 { 4, { _stickDisplayPositionXRightYCentered, _stickDisplayPositionCentered } },
269 { StateMachineStepExtensionHighVert, {
270 { 1, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionXCenteredYUp } },
271 { 2, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionXCenteredYUp } },
272 { 3, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionXCenteredYUp } },
273 { 4, { _stickDisplayPositionXCenteredYUp, _stickDisplayPositionXCenteredYUp } },
275 { StateMachineStepExtensionLowHorz, {
276 { 1, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
277 { 2, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
278 { 3, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
279 { 4, { _stickDisplayPositionXLeftYCentered, _stickDisplayPositionCentered } },
281 { StateMachineStepExtensionLowVert, {
282 { 1, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
283 { 2, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
284 { 3, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
285 { 4, { _stickDisplayPositionXCenteredYDown, _stickDisplayPositionCentered } },
287 { StateMachineStepSwitchMinMax, {
288 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
289 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
290 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
291 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
293 { StateMachineStepComplete, {
294 { 1, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
295 { 2, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
296 { 3, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
297 { 4, { _stickDisplayPositionCentered, _stickDisplayPositionCentered } },
302RemoteControlCalibrationController::~RemoteControlCalibrationController()
304 _saveCalibrationUISettings();
309void RemoteControlCalibrationController::start()
312 _readStoredCalibrationValues();
315const RemoteControlCalibrationController::StateMachineEntry &RemoteControlCalibrationController::_getStateMachineEntry(
int step)
const
317 if (step < 0 || step >= _stateMachine.size()) {
318 qCWarning(RemoteControlCalibrationControllerLog) <<
"Bad step value" << step;
322 return _stateMachine[step];
325void RemoteControlCalibrationController::_advanceState()
328 if (_currentStep >= _stateMachine.size()) {
333 _setupCurrentState();
336void RemoteControlCalibrationController::_setupCurrentState()
338 auto state = _getStateMachineEntry(_currentStep);
342 qCDebug(RemoteControlCalibrationControllerLog) <<
"Skipping step" << _currentStep <<
"for disabled stick function" <<
_stickFunctionToString(state.stickFunction);
348 if (_joystickMode && state.stepFunction == StateMachineStepSwitchMinMax) {
355 BothSticksDisplayPositions defaultPositions = { _stickDisplayPositionCentered, _stickDisplayPositionCentered };
356 BothSticksDisplayPositions bothStickPositions = _centeredThrottle
357 ? _bothStickDisplayPositionThrottleCenteredMap.value(state.stepFunction).value(_transmitterMode, defaultPositions)
358 : _bothStickDisplayPositionThrottleDownMap.value(state.stepFunction).value(_transmitterMode, defaultPositions);
360 QString msg = _stepFunctionToMsgStringMap.value(state.stepFunction, QString());
361 if (state.stepFunction == StateMachineStepExtensionHighHorz || state.stepFunction == StateMachineStepExtensionHighVert ||
362 state.stepFunction == StateMachineStepExtensionLowHorz || state.stepFunction == StateMachineStepExtensionLowVert) {
363 static const QMap <StickFunction, QString> extensionNameMap = {
364 { stickFunctionPitchExtension, QT_TR_NOOP(
"Pitch") },
365 { stickFunctionRollExtension, QT_TR_NOOP(
"Roll") },
366 { stickFunctionAux1Extension, QT_TR_NOOP(
"Aux 1") },
367 { stickFunctionAux2Extension, QT_TR_NOOP(
"Aux 2") },
368 { stickFunctionAux3Extension, QT_TR_NOOP(
"Aux 3") },
369 { stickFunctionAux4Extension, QT_TR_NOOP(
"Aux 4") },
370 { stickFunctionAux5Extension, QT_TR_NOOP(
"Aux 5") },
371 { stickFunctionAux6Extension, QT_TR_NOOP(
"Aux 6") },
373 msg = msg.arg(extensionNameMap.value(state.stickFunction, QT_TR_NOOP(
"Unknown")));
376 _setSingleStickDisplay(state.stepFunction == StateMachineStepExtensionHighHorz || state.stepFunction == StateMachineStepExtensionHighVert ||
377 state.stepFunction == StateMachineStepExtensionLowHorz || state.stepFunction == StateMachineStepExtensionLowVert);
379 _statusText->setProperty(
"text", msg);
380 _stickDisplayPositions = { bothStickPositions.leftStick.horizontal, bothStickPositions.leftStick.vertical,
381 bothStickPositions.rightStick.horizontal, bothStickPositions.rightStick.vertical };
385 _stickDetectSettleStarted =
false;
387 _saveCurrentRawValues();
389 _nextButton->setEnabled(state.nextButtonFn !=
nullptr);
394 auto channelCount = channelValues.size();
396 qCWarning(RemoteControlCalibrationControllerLog) <<
"Too many channels:" << channelCount <<
", max is" <<
_chanMax;
400 qCDebug(RemoteControlCalibrationControllerVerboseLog) <<
"channelValues" << channelValues;
402 for (
int channel=0; channel<channelCount; channel++) {
403 const int channelValue = channelValues[channel];
405 const int adjustedValue = _adjustChannelRawValue(channelInfo, channelValue);
407 _channelRawValue[channel] = channelValue;
413 case stickFunctionRoll:
416 case stickFunctionPitch:
419 case stickFunctionYaw:
422 case stickFunctionThrottle:
425 case stickFunctionRollExtension:
428 case stickFunctionPitchExtension:
431 case stickFunctionAux1Extension:
434 case stickFunctionAux2Extension:
437 case stickFunctionAux3Extension:
440 case stickFunctionAux4Extension:
443 case stickFunctionAux5Extension:
446 case stickFunctionAux6Extension:
454 if (_currentStep == -1) {
460 auto state = _getStateMachineEntry(_currentStep);
461 if (state.channelInputFn) {
462 (this->*state.channelInputFn)(state.stickFunction, channel, channelValue);
468void RemoteControlCalibrationController::nextButtonClicked()
470 if (_currentStep == -1) {
473 qgcApp()->showAppMessage(QStringLiteral(
"Detected %1 channels. To operate vehicle, you need at least %2 channels.").arg(
_chanCount).arg(
_chanMinimum));
478 auto state = _getStateMachineEntry(_currentStep);
479 if (state.nextButtonFn) {
480 (this->*state.nextButtonFn)();
485void RemoteControlCalibrationController::cancelButtonClicked()
490void RemoteControlCalibrationController::_saveAllTrims()
498 qCDebug(RemoteControlCalibrationControllerLog) <<
"_saveAllTrims channel:trim" << i << _channelRawValue[i];
504void RemoteControlCalibrationController::_inputCenterWaitBegin(StickFunction ,
int channel,
int value)
508 int newDeadband = abs(value) * 1.1;
511 qCDebug(RemoteControlCalibrationControllerLog) <<
"Channel:" << channel <<
"Deadband:" <<
_rgChannelInfo[channel].
deadband;
513 if (stickFunction != stickFunctionMax) {
514 _emitDeadbandChanged(stickFunction);
519 _nextButton->setEnabled(
true);
522bool RemoteControlCalibrationController::_stickSettleComplete(
int value)
529 qCDebug(RemoteControlCalibrationControllerLog) <<
"Still moving, _stickDetectValue:value" << _stickDetectValue << value;
531 _stickDetectValue = value;
532 _stickDetectSettleStarted =
false;
536 if (_stickDetectSettleStarted) {
546 qCDebug(RemoteControlCalibrationControllerLog) <<
"Starting settle timer, _stickDetectValue:value" << _stickDetectValue << value;
548 _stickDetectSettleStarted =
true;
549 _stickDetectSettleElapsed.start();
556void RemoteControlCalibrationController::_inputStickDetect(StickFunction stickFunction,
int channel,
int value)
563 qCDebug(RemoteControlCalibrationControllerVerboseLog) <<
"_inputStickDetect function:channel:value" <<
_stickFunctionToString(stickFunction) << channel << value;
565 if (_stickDetectChannel ==
_chanMax) {
571 if (abs(_channelValueSave[channel] - value) >
_calMoveDelta) {
574 qCDebug(RemoteControlCalibrationControllerLog) <<
"Starting settle wait - function:channel" <<
_stickFunctionToString(stickFunction) << channel;
577 _stickDetectChannel = channel;
578 _stickDetectValue = value;
580 }
else if (channel == _stickDetectChannel) {
581 if (_stickSettleComplete(value)) {
589 info->channelReversed = value < _channelValueSave[channel];
590 if (info->channelReversed) {
596 qCDebug(RemoteControlCalibrationControllerLog) <<
"Stick detected - function:channel:reversed:" <<
_stickFunctionToString(stickFunction) << channel << info->channelReversed;
605void RemoteControlCalibrationController::_inputStickMin(StickFunction stickFunction,
int channel,
int value)
612 qCDebug(RemoteControlCalibrationControllerVerboseLog) <<
"_inputStickMin function:channel:value" <<
_stickFunctionToString(stickFunction) << channel << value;
614 if (_stickDetectChannel ==
_chanMax) {
617 qCDebug(RemoteControlCalibrationControllerLog) <<
"Movement detected, starting settle wait";
618 _stickDetectChannel = channel;
619 _stickDetectValue = value;
623 qCDebug(RemoteControlCalibrationControllerLog) <<
"Movement detected, starting settle wait";
624 _stickDetectChannel = channel;
625 _stickDetectValue = value;
630 if (_stickSettleComplete(value)) {
634 if (channelInfo.channelReversed) {
637 channelInfo.channelMin = value;
641 if (!_joystickMode && stickFunction == stickFunctionThrottle) {
642 channelInfo.channelTrim = value;
645 qCDebug(RemoteControlCalibrationControllerLog) <<
"Settle complete - function:channel:min:max:trim" <<
_stickFunctionToString(stickFunction) << channel << channelInfo.channelMin << channelInfo.channelMax << channelInfo.channelTrim;
652void RemoteControlCalibrationController::_inputCenterWait(StickFunction stickFunction,
int channel,
int value)
659 qCDebug(RemoteControlCalibrationControllerLog) <<
"_inputCenterWait function:channel:value" <<
_stickFunctionToString(stickFunction) << channel << value;
660 if (_stickDetectChannel ==
_chanMax) {
665 qCDebug(RemoteControlCalibrationControllerLog) <<
"_inputCenterWait Center detected. Waiting for settle.";
666 _stickDetectChannel = channel;
667 _stickDetectValue = value;
670 if (_stickSettleComplete(value)) {
676void RemoteControlCalibrationController::_inputSwitchMinMax(StickFunction ,
int channel,
int value)
686 const int minValue = qMin(
_rgChannelInfo[channel].channelMin, value);
688 qCDebug(RemoteControlCalibrationControllerLog) <<
"setting min channel:min" << channel << minValue;
694 qCDebug(RemoteControlCalibrationControllerLog) <<
"setting max channel:max" << channel << maxValue;
704 for (
int i = 0; i <
_chanMax; i++) {
715 for (
size_t i = 0; i < stickFunctionMax; i++) {
724 for (
int chan = 0; chan<
_chanMax; chan++) {
731 qCDebug(RemoteControlCalibrationControllerLog) <<
"resetting channel invalid min/max - chan:channelMin:calValidMinValue:channelMax:calValidMaxValue"
735 channelInfo.channelTrim = channelInfo.channelMin + ((channelInfo.channelMax - channelInfo.channelMin) / 2);
737 switch (channelInfo.stickFunction) {
738 case stickFunctionThrottle:
739 case stickFunctionYaw:
740 case stickFunctionRoll:
741 case stickFunctionPitch:
743 channelInfo.channelTrim = std::clamp(channelInfo.channelTrim, channelInfo.channelMin, channelInfo.channelMax);
747 channelInfo.channelTrim = channelInfo.channelMin + ((channelInfo.channelMax - channelInfo.channelMin) / 2);
754 qCDebug(RemoteControlCalibrationControllerLog) <<
"resetting unavailable channel" << chan;
757 channelInfo.channelTrim = channelInfo.channelMin + ((channelInfo.channelMax - channelInfo.channelMin) / 2);
758 channelInfo.channelReversed =
false;
759 channelInfo.deadband = 0;
760 channelInfo.stickFunction = stickFunctionMax;
766void RemoteControlCalibrationController::_startCalibration()
769 qCWarning(RemoteControlCalibrationControllerLog) <<
"Call to RemoteControlCalibrationController::_startCalibration with _chanCount < _chanMinimum";
780 _nextButton->setProperty(
"text", tr(
"Next"));
781 _cancelButton->setEnabled(
true);
784 _setupCurrentState();
787void RemoteControlCalibrationController::_setSingleStickDisplay(
bool singleStickDisplay)
789 if (_singleStickDisplay != singleStickDisplay) {
790 _singleStickDisplay = singleStickDisplay;
795void RemoteControlCalibrationController::_stopCalibration()
800 _readStoredCalibrationValues();
804 _calibrating =
false;
809 _statusText->setProperty(
"text",
"");
812 _nextButton->setProperty(
"text", tr(
"Calibrate"));
815 _nextButton->setEnabled(
true);
818 _cancelButton->setEnabled(
false);
821 _stickDisplayPositions = { _stickDisplayPositionCentered.horizontal, _stickDisplayPositionCentered.vertical,
822 _stickDisplayPositionCentered.horizontal, _stickDisplayPositionCentered.vertical };
826void RemoteControlCalibrationController::_saveCurrentRawValues()
828 for (
int i = 0; i <
_chanMax; i++) {
829 _channelValueSave[i] = _channelRawValue[i];
830 qCDebug(RemoteControlCalibrationControllerVerboseLog) <<
"_saveCurrentRawValues channel:value" << i << _channelValueSave[i];
835int RemoteControlCalibrationController::_adjustChannelRawValue(
const ChannelInfo& info,
int rawValue)
const
837 if (!info.channelReversed) {
841 const int invertedValue = info.channelMin + info.channelMax - rawValue;
842 return std::clamp(invertedValue, info.channelMin, info.channelMax);
845void RemoteControlCalibrationController::_loadCalibrationUISettings()
849 settings.beginGroup(_settingsGroup);
850 _transmitterMode = settings.value(_settingsKeyTransmitterMode, 2).toInt();
853 if (_transmitterMode < 1 || _transmitterMode > 4) {
854 _transmitterMode = 2;
858void RemoteControlCalibrationController::_saveCalibrationUISettings()
862 settings.beginGroup(_settingsGroup);
863 settings.setValue(_settingsKeyTransmitterMode, _transmitterMode);
867int RemoteControlCalibrationController::adjustedRollChannelValue()
871 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
877int RemoteControlCalibrationController::adjustedPitchChannelValue()
881 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
887int RemoteControlCalibrationController::adjustedYawChannelValue()
891 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
897int RemoteControlCalibrationController::adjustedThrottleChannelValue()
901 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
907int RemoteControlCalibrationController::adjustedRollExtensionChannelValue()
911 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
917int RemoteControlCalibrationController::adjustedPitchExtensionChannelValue()
921 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
927int RemoteControlCalibrationController::adjustedAux1ExtensionChannelValue()
931 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
937int RemoteControlCalibrationController::adjustedAux2ExtensionChannelValue()
941 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
947int RemoteControlCalibrationController::adjustedAux3ExtensionChannelValue()
951 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
957int RemoteControlCalibrationController::adjustedAux4ExtensionChannelValue()
961 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
967int RemoteControlCalibrationController::adjustedAux5ExtensionChannelValue()
971 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
977int RemoteControlCalibrationController::adjustedAux6ExtensionChannelValue()
981 return _adjustChannelRawValue(
_rgChannelInfo[channel], _channelRawValue[channel]);
987bool RemoteControlCalibrationController::rollChannelMapped()
992bool RemoteControlCalibrationController::pitchChannelMapped()
997bool RemoteControlCalibrationController::rollExtensionChannelMapped()
1002bool RemoteControlCalibrationController::pitchExtensionChannelMapped()
1007bool RemoteControlCalibrationController::aux1ExtensionChannelMapped()
1012bool RemoteControlCalibrationController::aux2ExtensionChannelMapped()
1017bool RemoteControlCalibrationController::aux3ExtensionChannelMapped()
1022bool RemoteControlCalibrationController::aux4ExtensionChannelMapped()
1027bool RemoteControlCalibrationController::aux5ExtensionChannelMapped()
1032bool RemoteControlCalibrationController::aux6ExtensionChannelMapped()
1037bool RemoteControlCalibrationController::yawChannelMapped()
1042bool RemoteControlCalibrationController::throttleChannelMapped()
1047bool RemoteControlCalibrationController::pitchExtensionEnabled()
1052bool RemoteControlCalibrationController::rollExtensionEnabled()
1057bool RemoteControlCalibrationController::aux1ExtensionEnabled()
1062bool RemoteControlCalibrationController::aux2ExtensionEnabled()
1067bool RemoteControlCalibrationController::aux3ExtensionEnabled()
1072bool RemoteControlCalibrationController::aux4ExtensionEnabled()
1077bool RemoteControlCalibrationController::aux5ExtensionEnabled()
1082bool RemoteControlCalibrationController::aux6ExtensionEnabled()
1087bool RemoteControlCalibrationController::anyExtensionEnabled()
1089 return pitchExtensionEnabled() || rollExtensionEnabled() ||
1090 aux1ExtensionEnabled() || aux2ExtensionEnabled() ||
1091 aux3ExtensionEnabled() || aux4ExtensionEnabled() ||
1092 aux5ExtensionEnabled() || aux6ExtensionEnabled();
1095bool RemoteControlCalibrationController::rollChannelReversed()
1104bool RemoteControlCalibrationController::pitchChannelReversed()
1113bool RemoteControlCalibrationController::rollExtensionChannelReversed()
1122bool RemoteControlCalibrationController::pitchExtensionChannelReversed()
1131bool RemoteControlCalibrationController::aux1ExtensionChannelReversed()
1140bool RemoteControlCalibrationController::aux2ExtensionChannelReversed()
1149bool RemoteControlCalibrationController::aux3ExtensionChannelReversed()
1158bool RemoteControlCalibrationController::aux4ExtensionChannelReversed()
1167bool RemoteControlCalibrationController::aux5ExtensionChannelReversed()
1176bool RemoteControlCalibrationController::aux6ExtensionChannelReversed()
1185bool RemoteControlCalibrationController::yawChannelReversed()
1194bool RemoteControlCalibrationController::throttleChannelReversed()
1203void RemoteControlCalibrationController::setTransmitterMode(
int mode)
1205 if (mode < 1 || mode > 4) {
1206 qCWarning(RemoteControlCalibrationControllerLog) <<
"Invalid transmitter mode set:" << mode;
1209 if (_transmitterMode != mode) {
1210 _transmitterMode = mode;
1243 _emitDeadbandChanged(stickFunctionRoll);
1244 _emitDeadbandChanged(stickFunctionPitch);
1245 _emitDeadbandChanged(stickFunctionRollExtension);
1246 _emitDeadbandChanged(stickFunctionPitchExtension);
1247 _emitDeadbandChanged(stickFunctionAux1Extension);
1248 _emitDeadbandChanged(stickFunctionAux2Extension);
1249 _emitDeadbandChanged(stickFunctionAux3Extension);
1250 _emitDeadbandChanged(stickFunctionAux4Extension);
1251 _emitDeadbandChanged(stickFunctionAux5Extension);
1252 _emitDeadbandChanged(stickFunctionAux6Extension);
1253 _emitDeadbandChanged(stickFunctionYaw);
1254 _emitDeadbandChanged(stickFunctionThrottle);
1257int RemoteControlCalibrationController::rollDeadband()
1259 return _deadbandForFunction(stickFunctionRoll);
1262int RemoteControlCalibrationController::pitchDeadband()
1264 return _deadbandForFunction(stickFunctionPitch);
1267int RemoteControlCalibrationController::rollExtensionDeadband()
1269 return _deadbandForFunction(stickFunctionRollExtension);
1272int RemoteControlCalibrationController::pitchExtensionDeadband()
1274 return _deadbandForFunction(stickFunctionPitchExtension);
1277int RemoteControlCalibrationController::aux1ExtensionDeadband()
1279 return _deadbandForFunction(stickFunctionAux1Extension);
1282int RemoteControlCalibrationController::aux2ExtensionDeadband()
1284 return _deadbandForFunction(stickFunctionAux2Extension);
1287int RemoteControlCalibrationController::aux3ExtensionDeadband()
1289 return _deadbandForFunction(stickFunctionAux3Extension);
1292int RemoteControlCalibrationController::aux4ExtensionDeadband()
1294 return _deadbandForFunction(stickFunctionAux4Extension);
1297int RemoteControlCalibrationController::aux5ExtensionDeadband()
1299 return _deadbandForFunction(stickFunctionAux5Extension);
1302int RemoteControlCalibrationController::aux6ExtensionDeadband()
1304 return _deadbandForFunction(stickFunctionAux6Extension);
1307int RemoteControlCalibrationController::yawDeadband()
1309 return _deadbandForFunction(stickFunctionYaw);
1312int RemoteControlCalibrationController::throttleDeadband()
1314 return _deadbandForFunction(stickFunctionThrottle);
1317void RemoteControlCalibrationController::copyTrims()
1324 switch (stickFunction) {
1325 case stickFunctionRoll:
1327 case stickFunctionPitch:
1329 case stickFunctionYaw:
1331 case stickFunctionThrottle:
1332 return tr(
"Throttle");
1333 case stickFunctionAux1Extension:
1334 return tr(
"Aux1 Extension");
1335 case stickFunctionAux2Extension:
1336 return tr(
"Aux2 Extension");
1337 case stickFunctionAux3Extension:
1338 return tr(
"Aux3 Extension");
1339 case stickFunctionAux4Extension:
1340 return tr(
"Aux4 Extension");
1341 case stickFunctionAux5Extension:
1342 return tr(
"Aux5 Extension");
1343 case stickFunctionAux6Extension:
1344 return tr(
"Aux6 Extension");
1345 case stickFunctionPitchExtension:
1346 return tr(
"Pitch Extension");
1347 case stickFunctionRollExtension:
1348 return tr(
"Roll Extension");
1350 return tr(
"Unknown");
1354void RemoteControlCalibrationController::setCenteredThrottle(
bool centered)
1356 if (_centeredThrottle != centered) {
1357 _centeredThrottle = centered;
1362void RemoteControlCalibrationController::setJoystickMode(
bool joystickMode)
1364 if (_joystickMode == joystickMode) {
1368 _joystickMode = joystickMode;
1369 setCenteredThrottle(joystickMode);
1373int RemoteControlCalibrationController::_deadbandForFunction(StickFunction stickFunction)
const
1375 if (stickFunction < 0 || stickFunction >= stickFunctionMax) {
1387void RemoteControlCalibrationController::_emitDeadbandChanged(StickFunction stickFunction)
1389 const int deadband = _deadbandForFunction(stickFunction);
1390 switch (stickFunction) {
1391 case stickFunctionRoll:
1394 case stickFunctionPitch:
1397 case stickFunctionYaw:
1400 case stickFunctionThrottle:
1408void RemoteControlCalibrationController::_saveCalibrationValues()
1410 _saveStoredCalibrationValues();
1418 switch (stickFunction) {
1419 case stickFunctionRoll:
1420 case stickFunctionPitch:
1421 case stickFunctionYaw:
1422 case stickFunctionThrottle:
#define QGC_LOGGING_CATEGORY(name, categoryStr)
static constexpr const char * msgPitchDown
static constexpr const char * msgSwitchMinMaxRC
static constexpr const char * msgPitchUp
static constexpr const char * msgRollLeft
static constexpr const char * msgComplete
static constexpr const char * msgBeginThrottleCenter
static constexpr const char * msgThrottleUp
static constexpr const char * msgYawLeft
static constexpr const char * msgPitchCenter
static constexpr const char * msgExtensionHigh
static constexpr const char * msgRollRight
static constexpr const char * msgExtensionLow
static constexpr const char * msgThrottleDown
static constexpr const char * msgBeginThrottleDown
static constexpr const char * msgYawRight
Used for handling missing Facts from C++ code.
Abstract base class for calibrating RC and Joystick controller.
void pitchDeadbandChanged(int deadband)
QString _stickFunctionToString(StickFunction stickFunction)
void pitchChannelReversedChanged(bool reversed)
void adjustedAux1ExtensionChannelValueChanged(int rcValue)
int _calValidMinValue
Largest valid minimum channel range value.
void joystickModeChanged(bool joystickMode)
void rawChannelValuesChanged(QVector< int > channelValues)
void _validateAndAdjustCalibrationValues()
void rollExtensionChannelReversedChanged(bool reversed)
void channelCountChanged(int channelCount)
void yawDeadbandChanged(int deadband)
void throttleDeadbandChanged(int deadband)
static constexpr int _chanMinimum
Minimum numner of channels required to run.
void pitchExtensionChannelReversedChanged(bool reversed)
int _calCenterPoint
Center point for calibration.
int _calMoveDelta
Amount of delta past center which is considered stick movement.
void aux6ExtensionChannelMappedChanged(bool mapped)
void aux3ExtensionChannelMappedChanged(bool mapped)
void singleStickDisplayChanged(bool singleStickDisplay)
void aux4ExtensionChannelReversedChanged(bool reversed)
void adjustedThrottleChannelValueChanged(int rcValue)
void aux4ExtensionChannelMappedChanged(bool mapped)
void _resetInternalCalibrationValues()
Resets internal calibration values to their initial state in preparation for a new calibration sequen...
void aux3ExtensionChannelReversedChanged(bool reversed)
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)
int _stickDetectSettleMSecs
Time in ms stick must be stable before detection completes.
void adjustedAux5ExtensionChannelValueChanged(int rcValue)
void adjustedAux2ExtensionChannelValueChanged(int rcValue)
void yawChannelReversedChanged(bool reversed)
void rollExtensionChannelMappedChanged(bool mapped)
void adjustedAux4ExtensionChannelValueChanged(int rcValue)
void aux6ExtensionChannelReversedChanged(bool reversed)
void adjustedRollChannelValueChanged(int rcValue)
void rollDeadbandChanged(int deadband)
void aux5ExtensionChannelReversedChanged(bool reversed)
void adjustedYawChannelValueChanged(int rcValue)
virtual bool _stickFunctionEnabled(StickFunction stickFunction)
Returns true if the stick function is enabled.
void aux1ExtensionChannelReversedChanged(bool reversed)
void adjustedAux3ExtensionChannelValueChanged(int rcValue)
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)
int _calSettleDelta
Amount of delta which is considered no stick movement.
void aux5ExtensionChannelMappedChanged(bool mapped)
ChannelInfo _rgChannelInfo[_chanMax]
Information associated with each rc channel.
void calibratingChanged(bool calibrating)
void rawChannelValueChanged(int channel, int value)
void adjustedRollExtensionChannelValueChanged(int rcValue)
void stickDisplayPositionsChanged()
void throttleChannelMappedChanged(bool mapped)
int _rgFunctionChannelMapping[stickFunctionMax]
Maps from StickFunction to channel index. _chanMax indicates channel not set for this function.
void transmitterModeChanged()
int _chanCount
Number of actual rc channels available.
void rollChannelReversedChanged(bool reversed)
int _calDefaultMaxValue
Default value for Max if not set.
void centeredThrottleChanged(bool centeredThrottle)
void _signalAllAttitudeValueChanges()
void aux1ExtensionChannelMappedChanged(bool mapped)
void throttleChannelReversedChanged(bool reversed)
void pitchExtensionChannelMappedChanged(bool mapped)
void yawChannelMappedChanged(bool mapped)
void aux2ExtensionChannelMappedChanged(bool mapped)
void adjustedAux6ExtensionChannelValueChanged(int rcValue)
void calibrationCompleted()
void aux2ExtensionChannelReversedChanged(bool reversed)
void adjustedPitchExtensionChannelValueChanged(int rcValue)
void startCalibration(QGCMAVLink::CalibrationType calType)
int deadband
deadband around center
int channelTrim
Trim position (usually center for sticks)
enum StickFunction stickFunction
Function mapped to this channel, stickFunctionMax for none.