From 02c4ade94883d6ee09ec49bc9eaacce523e9e7ec Mon Sep 17 00:00:00 2001 From: Arne Schwarck Date: Wed, 4 Dec 2019 20:46:39 +0100 Subject: [PATCH] Battery protection (#888) * Battery protection If your car battery voltage is lower than 0% switch off charging to stop the Eon from damaging the 12v car battery. Leaving you with a car that can not start but has a fully charged eon ;-) * add rbiasini comment && !ignition * Update Offroad_ChargeDisabled with voltage low * simplify alert * non-temporal hysteresis from @rbiasini And up the start charge limit to 12v. i.e. 50% car battery voltage * once battery power recovers to 11.500 volts charge This leaves 1v inbetween for any fluctuations that could occur. * fix indent * Fix indent of whole block It looks like sometimes when you copy and paste into the github web interface some white spacing gets added or removed. BE AWARE! --- selfdrive/boardd/boardd.cc | 12 +++++++++++- selfdrive/controls/lib/alerts_offroad.json | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index b94bf3a3ed..573b1aee0f 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -57,6 +57,8 @@ bool loopback_can = false; cereal::HealthData::HwType hw_type = cereal::HealthData::HwType::UNKNOWN; bool is_pigeon = false; const uint32_t NO_IGNITION_CNT_MAX = 2 * 60 * 60 * 24 * 3; // turn off charge after 3 days +const uint32_t VBATT_START_CHARGING = 11500; +const uint32_t VBATT_PAUSE_CHARGING = 10500; uint32_t no_ignition_cnt = 0; bool connected_once = false; bool ignition_last = false; @@ -353,12 +355,20 @@ void can_health(PubSocket *publisher) { } #ifndef __x86_64__ - if ((no_ignition_cnt > NO_IGNITION_CNT_MAX) && (health.usb_power_mode == (uint8_t)(cereal::HealthData::UsbPowerMode::CDP))) { + bool cdp_mode = health.usb_power_mode == (uint8_t)(cereal::HealthData::UsbPowerMode::CDP); + bool no_ignition_exp = no_ignition_cnt > NO_IGNITION_CNT_MAX; + if ((no_ignition_exp || (health.voltage < VBATT_PAUSE_CHARGING)) && cdp_mode && !ignition) { printf("TURN OFF CHARGING!\n"); pthread_mutex_lock(&usb_lock); libusb_control_transfer(dev_handle, 0xc0, 0xe6, (uint16_t)(cereal::HealthData::UsbPowerMode::CLIENT), 0, NULL, 0, TIMEOUT); pthread_mutex_unlock(&usb_lock); } + if (!no_ignition_exp && (health.voltage > VBATT_START_CHARGING) && !cdp_mode) { + printf("TURN ON CHARGING!\n"); + pthread_mutex_lock(&usb_lock); + libusb_control_transfer(dev_handle, 0xc0, 0xe6, (uint16_t)(cereal::HealthData::UsbPowerMode::CDP), 0, NULL, 0, TIMEOUT); + pthread_mutex_unlock(&usb_lock); + } #endif // clear VIN, CarParams, and set new safety on car start diff --git a/selfdrive/controls/lib/alerts_offroad.json b/selfdrive/controls/lib/alerts_offroad.json index 534deae2fe..92a41ac854 100644 --- a/selfdrive/controls/lib/alerts_offroad.json +++ b/selfdrive/controls/lib/alerts_offroad.json @@ -1,6 +1,6 @@ { "Offroad_ChargeDisabled": { - "text": "EON charging disabled after car being off for more than 3 days. Turn ignition on to start charging again.", + "text": "EON charging disabled after car being off for more than 3 days or car voltage too low. Turn ignition on to start charging again.", "severity": 0 }, "Offroad_TemperatureTooHigh": {