vtx: fix VTX_SETTINGS_POWER_COUNT and add dummy entries to saPowerNames
[inav.git] / src / test / unit / rc_controls_unittest.cc.txt
blob8e744dba8931045b4d300656491ceb9cdaab0916
1 /*
2  * This file is part of Cleanflight.
3  *
4  * Cleanflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Cleanflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Cleanflight.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include <stdint.h>
19 #include <limits.h>
21 //#define DEBUG_RC_CONTROLS
23 extern "C" {
24     #include "platform.h"
26     #include "common/maths.h"
27     #include "common/axis.h"
29     #include "drivers/sensor.h"
30     #include "drivers/accgyro.h"
32     #include "sensors/sensors.h"
33     #include "sensors/acceleration.h"
35     #include "io/beeper.h"
36     #include "io/escservo.h"
37     #include "io/rc_controls.h"
39     #include "rx/rx.h"
41     #include "flight/pid.h"
44 #include "unittest_macros.h"
45 #include "gtest/gtest.h"
47 extern "C" {
48 extern void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions, escAndServoConfig_t *escAndServoConfig, pidProfile_t *pidProfile);
51 class RcControlsModesTest : public ::testing::Test {
52 protected:
53     modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
55     virtual void SetUp() {
56         memset(&modeActivationConditions, 0, sizeof(modeActivationConditions));
57     }
60 TEST_F(RcControlsModesTest, updateActivatedModesWithAllInputsAtMidde)
62     // given
63     rcModeActivationMask = 0;
65     // and
66     memset(&rxRuntimeConfig, 0, sizeof(rxRuntimeConfig_t));
67     rxRuntimeConfig.auxChannelCount = MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT;
69     // and
70     uint8_t index;
71     for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
72         rcData[index] = PWM_RANGE_MIDDLE;
73     }
75     // when
76     updateActivatedModes(modeActivationConditions);
78     // then
79     for (index = 0; index < CHECKBOX_ITEM_COUNT; index++) {
80 #ifdef DEBUG_RC_CONTROLS
81         printf("iteration: %d\n", index);
82 #endif
83         EXPECT_EQ(false, IS_RC_MODE_ACTIVE(index));
84     }
87 TEST_F(RcControlsModesTest, updateActivatedModesUsingValidAuxConfigurationAndRXValues)
89     // given
90     modeActivationConditions[0].modeId = (boxId_e)0;
91     modeActivationConditions[0].auxChannelIndex = AUX1 - NON_AUX_CHANNEL_COUNT;
92     modeActivationConditions[0].range.startStep = CHANNEL_VALUE_TO_STEP(1700);
93     modeActivationConditions[0].range.endStep = CHANNEL_VALUE_TO_STEP(2100);
95     modeActivationConditions[1].modeId = (boxId_e)1;
96     modeActivationConditions[1].auxChannelIndex = AUX2 - NON_AUX_CHANNEL_COUNT;
97     modeActivationConditions[1].range.startStep = CHANNEL_VALUE_TO_STEP(1300);
98     modeActivationConditions[1].range.endStep = CHANNEL_VALUE_TO_STEP(1700);
100     modeActivationConditions[2].modeId = (boxId_e)2;
101     modeActivationConditions[2].auxChannelIndex = AUX3 - NON_AUX_CHANNEL_COUNT;
102     modeActivationConditions[2].range.startStep = CHANNEL_VALUE_TO_STEP(900);
103     modeActivationConditions[2].range.endStep = CHANNEL_VALUE_TO_STEP(1200);
105     modeActivationConditions[3].modeId = (boxId_e)3;
106     modeActivationConditions[3].auxChannelIndex = AUX4 - NON_AUX_CHANNEL_COUNT;
107     modeActivationConditions[3].range.startStep = CHANNEL_VALUE_TO_STEP(900);
108     modeActivationConditions[3].range.endStep = CHANNEL_VALUE_TO_STEP(2100);
110     modeActivationConditions[4].modeId = (boxId_e)4;
111     modeActivationConditions[4].auxChannelIndex = AUX5 - NON_AUX_CHANNEL_COUNT;
112     modeActivationConditions[4].range.startStep = CHANNEL_VALUE_TO_STEP(900);
113     modeActivationConditions[4].range.endStep = CHANNEL_VALUE_TO_STEP(925);
115     EXPECT_EQ(0, modeActivationConditions[4].range.startStep);
116     EXPECT_EQ(1, modeActivationConditions[4].range.endStep);
118     modeActivationConditions[5].modeId = (boxId_e)5;
119     modeActivationConditions[5].auxChannelIndex = AUX6 - NON_AUX_CHANNEL_COUNT;
120     modeActivationConditions[5].range.startStep = CHANNEL_VALUE_TO_STEP(2075);
121     modeActivationConditions[5].range.endStep = CHANNEL_VALUE_TO_STEP(2100);
123     EXPECT_EQ(47, modeActivationConditions[5].range.startStep);
124     EXPECT_EQ(48, modeActivationConditions[5].range.endStep);
126     modeActivationConditions[6].modeId = (boxId_e)6;
127     modeActivationConditions[6].auxChannelIndex = AUX7 - NON_AUX_CHANNEL_COUNT;
128     modeActivationConditions[6].range.startStep = CHANNEL_VALUE_TO_STEP(925);
129     modeActivationConditions[6].range.endStep = CHANNEL_VALUE_TO_STEP(950);
131     EXPECT_EQ(1, modeActivationConditions[6].range.startStep);
132     EXPECT_EQ(2, modeActivationConditions[6].range.endStep);
134     // and
135     rcModeActivationMask = 0;
137     // and
138     memset(&rxRuntimeConfig, 0, sizeof(rxRuntimeConfig_t));
139     rxRuntimeConfig.auxChannelCount = MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT;
141     // and
142     uint8_t index;
143     for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
144         rcData[index] = PWM_RANGE_MIDDLE;
145     }
147     rcData[AUX1] = PWM_RANGE_MAX;
148     rcData[AUX2] = PWM_RANGE_MIDDLE;
149     rcData[AUX3] = PWM_RANGE_MIN;
150     rcData[AUX4] = PWM_RANGE_MAX;
151     rcData[AUX5] = 899; // value lower that range minimum should be treated the same as the lowest range value
152     rcData[AUX6] = 2101; // value higher than the range maximum should be treated the same as the highest range value
153     rcData[AUX7] = 950; // value equal to range step upper boundary should not activate the mode
155     // and
156     uint32_t expectedMask = 0;
157     expectedMask |= (1 << 0);
158     expectedMask |= (1 << 1);
159     expectedMask |= (1 << 2);
160     expectedMask |= (1 << 3);
161     expectedMask |= (1 << 4);
162     expectedMask |= (1 << 5);
163     expectedMask |= (0 << 6);
165     // when
166     updateActivatedModes(modeActivationConditions);
168     // then
169     for (index = 0; index < CHECKBOX_ITEM_COUNT; index++) {
170 #ifdef DEBUG_RC_CONTROLS
171         printf("iteration: %d\n", index);
172 #endif
173         EXPECT_EQ(expectedMask & (1 << index), rcModeActivationMask & (1 << index));
174     }
177 enum {
178     COUNTER_GENERATE_PITCH_ROLL_CURVE = 0,
179     COUNTER_QUEUE_CONFIRMATION_BEEP,
180     COUNTER_CHANGE_CONTROL_RATE_PROFILE
182 #define CALL_COUNT_ITEM_COUNT 3
184 static int callCounts[CALL_COUNT_ITEM_COUNT];
186 #define CALL_COUNTER(item) (callCounts[item])
188 extern "C" {
189 void generateRcCurves(controlRateConfig_t *) {
190     callCounts[COUNTER_GENERATE_PITCH_ROLL_CURVE]++;
193 void beeperConfirmationBeeps(uint8_t) {
194     callCounts[COUNTER_QUEUE_CONFIRMATION_BEEP]++;
197 void beeper(beeperMode_e mode) {
198     UNUSED(mode);
201 void changeControlRateProfile(uint8_t) {
202     callCounts[COUNTER_CHANGE_CONTROL_RATE_PROFILE]++;
207 void resetCallCounters(void) {
208     memset(&callCounts, 0, sizeof(callCounts));
211 uint32_t fixedMillis;
213 extern "C" {
214 uint32_t millis(void) {
215     return fixedMillis;
219 void resetMillis(void) {
220     fixedMillis = 0;
223 #define DEFAULT_MIN_CHECK 1100
224 #define DEFAULT_MAX_CHECK 1900
226 rxConfig_t rxConfig;
228 extern uint8_t adjustmentStateMask;
229 extern adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENT_COUNT];
231 static const adjustmentConfig_t rateAdjustmentConfig = {
232     .adjustmentFunction = ADJUSTMENT_RC_RATE,
233     .mode = ADJUSTMENT_MODE_STEP,
234     .data = { { 1 } }
237 class RcControlsAdjustmentsTest : public ::testing::Test {
238 protected:
239     controlRateConfig_t controlRateConfig = {
240             .rcExpo8 = 0,
241             .thrMid8 = 0,
242             .thrExpo8 = 0,
243             .rates = {0, 0, 0},
244             .dynThrPID = 0,
245             .rcYawExpo8 = 0,
246             .tpa_breakpoint = 0
247     };
249     virtual void SetUp() {
250         adjustmentStateMask = 0;
251         memset(&adjustmentStates, 0, sizeof(adjustmentStates));
253         memset(&rxConfig, 0, sizeof (rxConfig));
254         rxConfig.mincheck = DEFAULT_MIN_CHECK;
255         rxConfig.maxcheck = DEFAULT_MAX_CHECK;
256         rxConfig.midrc = 1500;
258         controlRateConfig.rcExpo8 = 0;
259         controlRateConfig.thrMid8 = 0;
260         controlRateConfig.thrExpo8 = 0;
261         controlRateConfig.rcYawExpo8 = 0;
262         controlRateConfig.rates[0] = 0;
263         controlRateConfig.rates[1] = 0;
264         controlRateConfig.rates[2] = 0;
265         controlRateConfig.dynThrPID = 0;
266         controlRateConfig.tpa_breakpoint = 0;
268     }
271 TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsSticksInMiddle)
273     // given
274     configureAdjustment(0, AUX3 - NON_AUX_CHANNEL_COUNT, &rateAdjustmentConfig);
276     // and
277     uint8_t index;
278     for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
279         rcData[index] = PWM_RANGE_MIDDLE;
280     }
282     // and
283     resetCallCounters();
284     resetMillis();
286     // when
287     processRcAdjustments(&controlRateConfig, &rxConfig);
289     // then
290     EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 0);
291     EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 0);
292     EXPECT_EQ(adjustmentStateMask, 0);
295 TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
297     // given
298     controlRateConfig_t controlRateConfig = {
299             .rcExpo8 = 0,
300             .thrMid8 = 0,
301             .thrExpo8 = 0,
302             .rates = {0,0,0},
303             .dynThrPID = 0,
304             .rcYawExpo8 = 0,
305             .tpa_breakpoint = 0
306     };
308     // and
309     memset(&rxConfig, 0, sizeof (rxConfig));
310     rxConfig.mincheck = DEFAULT_MIN_CHECK;
311     rxConfig.maxcheck = DEFAULT_MAX_CHECK;
312     rxConfig.midrc = 1500;
314     // and
315     adjustmentStateMask = 0;
316     memset(&adjustmentStates, 0, sizeof(adjustmentStates));
317     configureAdjustment(0, AUX3 - NON_AUX_CHANNEL_COUNT, &rateAdjustmentConfig);
319     // and
320     uint8_t index;
321     for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
322         rcData[index] = PWM_RANGE_MIDDLE;
323     }
325     // and
326     resetCallCounters();
327     resetMillis();
329     // and
330     rcData[AUX3] = PWM_RANGE_MAX;
332     // and
333     uint8_t expectedAdjustmentStateMask =
334             (1 << 0);
336     // and
337     fixedMillis = 496;
339     // when
340     processRcAdjustments(&controlRateConfig, &rxConfig);
342     // then
343     EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 1);
344     EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 1);
345     EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
348     //
349     // now pretend a short amount of time has passed, but not enough time to allow the value to have been increased
350     //
352     // given
353     fixedMillis = 497;
355     // when
356     processRcAdjustments(&controlRateConfig, &rxConfig);
358     EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
361     //
362     // moving the switch back to the middle should immediately reset the state flag without increasing the value
363     //
366     // given
367     rcData[AUX3] = PWM_RANGE_MIDDLE;
369     // and
370     fixedMillis = 498;
372     // and
373     expectedAdjustmentStateMask = adjustmentStateMask &
374             ~(1 << 0);
376     // when
377     processRcAdjustments(&controlRateConfig, &rxConfig);
379     EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
382     //
383     // flipping the switch again, before the state reset would have occurred, allows the value to be increased again
385     // given
386     rcData[AUX3] = PWM_RANGE_MAX;
388     // and
389     expectedAdjustmentStateMask =
390             (1 << 0);
392     // and
393     fixedMillis = 499;
395     // when
396     processRcAdjustments(&controlRateConfig, &rxConfig);
398     // then
399     EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 2);
400     EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 2);
401     EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
403     //
404     // leaving the switch up, after the original timer would have reset the state should now NOT cause
405     // the rate to increase, it should only increase after another 500ms from when the state was reset.
406     //
408     // given
409     fixedMillis = 500;
411     // when
412     processRcAdjustments(&controlRateConfig, &rxConfig);
414     // then
415     EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
417     //
418     // should still not be able to be increased
419     //
421     // given
422     fixedMillis = 997;
424     // when
425     processRcAdjustments(&controlRateConfig, &rxConfig);
427     // then
428     EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
430     //
431     // 500ms has now passed since the switch was returned to the middle, now that
432     // switch is still in the UP position after the timer has elapses it should
433     // be increased again.
434     //
436     // given
437     fixedMillis = 998;
439     // when
440     processRcAdjustments(&controlRateConfig, &rxConfig);
442     // then
443     EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 3);
444     EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 3);
445     EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
448 static const adjustmentConfig_t rateProfileAdjustmentConfig = {
449     .adjustmentFunction = ADJUSTMENT_RATE_PROFILE,
450     .mode = ADJUSTMENT_MODE_SELECT,
451     .data = { { 3 } }
454 TEST_F(RcControlsAdjustmentsTest, processRcRateProfileAdjustments)
456     // given
457     int adjustmentIndex = 3;
458     configureAdjustment(adjustmentIndex, AUX4 - NON_AUX_CHANNEL_COUNT, &rateProfileAdjustmentConfig);
460     // and
461     uint8_t index;
462     for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
463         rcData[index] = PWM_RANGE_MIDDLE;
464     }
466     // and
467     resetCallCounters();
468     resetMillis();
470     // and
471     rcData[AUX4] = PWM_RANGE_MAX;
473     // and
474     uint8_t expectedAdjustmentStateMask =
475             (1 << adjustmentIndex);
477     // when
478     processRcAdjustments(&controlRateConfig, &rxConfig);
480     // then
481     EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 1);
482     EXPECT_EQ(CALL_COUNTER(COUNTER_CHANGE_CONTROL_RATE_PROFILE), 1);
483     EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
486 static const adjustmentConfig_t pidPitchAndRollPAdjustmentConfig = {
487     .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_P,
488     .mode = ADJUSTMENT_MODE_STEP,
489     .data = { { 1 } }
492 static const adjustmentConfig_t pidPitchAndRollIAdjustmentConfig = {
493     .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_I,
494     .mode = ADJUSTMENT_MODE_STEP,
495     .data = { { 1 } }
498 static const adjustmentConfig_t pidPitchAndRollDAdjustmentConfig = {
499     .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_D,
500     .mode = ADJUSTMENT_MODE_STEP,
501     .data = { { 1 } }
504 static const adjustmentConfig_t pidYawPAdjustmentConfig = {
505     .adjustmentFunction = ADJUSTMENT_YAW_P,
506     .mode = ADJUSTMENT_MODE_STEP,
507     .data = { { 1 } }
510 static const adjustmentConfig_t pidYawIAdjustmentConfig = {
511     .adjustmentFunction = ADJUSTMENT_YAW_I,
512     .mode = ADJUSTMENT_MODE_STEP,
513     .data = { { 1 } }
516 static const adjustmentConfig_t pidYawDAdjustmentConfig = {
517     .adjustmentFunction = ADJUSTMENT_YAW_D,
518     .mode = ADJUSTMENT_MODE_STEP,
519     .data = { { 1 } }
522 TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController0)
524     // given
525     modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
526     memset(&modeActivationConditions, 0, sizeof (modeActivationConditions));
528     escAndServoConfig_t escAndServoConfig;
529     memset(&escAndServoConfig, 0, sizeof (escAndServoConfig));
531     pidProfile_t pidProfile;
532     memset(&pidProfile, 0, sizeof (pidProfile));
533     pidProfile.pidController = 0;
534     pidProfile.P8[PIDPITCH] = 0;
535     pidProfile.P8[PIDROLL] = 5;
536     pidProfile.P8[YAW] = 7;
537     pidProfile.I8[PIDPITCH] = 10;
538     pidProfile.I8[PIDROLL] = 15;
539     pidProfile.I8[YAW] = 17;
540     pidProfile.D8[PIDPITCH] = 20;
541     pidProfile.D8[PIDROLL] = 25;
542     pidProfile.D8[YAW] = 27;
544     // and
545     controlRateConfig_t controlRateConfig;
546     memset(&controlRateConfig, 0, sizeof (controlRateConfig));
548     configureAdjustment(0, AUX1 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollPAdjustmentConfig);
549     configureAdjustment(1, AUX2 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollIAdjustmentConfig);
550     configureAdjustment(2, AUX3 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollDAdjustmentConfig);
551     configureAdjustment(3, AUX1 - NON_AUX_CHANNEL_COUNT, &pidYawPAdjustmentConfig);
552     configureAdjustment(4, AUX2 - NON_AUX_CHANNEL_COUNT, &pidYawIAdjustmentConfig);
553     configureAdjustment(5, AUX3 - NON_AUX_CHANNEL_COUNT, &pidYawDAdjustmentConfig);
555     // and
556     uint8_t index;
557     for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
558         rcData[index] = PWM_RANGE_MIDDLE;
559     }
561     // and
562     resetCallCounters();
563     resetMillis();
565     // and
566     rcData[AUX1] = PWM_RANGE_MAX;
567     rcData[AUX2] = PWM_RANGE_MAX;
568     rcData[AUX3] = PWM_RANGE_MAX;
570     // and
571     uint8_t expectedAdjustmentStateMask =
572             (1 << 0) |
573             (1 << 1) |
574             (1 << 2) |
575             (1 << 3) |
576             (1 << 4) |
577             (1 << 5);
579     // when
580     useRcControlsConfig(modeActivationConditions, &escAndServoConfig, &pidProfile);
581     processRcAdjustments(&controlRateConfig, &rxConfig);
583     // then
584     EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 6);
585     EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
587     // and
588     EXPECT_EQ(1, pidProfile.P8[PIDPITCH]);
589     EXPECT_EQ(6, pidProfile.P8[PIDROLL]);
590     EXPECT_EQ(8, pidProfile.P8[YAW]);
591     EXPECT_EQ(11, pidProfile.I8[PIDPITCH]);
592     EXPECT_EQ(16, pidProfile.I8[PIDROLL]);
593     EXPECT_EQ(18, pidProfile.I8[YAW]);
594     EXPECT_EQ(21, pidProfile.D8[PIDPITCH]);
595     EXPECT_EQ(26, pidProfile.D8[PIDROLL]);
596     EXPECT_EQ(28, pidProfile.D8[YAW]);
599 TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController2)
601     // given
602     modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
603     memset(&modeActivationConditions, 0, sizeof (modeActivationConditions));
605     escAndServoConfig_t escAndServoConfig;
606     memset(&escAndServoConfig, 0, sizeof (escAndServoConfig));
608     pidProfile_t pidProfile;
609     memset(&pidProfile, 0, sizeof (pidProfile));
610     pidProfile.pidController = 2;
611     pidProfile.P_f[PIDPITCH] = 0.0f;
612     pidProfile.P_f[PIDROLL] = 5.0f;
613     pidProfile.P_f[PIDYAW] = 7.0f;
614     pidProfile.I_f[PIDPITCH] = 10.0f;
615     pidProfile.I_f[PIDROLL] = 15.0f;
616     pidProfile.I_f[PIDYAW] = 17.0f;
617     pidProfile.D_f[PIDPITCH] = 20.0f;
618     pidProfile.D_f[PIDROLL] = 25.0f;
619     pidProfile.D_f[PIDYAW] = 27.0f;
621     // and
622     controlRateConfig_t controlRateConfig;
623     memset(&controlRateConfig, 0, sizeof (controlRateConfig));
625     configureAdjustment(0, AUX1 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollPAdjustmentConfig);
626     configureAdjustment(1, AUX2 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollIAdjustmentConfig);
627     configureAdjustment(2, AUX3 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollDAdjustmentConfig);
628     configureAdjustment(3, AUX1 - NON_AUX_CHANNEL_COUNT, &pidYawPAdjustmentConfig);
629     configureAdjustment(4, AUX2 - NON_AUX_CHANNEL_COUNT, &pidYawIAdjustmentConfig);
630     configureAdjustment(5, AUX3 - NON_AUX_CHANNEL_COUNT, &pidYawDAdjustmentConfig);
632     // and
633     uint8_t index;
634     for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
635         rcData[index] = PWM_RANGE_MIDDLE;
636     }
638     // and
639     resetCallCounters();
640     resetMillis();
642     // and
643     rcData[AUX1] = PWM_RANGE_MAX;
644     rcData[AUX2] = PWM_RANGE_MAX;
645     rcData[AUX3] = PWM_RANGE_MAX;
647     // and
648     uint8_t expectedAdjustmentStateMask =
649             (1 << 0) |
650             (1 << 1) |
651             (1 << 2) |
652             (1 << 3) |
653             (1 << 4) |
654             (1 << 5);
656     // when
657     useRcControlsConfig(modeActivationConditions, &escAndServoConfig, &pidProfile);
658     processRcAdjustments(&controlRateConfig, &rxConfig);
660     // then
661     EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 6);
662     EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
664     // and
665     EXPECT_EQ(0.1f, pidProfile.P_f[PIDPITCH]);
666     EXPECT_EQ(5.1f, pidProfile.P_f[PIDROLL]);
667     EXPECT_EQ(7.1f, pidProfile.P_f[PIDYAW]);
668     EXPECT_EQ(10.01f, pidProfile.I_f[PIDPITCH]);
669     EXPECT_EQ(15.01f, pidProfile.I_f[PIDROLL]);
670     EXPECT_EQ(17.01f, pidProfile.I_f[PIDYAW]);
671     EXPECT_EQ(20.001f, pidProfile.D_f[PIDPITCH]);
672     EXPECT_EQ(25.001f, pidProfile.D_f[PIDROLL]);
673     EXPECT_EQ(27.001f, pidProfile.D_f[PIDYAW]);
677 extern "C" {
678 void saveConfigAndNotify(void) {}
679 void generateThrottleCurve(controlRateConfig_t *, escAndServoConfig_t *) {}
680 void changeProfile(uint8_t) {}
681 void accSetCalibrationCycles(uint16_t) {}
682 void gyroSetCalibrationCycles(uint16_t) {}
683 void applyAndSaveAccelerometerTrimsDelta(rollAndPitchTrims_t*) {}
684 void handleInflightCalibrationStickPosition(void) {}
685 bool feature(uint32_t) { return false;}
686 bool sensors(uint32_t) { return false;}
687 void mwArm(void) {}
688 void mwDisarm(void) {}
689 void displayDisablePageCycling() {}
690 void displayEnablePageCycling() {}
692 bool failsafeIsActive() { return false; }
693 bool rxIsReceivingSignal() { return true; }
695 uint8_t getCurrentControlRateProfile(void) {
696     return 0;
698 void GPS_reset_home_position(void) {}
699 void baroSetCalibrationCycles(uint16_t) {}
701 uint8_t armingFlags = 0;
702 int16_t heading;
703 uint8_t stateFlags = 0;
704 int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT];
705 rxRuntimeConfig_t rxRuntimeConfig;