mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 23:43: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:
@@ -81,6 +81,8 @@
|
||||
#include <v2.0/mavlink_types.h>
|
||||
#include <lib/battery/battery.h>
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
//! Enumeration to use on the bitmask in HIL_SENSOR
|
||||
enum class SensorSource {
|
||||
ACCEL = 0b111,
|
||||
@@ -193,7 +195,10 @@ private:
|
||||
class SimulatorBattery : public Battery
|
||||
{
|
||||
public:
|
||||
SimulatorBattery() : Battery(1, nullptr) {}
|
||||
static constexpr uint32_t SIMLATOR_BATTERY_SAMPLE_FREQUENCY_HZ = 100; // Hz
|
||||
static constexpr uint32_t SIMLATOR_BATTERY_SAMPLE_INTERVAL_US = 1_s / SIMLATOR_BATTERY_SAMPLE_FREQUENCY_HZ;
|
||||
|
||||
SimulatorBattery() : Battery(1, nullptr, SIMLATOR_BATTERY_SAMPLE_INTERVAL_US) {}
|
||||
|
||||
virtual void updateParams() override
|
||||
{
|
||||
|
||||
@@ -350,7 +350,7 @@ void Simulator::handle_message_hil_sensor(const mavlink_message_t *msg)
|
||||
static uint64_t last_integration_us = 0;
|
||||
|
||||
// battery simulation (limit update to 100Hz)
|
||||
if (hrt_elapsed_time(&_last_battery_timestamp) >= 10_ms) {
|
||||
if (hrt_elapsed_time(&_last_battery_timestamp) >= SimulatorBattery::SIMLATOR_BATTERY_SAMPLE_INTERVAL_US) {
|
||||
|
||||
const float discharge_interval_us = _param_sim_bat_drain.get() * 1000 * 1000;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user