From b9da80c08cc9220ed142f8b824b78c45654e28f3 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 19:32:18 +1100 Subject: [PATCH 01/12] hwdef: remove bad hwdef lines these have no effect --- libraries/AP_HAL_ChibiOS/hwdef/HEEWING-F405/hwdef.dat | 3 --- .../AP_HAL_ChibiOS/hwdef/SpeedyBeeF405WING/hwdef.dat | 8 -------- 2 files changed, 11 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/HEEWING-F405/hwdef.dat b/libraries/AP_HAL_ChibiOS/hwdef/HEEWING-F405/hwdef.dat index ea20a6af98b86..f3fee9ff6d736 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/HEEWING-F405/hwdef.dat +++ b/libraries/AP_HAL_ChibiOS/hwdef/HEEWING-F405/hwdef.dat @@ -160,9 +160,6 @@ define HAL_BATT_CURR_SCALE 26.7 define HAL_WITH_DSP FALSE define HAL_GYROFFT_ENABLED 0 -# --------------------- save flash ---------------------- -define AP_BATTMON_SMBUS_ENABLE 0 - include ../include/minimize_fpv_osd.inc include ../include/save_some_flash.inc diff --git a/libraries/AP_HAL_ChibiOS/hwdef/SpeedyBeeF405WING/hwdef.dat b/libraries/AP_HAL_ChibiOS/hwdef/SpeedyBeeF405WING/hwdef.dat index f6052add8b977..f6842833c8d38 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/SpeedyBeeF405WING/hwdef.dat +++ b/libraries/AP_HAL_ChibiOS/hwdef/SpeedyBeeF405WING/hwdef.dat @@ -171,14 +171,6 @@ define STM32_PWM_USE_ADVANCED TRUE define HAL_WITH_DSP FALSE -# save some flash - -# disable SMBUS and fuel battery monitors to save flash -define AP_BATTMON_SMBUS_ENABLE 0 -define AP_BATTMON_FUEL_ENABLE 0 -define AP_BATTMON_SYNTHETIC_CURRENT_ENABLED 0 -define HAL_BATTMON_INA2XX_ENABLED 0 - # disable parachute and sprayer to save flash define HAL_PARACHUTE_ENABLED 0 define HAL_SPRAYER_ENABLED 0 From 70cd4d20ee06832cdb5c6f77085bbada70a1e73b Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 19:38:49 +1100 Subject: [PATCH 02/12] AP_BattMonitor: add and use AP_BATTERY_ENABLED --- libraries/AP_BattMonitor/AP_BattMonitor.cpp | 7 +++++++ libraries/AP_BattMonitor/AP_BattMonitor.h | 7 ++++++- libraries/AP_BattMonitor/AP_BattMonitor_Backend.cpp | 6 ++++++ libraries/AP_BattMonitor/AP_BattMonitor_Backend.h | 9 ++++++++- libraries/AP_BattMonitor/AP_BattMonitor_Logging.cpp | 5 +++-- libraries/AP_BattMonitor/AP_BattMonitor_Params.cpp | 6 ++++++ 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/libraries/AP_BattMonitor/AP_BattMonitor.cpp b/libraries/AP_BattMonitor/AP_BattMonitor.cpp index e62ddc28b112c..d929b8182a06d 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor.cpp @@ -1,4 +1,9 @@ +#include "AP_BattMonitor_config.h" + +#if AP_BATTERY_ENABLED + #include "AP_BattMonitor.h" + #include "AP_BattMonitor_Analog.h" #include "AP_BattMonitor_SMBus.h" #include "AP_BattMonitor_SMBus_Solo.h" @@ -1117,3 +1122,5 @@ AP_BattMonitor &battery() } }; + +#endif // AP_BATTERY_ENABLED diff --git a/libraries/AP_BattMonitor/AP_BattMonitor.h b/libraries/AP_BattMonitor/AP_BattMonitor.h index e9e10b7ef06ed..67c138e5f779f 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor.h +++ b/libraries/AP_BattMonitor/AP_BattMonitor.h @@ -1,12 +1,15 @@ #pragma once +#include "AP_BattMonitor_config.h" + +#if AP_BATTERY_ENABLED + #include #include #include #include #include #include "AP_BattMonitor_Params.h" -#include "AP_BattMonitor_config.h" // maximum number of battery monitors #ifndef AP_BATT_MONITOR_MAX_INSTANCES @@ -315,3 +318,5 @@ class AP_BattMonitor namespace AP { AP_BattMonitor &battery(); }; + +#endif // AP_BATTERY_ENABLED diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_Backend.cpp b/libraries/AP_BattMonitor/AP_BattMonitor_Backend.cpp index 842c6ac907852..195dbded04047 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_Backend.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor_Backend.cpp @@ -13,6 +13,10 @@ along with this program. If not, see . */ +#include "AP_BattMonitor_config.h" + +#if AP_BATTERY_ENABLED + #include #include #include "AP_BattMonitor.h" @@ -334,3 +338,5 @@ void AP_BattMonitor_Backend::update_consumed(AP_BattMonitor::BattMonitor_State & state.consumed_wh += 0.001 * mah * state.voltage; } } + +#endif // AP_BATTERY_ENABLED diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_Backend.h b/libraries/AP_BattMonitor/AP_BattMonitor_Backend.h index 907d8712c1174..a33c316d70d7b 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_Backend.h +++ b/libraries/AP_BattMonitor/AP_BattMonitor_Backend.h @@ -14,9 +14,14 @@ */ #pragma once -#include +#include "AP_BattMonitor_config.h" + +#if AP_BATTERY_ENABLED + #include "AP_BattMonitor.h" +#include + class AP_BattMonitor_Backend { public: @@ -141,3 +146,5 @@ struct BattMonitorScript_State { float temperature=nanf(""); // Battery temperature in degrees Celsius }; #endif // AP_BATTERY_SCRIPTING_ENABLED + +#endif // AP_BATTERY_ENABLED diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_Logging.cpp b/libraries/AP_BattMonitor/AP_BattMonitor_Logging.cpp index 4b5d4fe2c57e1..c7950b847eac2 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_Logging.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor_Logging.cpp @@ -1,6 +1,7 @@ +#include "AP_BattMonitor_config.h" #include -#if HAL_LOGGING_ENABLED +#if AP_BATTERY_ENABLED && HAL_LOGGING_ENABLED #include "AP_BattMonitor_Backend.h" #include @@ -88,4 +89,4 @@ void AP_BattMonitor_Backend::Log_Write_BCL(const uint8_t instance, const uint64_ #endif } -#endif // HAL_LOGGING_ENABLED +#endif // AP_BATTERY_ENABLED && HAL_LOGGING_ENABLED diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_Params.cpp b/libraries/AP_BattMonitor/AP_BattMonitor_Params.cpp index 09e1b7ae61bd4..60cdf5ad769bc 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_Params.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor_Params.cpp @@ -1,3 +1,7 @@ +#include "AP_BattMonitor_config.h" + +#if AP_BATTERY_ENABLED + #include #include #include "AP_BattMonitor_Params.h" @@ -172,3 +176,5 @@ const AP_Param::GroupInfo AP_BattMonitor_Params::var_info[] = { AP_BattMonitor_Params::AP_BattMonitor_Params(void) { AP_Param::setup_object_defaults(this, var_info); } + +#endif // AP_BATTERY_ENABLED From 744312df5bd2792a75e2c5eae8dc25be3ea1385e Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 19:38:49 +1100 Subject: [PATCH 03/12] AP_Hott_Telem: add and use AP_BATTERY_ENABLED --- libraries/AP_Hott_Telem/AP_Hott_Telem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/AP_Hott_Telem/AP_Hott_Telem.cpp b/libraries/AP_Hott_Telem/AP_Hott_Telem.cpp index 98bff2d86ecba..14a2550343614 100644 --- a/libraries/AP_Hott_Telem/AP_Hott_Telem.cpp +++ b/libraries/AP_Hott_Telem/AP_Hott_Telem.cpp @@ -109,6 +109,7 @@ void AP_Hott_Telem::send_EAM(void) uint8_t stop_byte = 0x7D; //#44 stop } msg {}; +#if AP_BATTERY_ENABLED const AP_BattMonitor &battery = AP::battery(); if (battery.num_instances() > 0) { msg.batt1_voltage = uint16_t(battery.voltage(0) * 10); @@ -125,6 +126,7 @@ void AP_Hott_Telem::send_EAM(void) if (battery.consumed_mah(used_mah)) { msg.batt_used = used_mah * 0.1; } +#endif // AP_BATTERY_ENABLED const AP_Baro &baro = AP::baro(); msg.temp1 = uint8_t(baro.get_temperature(0) + 20.5); From 6e10a0a90de13c8845b2ed699445939b55d55ce7 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 19:38:49 +1100 Subject: [PATCH 04/12] AP_LTM_Telem: add and use AP_BATTERY_ENABLED --- libraries/AP_LTM_Telem/AP_LTM_Telem.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/AP_LTM_Telem/AP_LTM_Telem.cpp b/libraries/AP_LTM_Telem/AP_LTM_Telem.cpp index d4599d28d16fd..5d3bdc2f41558 100644 --- a/libraries/AP_LTM_Telem/AP_LTM_Telem.cpp +++ b/libraries/AP_LTM_Telem/AP_LTM_Telem.cpp @@ -116,6 +116,7 @@ void AP_LTM_Telem::send_Gframe(void) // Sensors frame void AP_LTM_Telem::send_Sframe(void) { +#if AP_BATTERY_ENABLED const AP_BattMonitor &battery = AP::battery(); const uint16_t volt = (uint16_t) roundf(battery.voltage() * 1000.0f); // battery voltage (expects value in mV) float current; @@ -124,6 +125,10 @@ void AP_LTM_Telem::send_Sframe(void) } // note: max. current value we can send is 65.536 A const uint16_t amp = (uint16_t) roundf(current * 100.0f); // current sensor (expects value in hundredth of A) +#else + const uint16_t volt = 0; + const uint16_t amp = 0; +#endif // airspeed in m/s if available and enabled - even if not used - otherwise send 0 uint8_t airspeed = 0; // airspeed sensor (m/s) From 008121334eb39985fff84e8986542130d1efa17e Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 19:38:49 +1100 Subject: [PATCH 05/12] AP_MSP: add and use AP_BATTERY_ENABLED --- libraries/AP_MSP/AP_MSP_Telem_Backend.cpp | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/libraries/AP_MSP/AP_MSP_Telem_Backend.cpp b/libraries/AP_MSP/AP_MSP_Telem_Backend.cpp index 2f4fe9c63bb18..e2e804d0d2169 100644 --- a/libraries/AP_MSP/AP_MSP_Telem_Backend.cpp +++ b/libraries/AP_MSP/AP_MSP_Telem_Backend.cpp @@ -66,7 +66,9 @@ void AP_MSP_Telem_Backend::setup_wfq_scheduler(void) set_scheduler_entry(ATTITUDE, 200, 200); // 5Hz attitude set_scheduler_entry(ALTITUDE, 250, 250); // 4Hz altitude(cm) and velocity(cm/s) set_scheduler_entry(ANALOG, 250, 250); // 4Hz rssi + batt +#if AP_BATTERY_ENABLED set_scheduler_entry(BATTERY_STATE, 500, 500); // 2Hz battery +#endif #if HAL_WITH_ESC_TELEM set_scheduler_entry(ESC_SENSOR_DATA, 500, 500); // 2Hz ESC telemetry #endif @@ -114,7 +116,9 @@ bool AP_MSP_Telem_Backend::is_packet_ready(uint8_t idx, bool queue_empty) case ATTITUDE: // Attitude case ALTITUDE: // Altitude and Vario case ANALOG: // Rssi, Battery, mAh, Current +#if AP_BATTERY_ENABLED case BATTERY_STATE: // voltage, capacity, current, mAh +#endif #if HAL_WITH_ESC_TELEM case ESC_SENSOR_DATA: // esc temp + rpm #endif @@ -155,10 +159,12 @@ void AP_MSP_Telem_Backend::process_packet(uint8_t idx) _msp_port.c_state = MSP_IDLE; } +#if AP_BATTERY_ENABLED uint8_t AP_MSP_Telem_Backend::calc_cell_count(const float battery_voltage) { return floorf((battery_voltage / CELLFULL) + 1); } +#endif float AP_MSP_Telem_Backend::get_vspeed_ms(void) const { @@ -215,6 +221,7 @@ void AP_MSP_Telem_Backend::update_gps_state(gps_state_t &gps_state) } } +#if AP_BATTERY_ENABLED void AP_MSP_Telem_Backend::update_battery_state(battery_state_t &battery_state) { memset(&battery_state, 0, sizeof(battery_state)); @@ -241,6 +248,7 @@ void AP_MSP_Telem_Backend::update_battery_state(battery_state_t &battery_state) battery_state.batt_cellcount = cc; } } +#endif // AP_BATTERY_ENABLED void AP_MSP_Telem_Backend::update_airspeed(airspeed_state_t &airspeed_state) { @@ -334,7 +342,9 @@ void AP_MSP_Telem_Backend::enable_warnings() return; } BIT_SET(msp->_osd_config.enabled_warnings, OSD_WARNING_FAIL_SAFE); +#if AP_BATTERY_ENABLED BIT_SET(msp->_osd_config.enabled_warnings, OSD_WARNING_BATTERY_CRITICAL); +#endif } void AP_MSP_Telem_Backend::process_incoming_data() @@ -466,8 +476,10 @@ MSPCommandResult AP_MSP_Telem_Backend::msp_process_out_command(uint16_t cmd_msp, return msp_process_out_altitude(dst); case MSP_ANALOG: return msp_process_out_analog(dst); +#if AP_BATTERY_ENABLED case MSP_BATTERY_STATE: return msp_process_out_battery_state(dst); +#endif case MSP_UID: return msp_process_out_uid(dst); #if HAL_WITH_ESC_TELEM @@ -905,6 +917,7 @@ MSPCommandResult AP_MSP_Telem_Backend::msp_process_out_altitude(sbuf_t *dst) MSPCommandResult AP_MSP_Telem_Backend::msp_process_out_analog(sbuf_t *dst) { +#if AP_BATTERY_ENABLED battery_state_t battery_state; update_battery_state(battery_state); @@ -922,10 +935,27 @@ MSPCommandResult AP_MSP_Telem_Backend::msp_process_out_analog(sbuf_t *dst) current_ca : (int16_t)constrain_int32(battery_state.batt_current_a * 100, -0x8000, 0x7FFF), // current A to cA (0.01 steps, range is -320A to 320A) voltage_cv : (uint16_t)constrain_int32(battery_state.batt_voltage_v * 100,0,0xFFFF) // battery voltage in 0.01V steps }; +#else + float rssi; + const struct PACKED { + uint8_t voltage_dv; + uint16_t mah; + uint16_t rssi; + int16_t current_ca; + uint16_t voltage_cv; + } analog { + voltage_dv : 0, + mah : 0, + rssi : uint16_t(get_rssi(rssi) ? constrain_float(rssi,0,1) * 1023 : 0), // rssi 0-1 to 0-1023) + current_ca : 0, + voltage_cv : 0 + }; +#endif sbuf_write_data(dst, &analog, sizeof(analog)); return MSP_RESULT_ACK; } +#if AP_BATTERY_ENABLED MSPCommandResult AP_MSP_Telem_Backend::msp_process_out_battery_state(sbuf_t *dst) { const AP_MSP *msp = AP::msp(); @@ -956,6 +986,7 @@ MSPCommandResult AP_MSP_Telem_Backend::msp_process_out_battery_state(sbuf_t *dst sbuf_write_data(dst, &battery, sizeof(battery)); return MSP_RESULT_ACK; } +#endif MSPCommandResult AP_MSP_Telem_Backend::msp_process_out_esc_sensor_data(sbuf_t *dst) { @@ -1104,7 +1135,9 @@ void AP_MSP_Telem_Backend::hide_osd_items(void) if (msp == nullptr) { return; } +#if AP_BATTERY_ENABLED const AP_Notify ¬ify = AP::notify(); +#endif // clear all and only set the flashing ones BIT_CLEAR(osd_hidden_items_bitmask, OSD_GPS_SATS); BIT_CLEAR(osd_hidden_items_bitmask, OSD_HOME_DIR); @@ -1146,11 +1179,13 @@ void AP_MSP_Telem_Backend::hide_osd_items(void) if (msp->_msp_status.flight_mode_focus) { BIT_SET(osd_hidden_items_bitmask, OSD_CRAFT_NAME); } +#if AP_BATTERY_ENABLED // flash battery on failsafe if (notify.flags.failsafe_battery) { BIT_SET(osd_hidden_items_bitmask, OSD_AVG_CELL_VOLTAGE); BIT_SET(osd_hidden_items_bitmask, OSD_MAIN_BATT_VOLTAGE); } +#endif // flash rtc if no time available #if AP_RTC_ENABLED uint64_t time_usec; From a29575040f9053af66ea0ad35febb40967463fd4 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 19:38:50 +1100 Subject: [PATCH 06/12] AP_Notify: add and use AP_BATTERY_ENABLED --- libraries/AP_Notify/Display.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/AP_Notify/Display.cpp b/libraries/AP_Notify/Display.cpp index 301cc862f3cc6..35ecbdb315b67 100644 --- a/libraries/AP_Notify/Display.cpp +++ b/libraries/AP_Notify/Display.cpp @@ -406,7 +406,9 @@ void Display::update_all() { update_text(0); update_mode(1); +#if AP_BATTERY_ENABLED update_battery(2); +#endif #if AP_GPS_ENABLED update_gps(3); #endif @@ -530,6 +532,7 @@ void Display::update_ekf(uint8_t r) } } +#if AP_BATTERY_ENABLED void Display::update_battery(uint8_t r) { char msg [DISPLAY_MESSAGE_SIZE]; @@ -541,7 +544,8 @@ void Display::update_battery(uint8_t r) snprintf(msg, DISPLAY_MESSAGE_SIZE, "BAT:%4.2fV --%% ", (double)battery.voltage()) ; } draw_text(COLUMN(0), ROW(r), msg); - } +} +#endif // AP_BATTERY_ENABLED void Display::update_mode(uint8_t r) { From 9c42dc3bc94f28c45daa1d7d0b8e652b72c8fdf4 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 19:38:50 +1100 Subject: [PATCH 07/12] AP_OSD: add and use AP_BATTERY_ENABLED --- libraries/AP_OSD/AP_OSD.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/AP_OSD/AP_OSD.cpp b/libraries/AP_OSD/AP_OSD.cpp index e88e2363959a4..4329c423e55d7 100644 --- a/libraries/AP_OSD/AP_OSD.cpp +++ b/libraries/AP_OSD/AP_OSD.cpp @@ -446,6 +446,7 @@ void AP_OSD::update_stats() // maximum altitude alt = -alt; _stats.max_alt_m = fmaxf(_stats.max_alt_m, alt); +#if AP_BATTERY_ENABLED // maximum current AP_BattMonitor &battery = AP::battery(); float amps; @@ -457,6 +458,7 @@ void AP_OSD::update_stats() if (voltage > 0) { _stats.min_voltage_v = fminf(_stats.min_voltage_v, voltage); } +#endif #if AP_RSSI_ENABLED // minimum rssi AP_RSSI *ap_rssi = AP_RSSI::get_singleton(); From 3e2a6b9b14ea802ebb5a58bf0a5520cadf1748b3 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 19:38:50 +1100 Subject: [PATCH 08/12] AP_RCTelemetry: add and use AP_BATTERY_ENABLED --- libraries/AP_RCTelemetry/AP_Spektrum_Telem.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libraries/AP_RCTelemetry/AP_Spektrum_Telem.cpp b/libraries/AP_RCTelemetry/AP_Spektrum_Telem.cpp index 3e669206ec847..083bb7af92340 100644 --- a/libraries/AP_RCTelemetry/AP_Spektrum_Telem.cpp +++ b/libraries/AP_RCTelemetry/AP_Spektrum_Telem.cpp @@ -296,12 +296,16 @@ void AP_Spektrum_Telem::calc_qos() // prepare rpm data - B/E mandatory frame that must be sent periodically void AP_Spektrum_Telem::calc_rpm() { +#if AP_BATTERY_ENABLED const AP_BattMonitor &_battery = AP::battery(); +#endif _telem.rpm.identifier = TELE_DEVICE_RPM; _telem.rpm.sID = 0; // battery voltage in centivolts, can have up to a 12S battery (4.25Vx12S = 51.0V) +#if AP_BATTERY_ENABLED _telem.rpm.volts = htobe16(((uint16_t)roundf(_battery.voltage(0) * 100.0f))); +#endif _telem.rpm.temperature = htobe16(int16_t(roundf(32.0f + AP::baro().get_temperature(0) * 9.0f / 5.0f))); #if AP_RPM_ENABLED const AP_RPM *rpm = AP::rpm(); @@ -328,10 +332,12 @@ void AP_Spektrum_Telem::send_msg_chunk(const MessageChunk& chunk) // prepare battery data - B/E but not supported by Spektrum void AP_Spektrum_Telem::calc_batt_volts(uint8_t instance) { +#if AP_BATTERY_ENABLED const AP_BattMonitor &_battery = AP::battery(); // battery voltage in centivolts, can have up to a 12S battery (4.25Vx12S = 51.0V) _telem.hv.volts = htobe16(uint16_t(roundf(_battery.voltage(instance) * 100.0f))); +#endif _telem.hv.identifier = TELE_DEVICE_VOLTAGE; _telem.hv.sID = 0; _telem_pending = true; @@ -340,6 +346,7 @@ void AP_Spektrum_Telem::calc_batt_volts(uint8_t instance) // prepare battery data - B/E but not supported by Spektrum void AP_Spektrum_Telem::calc_batt_amps(uint8_t instance) { +#if AP_BATTERY_ENABLED const AP_BattMonitor &_battery = AP::battery(); float current; @@ -349,6 +356,7 @@ void AP_Spektrum_Telem::calc_batt_amps(uint8_t instance) // Range: +/- 150A Resolution: 300A / 2048 = 0.196791 A/count _telem.amps.current = htobe16(int16_t(roundf(current * 2048.0f / 300.0f))); +#endif _telem.amps.identifier = TELE_DEVICE_AMPS; _telem.amps.sID = 0; _telem_pending = true; @@ -357,11 +365,14 @@ void AP_Spektrum_Telem::calc_batt_amps(uint8_t instance) // prepare battery data - L/E void AP_Spektrum_Telem::calc_batt_mah() { +#if AP_BATTERY_ENABLED const AP_BattMonitor &_battery = AP::battery(); +#endif _telem.fpMAH.identifier = TELE_DEVICE_FP_MAH; _telem.fpMAH.sID = 0; +#if AP_BATTERY_ENABLED float current; if (!_battery.current_amps(current, 0)) { current = 0; @@ -396,6 +407,10 @@ void AP_Spektrum_Telem::calc_batt_mah() } else { _telem.fpMAH.temp_B = 0x7FFF; } +#else + _telem.fpMAH.temp_A = 0x7FFF; + _telem.fpMAH.temp_B = 0x7FFF; +#endif _telem_pending = true; } From 96c5060c4d6ff2006a97a12c27af48e92d8458bb Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 22:07:24 +1100 Subject: [PATCH 09/12] AP_Motors: add and use AP_BATTERY_ENABLED --- libraries/AP_Motors/AP_Motors6DOF.cpp | 2 ++ libraries/AP_Motors/AP_MotorsMulticopter.cpp | 4 ++++ libraries/AP_Motors/AP_Motors_Thrust_Linearization.cpp | 2 ++ 3 files changed, 8 insertions(+) diff --git a/libraries/AP_Motors/AP_Motors6DOF.cpp b/libraries/AP_Motors/AP_Motors6DOF.cpp index 951ecabbcbb7b..239544f9685bd 100644 --- a/libraries/AP_Motors/AP_Motors6DOF.cpp +++ b/libraries/AP_Motors/AP_Motors6DOF.cpp @@ -359,6 +359,7 @@ void AP_Motors6DOF::output_armed_stabilizing() } } +#if AP_BATTERY_ENABLED const AP_BattMonitor &battery = AP::battery(); // Current limiting @@ -384,6 +385,7 @@ void AP_Motors6DOF::output_armed_stabilizing() batt_current_ratio = predicted_current_ratio; } _output_limited += (_dt / (_dt + _batt_current_time_constant)) * (1 - batt_current_ratio); +#endif _output_limited = constrain_float(_output_limited, 0.0f, 1.0f); diff --git a/libraries/AP_Motors/AP_MotorsMulticopter.cpp b/libraries/AP_Motors/AP_MotorsMulticopter.cpp index cc7eb0fd3e7f7..e68cf85c8208a 100644 --- a/libraries/AP_Motors/AP_MotorsMulticopter.cpp +++ b/libraries/AP_Motors/AP_MotorsMulticopter.cpp @@ -345,6 +345,7 @@ void AP_MotorsMulticopter::update_throttle_filter() // return current_limit as a number from 0 ~ 1 in the range throttle_min to throttle_max float AP_MotorsMulticopter::get_current_limit_max_throttle() { +#if AP_BATTERY_ENABLED AP_BattMonitor &battery = AP::battery(); const uint8_t batt_idx = thr_lin.get_battery_index(); @@ -376,6 +377,9 @@ float AP_MotorsMulticopter::get_current_limit_max_throttle() // limit max throttle return get_throttle_hover() + ((1.0 - get_throttle_hover()) * _throttle_limit); +#else + return 1.0; +#endif } #if HAL_LOGGING_ENABLED diff --git a/libraries/AP_Motors/AP_Motors_Thrust_Linearization.cpp b/libraries/AP_Motors/AP_Motors_Thrust_Linearization.cpp index 92d4f800c9b67..ff2114864a455 100644 --- a/libraries/AP_Motors/AP_Motors_Thrust_Linearization.cpp +++ b/libraries/AP_Motors/AP_Motors_Thrust_Linearization.cpp @@ -151,6 +151,7 @@ float Thrust_Linearization::remove_thrust_curve_and_volt_scaling(float throttle) // update_lift_max from battery voltage - used for voltage compensation void Thrust_Linearization::update_lift_max_from_batt_voltage() { +#if AP_BATTERY_ENABLED // sanity check battery_voltage_min is not too small // if disabled or misconfigured exit immediately float _batt_voltage = motors.has_option(AP_Motors::MotorOptions::BATT_RAW_VOLTAGE) ? AP::battery().voltage(batt_idx) : AP::battery().voltage_resting_estimate(batt_idx); @@ -177,6 +178,7 @@ void Thrust_Linearization::update_lift_max_from_batt_voltage() // calculate lift max float thrust_curve_expo = constrain_float(curve_expo, -1.0, 1.0); lift_max = batt_voltage_filt.get() * (1 - thrust_curve_expo) + thrust_curve_expo * batt_voltage_filt.get() * batt_voltage_filt.get(); +#endif } // return gain scheduling gain based on voltage and air density From f9a6dd7445a3e324676b864e2ab2e1f08cf71013 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 22:07:24 +1100 Subject: [PATCH 10/12] AP_OSD: add and use AP_BATTERY_ENABLED --- libraries/AP_OSD/AP_OSD_Screen.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/AP_OSD/AP_OSD_Screen.cpp b/libraries/AP_OSD/AP_OSD_Screen.cpp index 53cb8ce8e50f1..1309707f9c2a9 100644 --- a/libraries/AP_OSD/AP_OSD_Screen.cpp +++ b/libraries/AP_OSD/AP_OSD_Screen.cpp @@ -1334,6 +1334,7 @@ void AP_OSD_Screen::draw_altitude(uint8_t x, uint8_t y) backend->write(x, y, false, "%4d%c", (int)u_scale(ALTITUDE, alt), u_icon(ALTITUDE)); } +#if AP_BATTERY_ENABLED void AP_OSD_Screen::draw_bat_volt(uint8_t instance, VoltageType type, uint8_t x, uint8_t y) { AP_BattMonitor &battery = AP::battery(); @@ -1409,6 +1410,7 @@ void AP_OSD_Screen::draw_restvolt(uint8_t x, uint8_t y) { draw_bat_volt(0,VoltageType::RESTING_VOLTAGE,x,y); } +#endif // AP_BATTERY_ENABLED #if AP_RSSI_ENABLED void AP_OSD_Screen::draw_rssi(uint8_t x, uint8_t y) @@ -1434,6 +1436,7 @@ void AP_OSD_Screen::draw_link_quality(uint8_t x, uint8_t y) } #endif // AP_RSSI_ENABLED +#if AP_BATTERY_ENABLED void AP_OSD_Screen::draw_current(uint8_t instance, uint8_t x, uint8_t y) { float amps; @@ -1454,6 +1457,7 @@ void AP_OSD_Screen::draw_current(uint8_t x, uint8_t y) { draw_current(0, x, y); } +#endif void AP_OSD_Screen::draw_fltmode(uint8_t x, uint8_t y) { @@ -1477,6 +1481,7 @@ void AP_OSD_Screen::draw_sats(uint8_t x, uint8_t y) backend->write(x, y, flash, "%c%c%2u", SYMBOL(SYM_SAT_L), SYMBOL(SYM_SAT_R), nsat); } +#if AP_BATTERY_ENABLED void AP_OSD_Screen::draw_batused(uint8_t instance, uint8_t x, uint8_t y) { float mah; @@ -1495,6 +1500,7 @@ void AP_OSD_Screen::draw_batused(uint8_t x, uint8_t y) { draw_batused(0, x, y); } +#endif //Autoscroll message is the same as in minimosd-extra. //Thanks to night-ghost for the approach. @@ -2035,6 +2041,7 @@ void AP_OSD_Screen::draw_flightime(uint8_t x, uint8_t y) } } +#if AP_BATTERY_ENABLED void AP_OSD_Screen::draw_eff(uint8_t x, uint8_t y) { AP_BattMonitor &battery = AP::battery(); @@ -2052,7 +2059,9 @@ void AP_OSD_Screen::draw_eff(uint8_t x, uint8_t y) backend->write(x, y, false, "%c---%c", SYMBOL(SYM_EFF),SYMBOL(SYM_MAH)); } } +#endif // AP_BATTERY_ENABLED +#if AP_BATTERY_ENABLED void AP_OSD_Screen::draw_climbeff(uint8_t x, uint8_t y) { char unit_icon = u_icon(DISTANCE); @@ -2082,6 +2091,7 @@ void AP_OSD_Screen::draw_climbeff(uint8_t x, uint8_t y) backend->write(x, y, false,"%c%c---%c",SYMBOL(SYM_PTCHUP),SYMBOL(SYM_EFF),unit_icon); } } +#endif #if BARO_MAX_INSTANCES > 1 void AP_OSD_Screen::draw_btemp(uint8_t x, uint8_t y) From f58a9806cdf067e10c8b580b2367f2a590c0e953 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 22:07:24 +1100 Subject: [PATCH 11/12] AP_Scripting: add and use AP_BATTERY_ENABLED --- libraries/AP_Scripting/generator/description/bindings.desc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/AP_Scripting/generator/description/bindings.desc b/libraries/AP_Scripting/generator/description/bindings.desc index 0f4194a9bc8ab..0eee97bf20d50 100644 --- a/libraries/AP_Scripting/generator/description/bindings.desc +++ b/libraries/AP_Scripting/generator/description/bindings.desc @@ -90,7 +90,7 @@ userdata BattMonitorScript_State field consumed_wh float'skip_check write userdata BattMonitorScript_State field temperature float'skip_check write singleton AP_BattMonitor rename battery -singleton AP_BattMonitor depends (!defined(HAL_BUILD_AP_PERIPH) || defined(HAL_PERIPH_ENABLE_BATTERY)) +singleton AP_BattMonitor depends AP_BATTERY_ENABLED singleton AP_BattMonitor method num_instances uint8_t singleton AP_BattMonitor method healthy boolean uint8_t 0 ud->num_instances() singleton AP_BattMonitor method voltage float uint8_t 0 ud->num_instances() From cb45439b46795d67d072034568b841486a1fe54e Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 31 Jan 2024 22:07:24 +1100 Subject: [PATCH 12/12] RC_Channel: add and use AP_BATTERY_ENABLED --- libraries/RC_Channel/RC_Channel.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/RC_Channel/RC_Channel.cpp b/libraries/RC_Channel/RC_Channel.cpp index 296afb878ba85..ef80a7ab849cf 100644 --- a/libraries/RC_Channel/RC_Channel.cpp +++ b/libraries/RC_Channel/RC_Channel.cpp @@ -1319,11 +1319,13 @@ bool RC_Channel::do_aux_function(const aux_func_t ch_option, const AuxSwitchPos break; #endif +#if AP_BATTERY_ENABLED case AUX_FUNC::BATTERY_MPPT_ENABLE: if (ch_flag != AuxSwitchPos::MIDDLE) { AP::battery().MPPT_set_powered_state_to_all(ch_flag == AuxSwitchPos::HIGH); } break; +#endif #if HAL_SPRAYER_ENABLED case AUX_FUNC::SPRAYER: