mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 00:43:33 +08:00
battery: pass voltage and current by setter
This commit is contained in:
@@ -97,16 +97,26 @@ Battery::Battery(int index, ModuleParams *parent, const int sample_interval_us,
|
||||
updateParams();
|
||||
}
|
||||
|
||||
void Battery::updateBatteryStatus(const hrt_abstime ×tamp, float voltage_v, float current_a)
|
||||
void Battery::updateVoltage(const float voltage_v)
|
||||
{
|
||||
_voltage_v = voltage_v;
|
||||
_voltage_filter_v.update(voltage_v);
|
||||
}
|
||||
|
||||
void Battery::updateCurrent(const float current_a)
|
||||
{
|
||||
_current_a = current_a;
|
||||
_current_filter_a.update(current_a);
|
||||
}
|
||||
|
||||
void Battery::updateBatteryStatus(const hrt_abstime ×tamp)
|
||||
{
|
||||
if (!_battery_initialized) {
|
||||
_voltage_filter_v.reset(voltage_v);
|
||||
_current_filter_a.reset(current_a);
|
||||
_voltage_filter_v.reset(_voltage_v);
|
||||
_current_filter_a.reset(_current_a);
|
||||
}
|
||||
|
||||
_voltage_filter_v.update(voltage_v);
|
||||
_current_filter_a.update(current_a);
|
||||
sumDischarged(timestamp, current_a);
|
||||
sumDischarged(timestamp, _current_a);
|
||||
estimateStateOfCharge(_voltage_filter_v.getState(), _current_filter_a.getState());
|
||||
computeScale();
|
||||
|
||||
@@ -122,15 +132,15 @@ void Battery::updateBatteryStatus(const hrt_abstime ×tamp, float voltage_v,
|
||||
}
|
||||
|
||||
battery_status_s battery_status{};
|
||||
battery_status.voltage_v = voltage_v;
|
||||
battery_status.voltage_v = _voltage_v;
|
||||
battery_status.voltage_filtered_v = _voltage_filter_v.getState();
|
||||
battery_status.current_a = current_a;
|
||||
battery_status.current_a = _current_a;
|
||||
battery_status.current_filtered_a = _current_filter_a.getState();
|
||||
battery_status.current_average_a = _current_average_filter_a.getState();
|
||||
battery_status.discharged_mah = _discharged_mah;
|
||||
battery_status.remaining = _state_of_charge;
|
||||
battery_status.scale = _scale;
|
||||
battery_status.time_remaining_s = computeRemainingTime(current_a);
|
||||
battery_status.time_remaining_s = computeRemainingTime(_current_a);
|
||||
battery_status.temperature = NAN;
|
||||
battery_status.cell_count = _params.n_cells;
|
||||
battery_status.connected = _connected;
|
||||
|
||||
@@ -87,15 +87,15 @@ public:
|
||||
|
||||
void setPriority(const uint8_t priority) { _priority = priority; }
|
||||
void setConnected(const bool connected) { _connected = connected; }
|
||||
void updateVoltage(const float voltage_v);
|
||||
void updateCurrent(const float current_a);
|
||||
|
||||
/**
|
||||
* Update current battery status message.
|
||||
*
|
||||
* @param voltage_raw: Battery voltage, in Volts
|
||||
* @param current_raw: Battery current, in Amps
|
||||
* @param timestamp: Time at which the ADC was read (use hrt_absolute_time())
|
||||
*/
|
||||
void updateBatteryStatus(const hrt_abstime ×tamp, float voltage_v, float current_a);
|
||||
void updateBatteryStatus(const hrt_abstime ×tamp);
|
||||
|
||||
protected:
|
||||
struct {
|
||||
@@ -143,7 +143,9 @@ private:
|
||||
const uint8_t _source{};
|
||||
uint8_t _priority{0};
|
||||
bool _battery_initialized{false};
|
||||
float _voltage_v{0.f};
|
||||
AlphaFilter<float> _voltage_filter_v;
|
||||
float _current_a{-1};
|
||||
AlphaFilter<float> _current_filter_a;
|
||||
AlphaFilter<float> _current_average_filter_a;
|
||||
AlphaFilter<float> _throttle_filter;
|
||||
|
||||
Reference in New Issue
Block a user