mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 09:23:33 +08:00
battery: pass voltage and current by setter
This commit is contained in:
@@ -84,11 +84,9 @@ INA226::INA226(const I2CSPIDriverConfig &config, int battery_index) :
|
||||
|
||||
// We need to publish immediately, to guarantee that the first instance of the driver publishes to uORB instance 0
|
||||
_battery.setConnected(false);
|
||||
_battery.updateBatteryStatus(
|
||||
hrt_absolute_time(),
|
||||
0.0,
|
||||
0.0
|
||||
);
|
||||
_battery.updateVoltage(0.f);
|
||||
_battery.updateCurrent(0.f);
|
||||
_battery.updateBatteryStatus(hrt_absolute_time());
|
||||
}
|
||||
|
||||
INA226::~INA226()
|
||||
@@ -229,11 +227,9 @@ INA226::collect()
|
||||
}
|
||||
|
||||
_battery.setConnected(success);
|
||||
_battery.updateBatteryStatus(
|
||||
hrt_absolute_time(),
|
||||
(float) _bus_voltage * INA226_VSCALE,
|
||||
(float) _current * _current_lsb
|
||||
);
|
||||
_battery.updateVoltage(static_cast<float>(_bus_voltage * INA226_VSCALE));
|
||||
_battery.updateCurrent(static_cast<float>(_current * _current_lsb));
|
||||
_battery.updateBatteryStatus(hrt_absolute_time());
|
||||
|
||||
perf_end(_sample_perf);
|
||||
|
||||
@@ -297,11 +293,9 @@ INA226::RunImpl()
|
||||
|
||||
} else {
|
||||
_battery.setConnected(false);
|
||||
_battery.updateBatteryStatus(
|
||||
hrt_absolute_time(),
|
||||
0.0f,
|
||||
0.0f
|
||||
);
|
||||
_battery.updateVoltage(0.f);
|
||||
_battery.updateCurrent(0.f);
|
||||
_battery.updateBatteryStatus(hrt_absolute_time());
|
||||
|
||||
if (init() != PX4_OK) {
|
||||
ScheduleDelayed(INA226_INIT_RETRY_INTERVAL_US);
|
||||
|
||||
@@ -86,11 +86,9 @@ INA228::INA228(const I2CSPIDriverConfig &config, int battery_index) :
|
||||
|
||||
// We need to publish immediately, to guarantee that the first instance of the driver publishes to uORB instance 0
|
||||
_battery.setConnected(false);
|
||||
_battery.updateBatteryStatus(
|
||||
hrt_absolute_time(),
|
||||
0.0,
|
||||
0.0
|
||||
);
|
||||
_battery.updateVoltage(0.f);
|
||||
_battery.updateCurrent(0.f);
|
||||
_battery.updateBatteryStatus(hrt_absolute_time());
|
||||
}
|
||||
|
||||
INA228::~INA228()
|
||||
@@ -310,11 +308,9 @@ INA228::collect()
|
||||
}
|
||||
|
||||
_battery.setConnected(success);
|
||||
_battery.updateBatteryStatus(
|
||||
hrt_absolute_time(),
|
||||
(float) _bus_voltage * INA228_VSCALE,
|
||||
(float) _current * _current_lsb
|
||||
);
|
||||
_battery.updateVoltage(static_cast<float>(_bus_voltage * INA228_VSCALE));
|
||||
_battery.updateCurrent(static_cast<float>(_current * _current_lsb));
|
||||
_battery.updateBatteryStatus(hrt_absolute_time());
|
||||
|
||||
perf_end(_sample_perf);
|
||||
|
||||
@@ -378,11 +374,9 @@ INA228::RunImpl()
|
||||
|
||||
} else {
|
||||
_battery.setConnected(false);
|
||||
_battery.updateBatteryStatus(
|
||||
hrt_absolute_time(),
|
||||
0.0f,
|
||||
0.0f
|
||||
);
|
||||
_battery.updateVoltage(0.f);
|
||||
_battery.updateCurrent(0.f);
|
||||
_battery.updateBatteryStatus(hrt_absolute_time());
|
||||
|
||||
if (init() != PX4_OK) {
|
||||
ScheduleDelayed(INA228_INIT_RETRY_INTERVAL_US);
|
||||
|
||||
@@ -69,11 +69,9 @@ INA238::INA238(const I2CSPIDriverConfig &config, int battery_index) :
|
||||
|
||||
// We need to publish immediately, to guarantee that the first instance of the driver publishes to uORB instance 0
|
||||
_battery.setConnected(false);
|
||||
_battery.updateBatteryStatus(
|
||||
hrt_absolute_time(),
|
||||
0.0,
|
||||
0.0
|
||||
);
|
||||
_battery.updateVoltage(0.f);
|
||||
_battery.updateCurrent(0.f);
|
||||
_battery.updateBatteryStatus(hrt_absolute_time());
|
||||
}
|
||||
|
||||
INA238::~INA238()
|
||||
@@ -197,11 +195,9 @@ int INA238::collect()
|
||||
}
|
||||
|
||||
_battery.setConnected(success);
|
||||
_battery.updateBatteryStatus(
|
||||
hrt_absolute_time(),
|
||||
(float) bus_voltage * INA238_VSCALE,
|
||||
(float) current * _current_lsb
|
||||
);
|
||||
_battery.updateVoltage(static_cast<float>(bus_voltage * INA238_VSCALE));
|
||||
_battery.updateCurrent(static_cast<float>(current * _current_lsb));
|
||||
_battery.updateBatteryStatus(hrt_absolute_time());
|
||||
|
||||
perf_end(_sample_perf);
|
||||
|
||||
@@ -256,11 +252,9 @@ void INA238::RunImpl()
|
||||
|
||||
} else {
|
||||
_battery.setConnected(false);
|
||||
_battery.updateBatteryStatus(
|
||||
hrt_absolute_time(),
|
||||
0.0f,
|
||||
0.0f
|
||||
);
|
||||
_battery.updateVoltage(0.f);
|
||||
_battery.updateCurrent(0.f);
|
||||
_battery.updateBatteryStatus(hrt_absolute_time());
|
||||
|
||||
if (init() != PX4_OK) {
|
||||
ScheduleDelayed(INA238_INIT_RETRY_INTERVAL_US);
|
||||
|
||||
@@ -72,11 +72,9 @@ VOXLPM::init()
|
||||
|
||||
if (_ch_type == VOXLPM_CH_TYPE_VBATT) {
|
||||
_battery.setConnected(false);
|
||||
_battery.updateBatteryStatus(
|
||||
hrt_absolute_time(),
|
||||
0.0,
|
||||
0.0
|
||||
);
|
||||
_battery.updateVoltage(0.f);
|
||||
_battery.updateCurrent(0.f);
|
||||
_battery.updateBatteryStatus(hrt_absolute_time());
|
||||
}
|
||||
|
||||
/* do I2C init, it will probe the bus for two possible configurations, LTC2946 or INA231 */
|
||||
@@ -345,9 +343,9 @@ VOXLPM::measure()
|
||||
case VOXLPM_CH_TYPE_VBATT: {
|
||||
|
||||
_battery.setConnected(true);
|
||||
_battery.updateBatteryStatus(tnow,
|
||||
_voltage,
|
||||
_amperage);
|
||||
_battery.updateVoltage(_voltage);
|
||||
_battery.updateCurrent(_amperage);
|
||||
_battery.updateBatteryStatus(tnow);
|
||||
}
|
||||
|
||||
// fallthrough
|
||||
@@ -371,9 +369,9 @@ VOXLPM::measure()
|
||||
switch (_ch_type) {
|
||||
case VOXLPM_CH_TYPE_VBATT: {
|
||||
_battery.setConnected(true);
|
||||
_battery.updateBatteryStatus(tnow,
|
||||
0.0,
|
||||
0.0);
|
||||
_battery.updateVoltage(0.f);
|
||||
_battery.updateCurrent(0.f);
|
||||
_battery.updateBatteryStatus(tnow);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user