diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2021-02-28 11:50:53 +0100 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2021-02-28 11:51:06 +0100 |
commit | c4554532612d139de31723267cb1c3192ff6d4a8 (patch) | |
tree | 869ceb9350a71bc23d2917001bd1a0369a4296ab /source/HoverBitController.cpp | |
parent | 4cceee770b44a7a9606543087bb89901574c7540 (diff) | |
download | hoverbit-ble-c4554532612d139de31723267cb1c3192ff6d4a8.tar.gz hoverbit-ble-c4554532612d139de31723267cb1c3192ff6d4a8.zip |
:sparkles: Add emptyBattery code
Diffstat (limited to 'source/HoverBitController.cpp')
-rw-r--r-- | source/HoverBitController.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/source/HoverBitController.cpp b/source/HoverBitController.cpp index df9893e..1ecc21b 100644 --- a/source/HoverBitController.cpp +++ b/source/HoverBitController.cpp @@ -32,7 +32,7 @@ DEALINGS IN THE SOFTWARE. */ void HoverBitController::init() { mainController = false; - batteryEmpty = false; + bBatteryEmpty = false; batteryMilliVolt = 3700; batteryFactor = 4.42; @@ -82,6 +82,18 @@ unsigned int HoverBitController::GetBatteryVoltage() { } /** + * Check wether battery level is too low. + */ +void HoverBitController::checkBattery() { + if (GetBatteryVoltage() < BATTERY_LOW_LIMIT - 60) { + bBatteryEmpty = true; + Throttle(0); + Arm(0); + Rudder(0); + } +} + +/** * Method for sending commands to the AirBit-card, * this code is translated from the ts-code in MakeKit's original hex-file. * @@ -148,6 +160,10 @@ void HoverBitController::AirBit(int Pitch,int Arm,int Roll,int Throttle,int Yaw, * Method that sends commands with the current values for all parameters. */ void HoverBitController::HoverControl() { + checkBattery(); + if (BatteryEmpty()) { + Arm(0); + } if (!failSafe()) { AirBit(0, arm, 0, throttle, roll, roll + 45, servo_1); } @@ -181,5 +197,6 @@ void HoverBitController::Arm(bool _arm) { lastReceiveTime = uBit.systemTime(); } bool HoverBitController::BatteryEmpty() { - return batteryEmpty; + checkBattery(); + return bBatteryEmpty; } |