Created new AnalogBattery class

This commit is contained in:
Timothy Scott
2019-12-05 16:38:04 +01:00
committed by Julian Oes
parent bff1df7080
commit d7bb5d46bb
20 changed files with 687 additions and 253 deletions
+18 -6
View File
@@ -42,7 +42,7 @@
#pragma once
#include <battery/battery.h>
#include <battery/battery_base.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_rc_input.h>
#include <lib/drivers/accelerometer/PX4Accelerometer.hpp>
@@ -183,8 +183,6 @@ private:
_gps.writeData(&gps_data);
_battery_status.timestamp = hrt_absolute_time();
_px4_accel.set_sample_rate(250);
_px4_gyro.set_sample_rate(250);
}
@@ -237,10 +235,24 @@ private:
hrt_abstime _last_sim_timestamp{0};
hrt_abstime _last_sitl_timestamp{0};
hrt_abstime _last_battery_timestamp{0};
// Lib used to do the battery calculations.
Battery1 _battery {};
battery_status_s _battery_status{};
// Because the simulator doesn't actually care about the real values of these, just stick
// in some good defaults.
// This is an anonymous class, because BatteryBase is abstract and can't directly be instantiated.
class : public BatteryBase
{
float _get_bat_v_empty() override { return 3.5; }
float _get_bat_v_charged() override { return 4.05; }
int _get_bat_n_cells() override { return 4; }
float _get_bat_capacity() override { return 10.0; }
float _get_bat_v_load_drop() override { return 0; }
float _get_bat_r_internal() override { return 0; }
float _get_bat_low_thr() override { return 0.15; }
float _get_bat_crit_thr() override { return 0.07; }
float _get_bat_emergen_thr() override { return 0.05; }
int _get_source() override { return 0; }
} _battery {};
#ifndef __PX4_QURT
+4 -2
View File
@@ -346,7 +346,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(&_battery_status.timestamp) >= 10_ms) {
if (hrt_elapsed_time(&_last_battery_timestamp) >= 10_ms) {
const float discharge_interval_us = _param_sim_bat_drain.get() * 1000 * 1000;
@@ -370,7 +370,9 @@ void Simulator::handle_message_hil_sensor(const mavlink_message_t *msg)
vbatt *= _battery.cell_count();
const float throttle = 0.0f; // simulate no throttle compensation to make the estimate predictable
_battery.updateBatteryStatus(vbatt, ibatt, now_us, true, 0, throttle, armed);
_battery.updateBatteryStatus(now_us, vbatt, ibatt, true, true, 0, throttle, armed, true);
_last_battery_timestamp = now_us;
}
}