2 * This file is part of Betaflight.
4 * Betaflight 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 * Betaflight 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 Betaflight. If not, see <http://www.gnu.org/licenses/>.
25 #include "build/debug.h"
26 #include "pg/pg_ids.h"
28 #include "common/filter.h"
29 #include "common/vector.h"
32 #include "fc/rc_controls.h"
33 #include "fc/runtime_config.h"
35 #include "flight/alt_hold.h"
36 #include "flight/failsafe.h"
37 #include "flight/imu.h"
38 #include "flight/pid.h"
39 #include "flight/position.h"
45 #include "pg/alt_hold.h"
46 #include "pg/autopilot.h"
48 #include "sensors/acceleration.h"
49 #include "sensors/gyro.h"
51 PG_REGISTER(accelerometerConfig_t
, accelerometerConfig
, PG_ACCELEROMETER_CONFIG
, 0);
52 PG_REGISTER(altHoldConfig_t
, altHoldConfig
, PG_ALTHOLD_CONFIG
, 0);
53 PG_REGISTER(apConfig_t
, apConfig
, PG_AUTOPILOT
, 0);
54 PG_REGISTER(gyroConfig_t
, gyroConfig
, PG_GYRO_CONFIG
, 0);
55 PG_REGISTER(positionConfig_t
, positionConfig
, PG_POSITION
, 0);
56 PG_REGISTER(rcControlsConfig_t
, rcControlsConfig
, PG_RC_CONTROLS_CONFIG
, 0);
58 bool failsafeIsActive(void) { return false; }
59 timeUs_t currentTimeUs
= 0;
60 bool isAltHoldActive();
63 #include "unittest_macros.h"
64 #include "gtest/gtest.h"
71 TEST(AltholdUnittest
, altHoldTransitionsTest
)
73 updateAltHold(currentTimeUs
);
74 EXPECT_EQ(isAltHoldActive(), false);
76 flightModeFlags
|= ALT_HOLD_MODE
;
78 updateAltHold(currentTimeUs
);
79 EXPECT_EQ(isAltHoldActive(), true);
81 flightModeFlags
^= ALT_HOLD_MODE
;
83 updateAltHold(currentTimeUs
);
84 EXPECT_EQ(isAltHoldActive(), false);
86 flightModeFlags
|= ALT_HOLD_MODE
;
88 updateAltHold(currentTimeUs
);
89 EXPECT_EQ(isAltHoldActive(), true);
92 TEST(AltholdUnittest
, altHoldTransitionsTestUnfinishedExitEnter
)
95 EXPECT_EQ(isAltHoldActive(), false);
97 flightModeFlags
|= ALT_HOLD_MODE
;
99 updateAltHold(currentTimeUs
);
100 EXPECT_EQ(isAltHoldActive(), true);
106 uint8_t armingFlags
= 0;
107 int16_t debug
[DEBUG16_VALUE_COUNT
];
109 uint16_t flightModeFlags
= 0;
110 uint8_t stateFlags
= 0;
113 attitudeEulerAngles_t attitude
;
114 gpsSolutionData_t gpsSol
;
116 float getAltitudeCm(void) { return 0.0f
; }
117 float getAltitudeDerivative(void) { return 0.0f
; }
118 float getCosTiltAngle(void) { return 0.0f
; }
119 float getGpsDataIntervalSeconds(void) { return 0.01f
; }
120 float getGpsDataFrequencyHz(void) { return 10.0f
; }
123 bool gpsHasNewData(uint16_t* gpsStamp
) {
128 void GPS_distance2d(const gpsLocation_t
* /*from*/, const gpsLocation_t
* /*to*/, vector2_t
* /*dest*/) { }
130 void parseRcChannels(const char *input
, rxConfig_t
*rxConfig
) {
135 throttleStatus_e
calculateThrottleStatus() {