From c35a2e999b9c886513d85627f1603459133ae441 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2012 21:05:04 +1000 Subject: [PATCH] SITL: added SIM_GPS_DELAY parameter this allows a delay to be added to the gps data to test the impact on AHRS/DCM --- libraries/Desktop/support/sitl_gps.cpp | 61 +++++++++++++++++++++----- libraries/SITL/SITL.cpp | 1 + libraries/SITL/SITL.h | 2 + 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/libraries/Desktop/support/sitl_gps.cpp b/libraries/Desktop/support/sitl_gps.cpp index 431ebf56b3..277ce95a52 100644 --- a/libraries/Desktop/support/sitl_gps.cpp +++ b/libraries/Desktop/support/sitl_gps.cpp @@ -12,11 +12,28 @@ #include #include #include +#include #include #include #include "desktop.h" #include "util.h" +extern SITL sitl; + +#define MAX_GPS_DELAY 100 + +struct gps_data { + double latitude; + double longitude; + float altitude; + double speedN; + double speedE; + bool have_lock; +} gps_data[MAX_GPS_DELAY]; + +static uint8_t next_gps_index; +static uint8_t gps_delay; + // state of GPS emulation static struct { /* pipe emulating UBLOX GPS serial stream */ @@ -113,6 +130,7 @@ void sitl_update_gps(double latitude, double longitude, float altitude, const uint8_t MSG_POSLLH = 0x2; const uint8_t MSG_STATUS = 0x3; const uint8_t MSG_VELNED = 0x12; + struct gps_data d; // 5Hz, to match the real UBlox config in APM if (millis() - gps_state.last_update < 200) { @@ -120,30 +138,53 @@ void sitl_update_gps(double latitude, double longitude, float altitude, } gps_state.last_update = millis(); + d.latitude = latitude; + d.longitude = longitude; + d.altitude = altitude; + d.speedN = speedN; + d.speedE = speedE; + d.have_lock = have_lock; + + // add in some GPS lag + gps_data[next_gps_index++] = d; + if (next_gps_index >= gps_delay) { + next_gps_index = 0; + } + + d = gps_data[next_gps_index]; + + if (sitl.gps_delay != gps_delay) { + // cope with updates to the delay control + gps_delay = sitl.gps_delay; + for (uint8_t i=0; i