mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 08:53:34 +08:00
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:
@@ -15,8 +15,8 @@ static constexpr int DEFAULT_V_CHANNEL[1] = {0};
|
||||
static constexpr int DEFAULT_I_CHANNEL[1] = {0};
|
||||
#endif
|
||||
|
||||
AnalogBattery::AnalogBattery(int index, ModuleParams *parent) :
|
||||
Battery(index, parent)
|
||||
AnalogBattery::AnalogBattery(int index, ModuleParams *parent, const int sample_interval_us) :
|
||||
Battery(index, parent, sample_interval_us)
|
||||
{
|
||||
char param_name[17];
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
class AnalogBattery : public Battery
|
||||
{
|
||||
public:
|
||||
AnalogBattery(int index, ModuleParams *parent);
|
||||
AnalogBattery(int index, ModuleParams *parent, const int sample_interval_us);
|
||||
|
||||
/**
|
||||
* Update current battery status message.
|
||||
|
||||
@@ -103,6 +103,9 @@ private:
|
||||
uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; /**< notification of parameter updates */
|
||||
uORB::Subscription _adc_report_sub{ORB_ID(adc_report)};
|
||||
|
||||
static constexpr uint32_t SAMPLE_FREQUENCY_HZ = 100;
|
||||
static constexpr uint32_t SAMPLE_INTERVAL_US = 1_s / SAMPLE_FREQUENCY_HZ;
|
||||
|
||||
AnalogBattery _battery1;
|
||||
|
||||
#if BOARD_NUMBER_BRICKS > 1
|
||||
@@ -135,9 +138,9 @@ private:
|
||||
BatteryStatus::BatteryStatus() :
|
||||
ModuleParams(nullptr),
|
||||
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::hp_default),
|
||||
_battery1(1, this),
|
||||
_battery1(1, this, SAMPLE_INTERVAL_US),
|
||||
#if BOARD_NUMBER_BRICKS > 1
|
||||
_battery2(2, this),
|
||||
_battery2(2, this, SAMPLE_INTERVAL_US),
|
||||
#endif
|
||||
_loop_perf(perf_alloc(PC_ELAPSED, MODULE_NAME))
|
||||
{
|
||||
@@ -277,7 +280,7 @@ BatteryStatus::task_spawn(int argc, char *argv[])
|
||||
bool
|
||||
BatteryStatus::init()
|
||||
{
|
||||
ScheduleOnInterval(10_ms); // 100 Hz
|
||||
ScheduleOnInterval(SAMPLE_INTERVAL_US);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user