Make all battery sensor drivers report their sample interval

To make use of the time abstraction in the leaky integrator.
This commit is contained in:
Matthias Grob
2020-05-25 11:04:24 +02:00
parent 4dc9ca69ab
commit 88c21337fa
14 changed files with 48 additions and 22 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ INA226::INA226(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int
_comms_errors(perf_alloc(PC_COUNT, "ina226_com_err")),
_collection_errors(perf_alloc(PC_COUNT, "ina226_collection_err")),
_measure_errors(perf_alloc(PC_COUNT, "ina226_measurement_err")),
_battery(battery_index, this)
_battery(battery_index, this, INA226_SAMPLE_INTERVAL_US)
{
float fvalue = MAX_CURRENT;
_max_current = fvalue;
+6 -2
View File
@@ -13,6 +13,8 @@
#include <uORB/topics/parameter_update.h>
#include <px4_platform_common/i2c_spi_buses.h>
using namespace time_literals;
/* Configuration Constants */
#define INA226_BASEADDR 0x41 /* 7-bit address. 8-bit address is 0x41 */
// If initialization is forced (with the -f flag on the command line), but it fails, the drive will try again to
@@ -98,7 +100,9 @@
#define INA226_SUL (1 << 14)
#define INA226_SOL (1 << 15)
#define INA226_CONVERSION_INTERVAL (100000-7) /* 100 ms / 10 Hz */
#define INA226_SAMPLE_FREQUENCY_HZ 10
#define INA226_SAMPLE_INTERVAL_US (1_s / INA226_SAMPLE_FREQUENCY_HZ)
#define INA226_CONVERSION_INTERVAL (INA226_SAMPLE_INTERVAL_US - 7)
#define MAX_CURRENT 164.0f /* 164 Amps */
#define DN_MAX 32768.0f /* 2^15 */
#define INA226_CONST 0.00512f /* is an internal fixed value used to ensure scaling is maintained properly */
@@ -139,7 +143,7 @@ protected:
private:
bool _sensor_ok{false};
int _measure_interval{0};
unsigned _measure_interval{0};
bool _collect_phase{false};
bool _initialized{false};
+3 -3
View File
@@ -50,7 +50,7 @@ VOXLPM::VOXLPM(I2CSPIBusOption bus_option, const int bus, int bus_frequency, VOX
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": sample")),
_ch_type(ch_type),
_battery(1, this)
_battery(1, this, _meas_interval_us)
{
if (_ch_type == VOXLPM_CH_TYPE_VBATT) {
_rsense = VOXLPM_RSENSE_VBATT;
@@ -100,13 +100,13 @@ VOXLPM::print_status()
printf(" - voltage: %9.2f VDC \n", (double)_voltage);
printf(" - current: %9.2f ADC \n", (double)_amperage);
printf(" - rsense: %9.6f ohm \n", (double)_rsense);
printf(" - meas interval: %u us \n", _meas_interval);
printf(" - meas interval: %u us \n", _meas_interval_us);
}
void
VOXLPM::start()
{
ScheduleOnInterval(_meas_interval, 1000);
ScheduleOnInterval(_meas_interval_us, 1000);
}
void
+3 -1
View File
@@ -73,6 +73,8 @@
#include <uORB/topics/power_monitor.h>
#include <uORB/topics/parameter_update.h>
using namespace time_literals;
/*
* Note that these are unshifted addresses.
*/
@@ -162,7 +164,7 @@ private:
void start();
int measure();
static constexpr unsigned _meas_interval{100000}; // 100ms
static constexpr unsigned _meas_interval_us{100_ms};
perf_counter_t _sample_perf;
uORB::PublicationMulti<power_monitor_s> _pm_pub_topic{ORB_ID(power_monitor)};