mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-21 23:33:57 -04:00
AP_Baro: get SITL to work with multiple baros
baro readings are independent of each other and can be configured to behave differently
This commit is contained in:
parent
4115603f13
commit
27fc7dcf0a
@ -573,10 +573,7 @@ void AP_Baro::init(void)
|
||||
if (sitl == nullptr) {
|
||||
AP_HAL::panic("No SITL pointer");
|
||||
}
|
||||
if (sitl->baro_count > 1) {
|
||||
::fprintf(stderr, "More than one baro not supported. Sorry.");
|
||||
}
|
||||
if (sitl->baro_count == 1) {
|
||||
for(uint8_t i = 0; i < sitl->baro_count; i++) {
|
||||
ADD_BACKEND(new AP_Baro_SITL(*this));
|
||||
}
|
||||
#elif HAL_BARO_DEFAULT == HAL_BARO_HIL
|
||||
|
@ -54,16 +54,16 @@ void AP_Baro_SITL::_timer()
|
||||
|
||||
float sim_alt = _sitl->state.altitude;
|
||||
|
||||
if (_sitl->baro_disable) {
|
||||
if (_sitl->baro_disable[_instance]) {
|
||||
// barometer is disabled
|
||||
return;
|
||||
}
|
||||
|
||||
sim_alt += _sitl->baro_drift * now / 1000.0f;
|
||||
sim_alt += _sitl->baro_noise * rand_float();
|
||||
sim_alt += _sitl->baro_drift[_instance] * now / 1000.0f;
|
||||
sim_alt += _sitl->baro_noise[_instance] * rand_float();
|
||||
|
||||
// add baro glitch
|
||||
sim_alt += _sitl->baro_glitch;
|
||||
sim_alt += _sitl->baro_glitch[_instance];
|
||||
|
||||
// add delay
|
||||
uint32_t best_time_delta = 200; // initialise large time representing buffer entry closest to current time - delay.
|
||||
@ -118,6 +118,12 @@ void AP_Baro_SITL::_timer()
|
||||
_has_sample = true;
|
||||
}
|
||||
|
||||
// unhealthy if baro is turned off or beyond supported instances
|
||||
bool AP_Baro_SITL::healthy(uint8_t instance)
|
||||
{
|
||||
return !_sitl->baro_disable[instance];
|
||||
}
|
||||
|
||||
// Read the sensor
|
||||
void AP_Baro_SITL::update(void)
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
void update_healthy_flag(uint8_t instance) override { _frontend.sensors[instance].healthy = true; }
|
||||
void update_healthy_flag(uint8_t instance) override { _frontend.sensors[instance].healthy = healthy(instance); };
|
||||
|
||||
private:
|
||||
uint8_t _instance;
|
||||
@ -32,7 +32,10 @@ private:
|
||||
|
||||
// adjust for simulated board temperature
|
||||
void temperature_adjustment(float &p, float &T);
|
||||
|
||||
|
||||
// is the barometer usable for flight
|
||||
bool healthy(uint8_t instance);
|
||||
|
||||
void _timer();
|
||||
bool _has_sample;
|
||||
uint32_t _last_sample_time;
|
||||
|
Loading…
Reference in New Issue
Block a user