2 * This file is part of Cleanflight.
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.
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.
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/>.
21 #include "blackbox/blackbox.h"
22 #include "build/debug.h"
23 #include "common/maths.h"
24 #include "common/streambuf.h"
25 #include "config/feature.h"
26 #include "config/config.h"
27 #include "fc/controlrate_profile.h"
29 #include "fc/rc_controls.h"
30 #include "fc/rc_modes.h"
31 #include "fc/runtime_config.h"
32 #include "flight/failsafe.h"
33 #include "flight/imu.h"
34 #include "flight/mixer.h"
35 #include "flight/pid.h"
36 #include "flight/servos.h"
37 #include "io/beeper.h"
42 #include "pg/pg_ids.h"
45 #include "scheduler/scheduler.h"
46 #include "sensors/acceleration.h"
47 #include "sensors/gyro.h"
48 #include "telemetry/telemetry.h"
50 vtxSettingsConfig_t
vtxGetSettings(void);
52 PG_REGISTER(accelerometerConfig_t
, accelerometerConfig
, PG_ACCELEROMETER_CONFIG
, 0);
53 PG_REGISTER(blackboxConfig_t
, blackboxConfig
, PG_BLACKBOX_CONFIG
, 0);
54 PG_REGISTER(gyroConfig_t
, gyroConfig
, PG_GYRO_CONFIG
, 0);
55 PG_REGISTER(mixerConfig_t
, mixerConfig
, PG_MIXER_CONFIG
, 0);
56 PG_REGISTER(pidConfig_t
, pidConfig
, PG_PID_CONFIG
, 0);
57 PG_REGISTER(rxConfig_t
, rxConfig
, PG_RX_CONFIG
, 0);
58 PG_REGISTER(servoConfig_t
, servoConfig
, PG_SERVO_CONFIG
, 0);
59 PG_REGISTER(systemConfig_t
, systemConfig
, PG_SYSTEM_CONFIG
, 0);
60 PG_REGISTER(telemetryConfig_t
, telemetryConfig
, PG_TELEMETRY_CONFIG
, 0);
61 PG_REGISTER(failsafeConfig_t
, failsafeConfig
, PG_FAILSAFE_CONFIG
, 0);
62 PG_REGISTER(motorConfig_t
, motorConfig
, PG_MOTOR_CONFIG
, 0);
65 float rcData
[MAX_SUPPORTED_RC_CHANNEL_COUNT
];
66 uint16_t averageSystemLoadPercent
= 0;
68 uint8_t debugMode
= 0;
69 int16_t debug
[DEBUG16_VALUE_COUNT
];
70 pidProfile_t
*currentPidProfile
;
71 controlRateConfig_t
*currentControlRateProfile
;
72 attitudeEulerAngles_t attitude
;
73 gpsSolutionData_t gpsSol
;
74 uint32_t targetPidLooptime
;
75 bool cmsInMenu
= false;
76 float axisPID_P
[3], axisPID_I
[3], axisPID_D
[3], axisPIDSum
[3];
77 rxRuntimeState_t rxRuntimeState
= {};
80 uint32_t simulationFeatureFlags
= 0;
81 uint32_t simulationTime
= 0;
82 bool gyroCalibDone
= false;
83 bool simulationHaveRx
= false;
85 #include "gtest/gtest.h"
87 TEST(VtxTest
, PitMode
)
90 modeActivationConditionsMutable(0)->auxChannelIndex
= 0;
91 modeActivationConditionsMutable(0)->modeId
= BOXVTXPITMODE
;
92 modeActivationConditionsMutable(0)->range
.startStep
= CHANNEL_VALUE_TO_STEP(1750);
93 modeActivationConditionsMutable(0)->range
.endStep
= CHANNEL_VALUE_TO_STEP(CHANNEL_RANGE_MAX
);
95 analyzeModeActivationConditions();
98 vtxSettingsConfigMutable()->band
= 0;
99 vtxSettingsConfigMutable()->freq
= 5800;
100 vtxSettingsConfigMutable()->pitModeFreq
= 5300;
103 EXPECT_EQ(5800, vtxGetSettings().freq
);
106 // enable vtx pit mode
110 updateActivatedModes();
113 EXPECT_TRUE(IS_RC_MODE_ACTIVE(BOXVTXPITMODE
));
114 EXPECT_EQ(5300, vtxGetSettings().freq
);
119 uint8_t activePidLoopDenom
= 1;
120 uint32_t micros(void) { return simulationTime
; }
121 uint32_t millis(void) { return micros() / 1000; }
122 bool rxIsReceivingSignal(void) { return simulationHaveRx
; }
124 bool featureIsEnabled(uint32_t f
) { return simulationFeatureFlags
& f
; }
125 void warningLedFlash(void) {}
126 void warningLedDisable(void) {}
127 void warningLedUpdate(void) {}
128 void beeper(beeperMode_e
) {}
129 void beeperConfirmationBeeps(uint8_t) {}
130 void beeperWarningBeeps(uint8_t) {}
131 void beeperSilence(void) {}
132 void systemBeep(bool) {}
133 void saveConfigAndNotify(void) {}
134 void blackboxFinish(void) {}
135 bool accIsCalibrationComplete(void) { return true; }
136 bool accHasBeenCalibrated(void) { return true; }
137 bool baroIsCalibrationComplete(void) { return true; }
138 bool gyroIsCalibrationComplete(void) { return gyroCalibDone
; }
139 void gyroStartCalibration(bool) {}
140 bool isFirstArmingGyroCalibrationRunning(void) { return false; }
141 void pidController(const pidProfile_t
*, timeUs_t
) {}
142 void pidStabilisationState(pidStabilisationState_e
) {}
143 void mixTable(timeUs_t
) {};
144 void writeMotors(void) {};
145 void writeServos(void) {};
146 bool calculateRxChannelsAndUpdateFailsafe(timeUs_t
) { return true; }
147 bool isMixerUsingServos(void) { return false; }
149 timeDelta_t
getTaskDeltaTimeUs(taskId_e
) { return 0; }
150 void updateRSSI(timeUs_t
) {}
151 bool failsafeIsMonitoring(void) { return false; }
152 void failsafeStartMonitoring(void) {}
153 void failsafeUpdateState(void) {}
154 bool failsafeIsActive(void) { return false; }
155 void pidResetIterm(void) {}
156 void updateAdjustmentStates(void) {}
157 void processRcAdjustments(controlRateConfig_t
*) {}
158 void updateGpsWaypointsAndMode(void) {}
159 void mspSerialReleaseSharedTelemetryPorts(void) {}
160 void telemetryCheckState(void) {}
161 void mspSerialAllocatePorts(void) {}
162 void gyroReadTemperature(void) {}
163 void updateRcCommands(void) {}
164 void applyAltHold(void) {}
165 void resetYawAxis(void) {}
166 int16_t calculateThrottleAngleCorrection(uint8_t) { return 0; }
167 void processRcCommand(void) {}
168 void updateGpsStateForHomeAndHoldMode(void) {}
169 void blackboxUpdate(timeUs_t
) {}
170 void transponderUpdate(timeUs_t
) {}
171 void GPS_reset_home_position(void) {}
172 void accStartCalibration(void) {}
173 void baroSetGroundLevel(void) {}
174 void changePidProfile(uint8_t) {}
175 void changeControlRateProfile(uint8_t) {}
176 void dashboardEnablePageCycling(void) {}
177 void dashboardDisablePageCycling(void) {}
178 bool imuQuaternionHeadfreeOffsetSet(void) { return true; }
179 void rescheduleTask(taskId_e
, timeDelta_t
) {}
180 bool usbCableIsInserted(void) { return false; }
181 bool usbVcpIsConnected(void) { return false; }
182 void pidSetAntiGravityState(bool newState
) { UNUSED(newState
); }
183 void osdSuppressStats(bool) {}
184 void pidSetItermReset(bool) {}
185 void applyAccelerometerTrimsDelta(rollAndPitchTrims_t
*) {}
186 bool isFixedWing(void) { return false; }
187 void compassStartCalibration(void) {}
188 bool compassIsCalibrationComplete(void) { return true; }
189 bool isUpright(void) { return true; }
190 void blackboxLogEvent(FlightLogEvent
, union flightLogEventData_u
*) {};
191 void gyroFiltering(timeUs_t
) {};
192 timeDelta_t
rxGetFrameDelta(timeDelta_t
*) { return 0; }
193 void updateRcRefreshRate(timeUs_t
) {};
194 uint16_t getAverageSystemLoadPercent(void) { return 0; }
195 bool isMotorProtocolEnabled(void) { return false; }
196 void pinioBoxTaskControl(void) {}
197 void sbufWriteU8(sbuf_t
*, uint8_t) {}
198 void sbufWriteU16(sbuf_t
*, uint16_t) {}
199 void sbufWriteU32(sbuf_t
*, uint32_t) {}
200 void schedulerSetNextStateTime(timeDelta_t
) {}