AP_BattMonitor: Record and report UAVCAN Battery Info temperature correctly
This commit is contained in:
parent
c71163680f
commit
89e4df485a
@ -87,11 +87,16 @@ AP_BattMonitor_UAVCAN* AP_BattMonitor_UAVCAN::get_uavcan_backend(AP_UAVCAN* ap_u
|
||||
void AP_BattMonitor_UAVCAN::handle_battery_info(const BattInfoCb &cb)
|
||||
{
|
||||
WITH_SEMAPHORE(_sem_battmon);
|
||||
_interim_state.temperature = cb.msg->temperature;
|
||||
_interim_state.voltage = cb.msg->voltage;
|
||||
_interim_state.current_amps = cb.msg->current;
|
||||
_soc = cb.msg->state_of_charge_pct;
|
||||
|
||||
if (!isnanf(cb.msg->temperature) && cb.msg->temperature > 0) {
|
||||
// Temperature reported from battery in kelvin and stored internally in Celsius.
|
||||
_interim_state.temperature = cb.msg->temperature - C_TO_KELVIN;
|
||||
_interim_state.temperature_time = AP_HAL::millis();
|
||||
}
|
||||
|
||||
uint32_t tnow = AP_HAL::micros();
|
||||
uint32_t dt = tnow - _interim_state.last_time_micros;
|
||||
|
||||
@ -130,12 +135,15 @@ void AP_BattMonitor_UAVCAN::read()
|
||||
// Copy over relevant states over to main state
|
||||
WITH_SEMAPHORE(_sem_battmon);
|
||||
_state.temperature = _interim_state.temperature;
|
||||
_state.temperature_time = _interim_state.temperature_time;
|
||||
_state.voltage = _interim_state.voltage;
|
||||
_state.current_amps = _interim_state.current_amps;
|
||||
_state.consumed_mah = _interim_state.consumed_mah;
|
||||
_state.consumed_wh = _interim_state.consumed_wh;
|
||||
_state.last_time_micros = _interim_state.last_time_micros;
|
||||
_state.healthy = _interim_state.healthy;
|
||||
|
||||
_has_temperature = (AP_HAL::millis() - _state.temperature_time) <= AP_BATT_MONITOR_TIMEOUT;
|
||||
}
|
||||
|
||||
/// capacity_remaining_pct - returns the % battery capacity remaining (0 ~ 100)
|
||||
|
@ -27,6 +27,8 @@ public:
|
||||
/// capacity_remaining_pct - returns the % battery capacity remaining (0 ~ 100)
|
||||
uint8_t capacity_remaining_pct() const override;
|
||||
|
||||
bool has_temperature() const override { return _has_temperature; }
|
||||
|
||||
bool has_current() const override {
|
||||
return true;
|
||||
}
|
||||
@ -51,4 +53,5 @@ private:
|
||||
AP_UAVCAN* _ap_uavcan;
|
||||
uint8_t _node_id;
|
||||
uint8_t _soc;
|
||||
bool _has_temperature;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user