Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
SW-97
  • Loading branch information
loki077 committed Mar 7, 2024
1 parent 7ae28b6 commit 82a550f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
23 changes: 19 additions & 4 deletions libraries/AP_BattMonitor/AP_BattMonitor_ESC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ void AP_BattMonitor_ESC::read(void)
uint8_t voltage_escs = 0; // number of ESCs with valid voltage
uint8_t temperature_escs = 0; // number of ESCs with valid temperature
float voltage_sum = 0;
float voltage_min = 0;
float current_sum = 0;
float temperature_sum = 0;
uint32_t highest_ms = 0;
_state.consumed_mah = delta_mah;


const uint32_t options = uint32_t(_params._options.get());
const bool esc_min_volt_enabled = (options & uint32_t(AP_BattMonitor_Params::Options::ESC_Minimum_Voltage)) != 0;

for (uint8_t i=0; i<ESC_TELEM_MAX_ESCS; i++) {
int16_t temperature_cdeg;
float voltage;
Expand All @@ -50,8 +54,15 @@ void AP_BattMonitor_ESC::read(void)
}

if (telem.get_voltage(i, voltage)) {
voltage_sum += voltage;
voltage_escs++;
if (esc_min_volt_enabled) {
if (voltage_min > voltage) {
voltage_min = voltage;
}
}
else {
voltage_sum += voltage;
voltage_escs++;
}
}

if (telem.get_current(i, current)) {
Expand All @@ -69,7 +80,11 @@ void AP_BattMonitor_ESC::read(void)
}

if (voltage_escs > 0) {
_state.voltage = voltage_sum / voltage_escs;
if (esc_min_volt_enabled) {
_state.voltage = voltage_min;
} else {
_state.voltage = voltage_sum / voltage_escs;
}
_state.healthy = true;
} else {
_state.voltage = 0;
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_BattMonitor/AP_BattMonitor_Params.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AP_BattMonitor_Params {
MPPT_Power_Off_At_Boot = (1U<<4), // MPPT Disabled at startup (aka boot), if HW supports it
MPPT_Power_On_At_Boot = (1U<<5), // MPPT Enabled at startup (aka boot), if HW supports it. If Power_Off_at_Boot is also set, the behavior is Power_Off_at_Boot
GCS_Resting_Voltage = (1U<<6), // send resistance resting voltage to GCS
ESC_Minimum_Voltage = (1U<<7), // send minimum Voltage of ESC rather than average
};

BattMonitor_LowVoltage_Source failsafe_voltage_source(void) const { return (enum BattMonitor_LowVoltage_Source)_failsafe_voltage_source.get(); }
Expand Down

0 comments on commit 82a550f

Please sign in to comment.