From 366361f0bb1e9b11af721c683bcb92d5c745072f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 4 Nov 2018 16:31:13 +1100 Subject: [PATCH] SITL: fixed running of example programs --- libraries/SITL/SIM_Aircraft.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/SITL/SIM_Aircraft.cpp b/libraries/SITL/SIM_Aircraft.cpp index aa655bea1a..8b2d8e97b8 100644 --- a/libraries/SITL/SIM_Aircraft.cpp +++ b/libraries/SITL/SIM_Aircraft.cpp @@ -215,6 +215,11 @@ void Aircraft::update_mag_field_bf() // calculate frame height above ground const float frame_height_agl = fmaxf((-position.z) + home.alt * 0.01f - ground_level, 0.0f); + if (!sitl) { + // running example program + return; + } + // calculate scaling factor that varies from 1 at ground level to 1/8 at sitl->mag_anomaly_hgt // Assume magnetic anomaly strength scales with 1/R**3 float anomaly_scaler = (sitl->mag_anomaly_hgt / (frame_height_agl + sitl->mag_anomaly_hgt));