|
|
@ -17,7 +17,9 @@ |
|
|
|
#include <AP_HAL/AP_HAL.h> |
|
|
|
#include <AP_HAL/AP_HAL.h> |
|
|
|
#include "AP_BattMonitor.h" |
|
|
|
#include "AP_BattMonitor.h" |
|
|
|
#include "AP_BattMonitor_Backend.h" |
|
|
|
#include "AP_BattMonitor_Backend.h" |
|
|
|
|
|
|
|
#include <GCS_MAVLink/GCS.h> |
|
|
|
|
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h> |
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
base class constructor. |
|
|
|
base class constructor. |
|
|
|
This incorporates initialisation as well. |
|
|
|
This incorporates initialisation as well. |
|
|
@ -167,6 +169,10 @@ bool AP_BattMonitor_Backend::arming_checks(char * buffer, size_t buflen) const |
|
|
|
bool fs_voltage_inversion = is_positive(_params._critical_voltage) && |
|
|
|
bool fs_voltage_inversion = is_positive(_params._critical_voltage) && |
|
|
|
is_positive(_params._low_voltage) && |
|
|
|
is_positive(_params._low_voltage) && |
|
|
|
(_params._low_voltage < _params._critical_voltage); |
|
|
|
(_params._low_voltage < _params._critical_voltage); |
|
|
|
|
|
|
|
uint8_t cell_min_index; |
|
|
|
|
|
|
|
uint8_t cell_max_index; |
|
|
|
|
|
|
|
uint16_t dropout_voltage; |
|
|
|
|
|
|
|
bool fs_cells_dropout_voltage = cells_dropout_voltage_checks(cell_min_index,cell_max_index,dropout_voltage); |
|
|
|
|
|
|
|
|
|
|
|
bool result = update_check(buflen, buffer, low_voltage, "low voltage failsafe"); |
|
|
|
bool result = update_check(buflen, buffer, low_voltage, "low voltage failsafe"); |
|
|
|
result = result && update_check(buflen, buffer, low_capacity, "low capacity failsafe"); |
|
|
|
result = result && update_check(buflen, buffer, low_capacity, "low capacity failsafe"); |
|
|
@ -176,7 +182,9 @@ bool AP_BattMonitor_Backend::arming_checks(char * buffer, size_t buflen) const |
|
|
|
result = result && update_check(buflen, buffer, below_arming_capacity, "below minimum arming capacity"); |
|
|
|
result = result && update_check(buflen, buffer, below_arming_capacity, "below minimum arming capacity"); |
|
|
|
result = result && update_check(buflen, buffer, fs_capacity_inversion, "capacity failsafe critical > low"); |
|
|
|
result = result && update_check(buflen, buffer, fs_capacity_inversion, "capacity failsafe critical > low"); |
|
|
|
result = result && update_check(buflen, buffer, fs_voltage_inversion, "voltage failsafe critical > low"); |
|
|
|
result = result && update_check(buflen, buffer, fs_voltage_inversion, "voltage failsafe critical > low"); |
|
|
|
|
|
|
|
// char bat_message[60];
|
|
|
|
|
|
|
|
// snprintf(bat_message,60,"电池压差过大,%d号与%d号电芯,压差 %f V",cell_max_index,cell_min_index,dropout_voltage/1000.0);
|
|
|
|
|
|
|
|
result = result && update_check(buflen, buffer, fs_cells_dropout_voltage,"电池压差过大"); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -245,3 +253,35 @@ bool AP_BattMonitor_Backend::reset_remaining(float percentage) |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool AP_BattMonitor_Backend::cells_dropout_voltage_checks(uint8_t &cell_min_index, uint8_t &cell_max_index, uint16_t &dropout_voltage) const |
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (has_cell_voltages()&&(_params._arming_dropout_voltage>0)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
uint16_t cell_min = 65535; |
|
|
|
|
|
|
|
uint16_t cell_max = 0; |
|
|
|
|
|
|
|
for (int k = 0; k < MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_LEN; k++) |
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((_state.cell_voltages.cells[k]!=65535) && _state.cell_voltages.cells[k] != 0) //TODO if valid cell valtage =0
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (_state.cell_voltages.cells[k] < cell_min) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
cell_min = _state.cell_voltages.cells[k]; |
|
|
|
|
|
|
|
cell_min_index = k + 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_state.cell_voltages.cells[k] > cell_max) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
cell_max = _state.cell_voltages.cells[k]; |
|
|
|
|
|
|
|
cell_max_index = k + 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dropout_voltage = abs(cell_max - cell_min); |
|
|
|
|
|
|
|
if ((dropout_voltage/1000.0) >= _params._arming_dropout_voltage) //0.1v
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|