@@ -105,30 +105,52 @@ void updateGpsSettings(__attribute__((unused)) UAVObjEvent *ev);
105105// the new location with Set = true.
106106#define GPS_HOMELOCATION_SET_DELAY 5000
107107
108- #define GPS_LOOP_DELAY_MS 6
108+ // PIOS serial port receive buffer for GPS is set to 32 bytes for the minimal and 128 bytes for the full version.
109+ // GPS_READ_BUFFER is defined a few lines below in this file.
110+ //
111+ // 57600 bps = 5760 bytes per second
112+ //
113+ // For 32 bytes buffer: this is a maximum of 5760/32 = 180 buffers per second
114+ // that is 1/180 = 0.0056 seconds per packet
115+ // We must never wait more than 5ms since packet was last drained or it may overflow
116+ //
117+ // For 128 bytes buffer: this is a maximum of 5760/128 = 45 buffers per second
118+ // that is 1/45 = 0.022 seconds per packet
119+ // We must never wait more than 22ms since packet was last drained or it may overflow
120+
121+ // There are two delays in play for the GPS task:
122+ // - GPS_BLOCK_ON_NO_DATA_MS is the time to block while waiting to receive serial data from the GPS
123+ // - GPS_LOOP_DELAY_MS is used for a context switch initiated by calling vTaskDelayUntil() to let other tasks run
124+ //
125+ // The delayMs time is not that critical. It should not be too high so that maintenance actions within this task
126+ // are run often enough.
127+ // GPS_LOOP_DELAY_MS on the other hand, should be less then 5.55 ms. A value set too high will cause data to be dropped.
128+
129+ #define GPS_LOOP_DELAY_MS 5
130+ #define GPS_BLOCK_ON_NO_DATA_MS 20
109131
110132#ifdef PIOS_GPS_SETS_HOMELOCATION
111133// Unfortunately need a good size stack for the WMM calculation
112- #define STACK_SIZE_BYTES 1024
134+ #define STACK_SIZE_BYTES 1024
113135#else
114136#if defined(PIOS_GPS_MINIMAL )
115- #define GPS_READ_BUFFER 32
137+ #define GPS_READ_BUFFER 32
116138
117139#ifdef PIOS_INCLUDE_GPS_NMEA_PARSER
118- #define STACK_SIZE_BYTES 580 // NMEA
119- #else
120- #define STACK_SIZE_BYTES 440 // UBX
140+ #define STACK_SIZE_BYTES 580 // NMEA
141+ #else // PIOS_INCLUDE_GPS_NMEA_PARSER
142+ #define STACK_SIZE_BYTES 440 // UBX
121143#endif // PIOS_INCLUDE_GPS_NMEA_PARSER
122- #else
123- #define STACK_SIZE_BYTES 650
144+ #else // PIOS_GPS_MINIMAL
145+ #define STACK_SIZE_BYTES 650
124146#endif // PIOS_GPS_MINIMAL
125147#endif // PIOS_GPS_SETS_HOMELOCATION
126148
127149#ifndef GPS_READ_BUFFER
128- #define GPS_READ_BUFFER 128
150+ #define GPS_READ_BUFFER 128
129151#endif
130152
131- #define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
153+ #define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
132154
133155// ****************
134156// Private variables
@@ -284,14 +306,7 @@ MODULE_INITCALL(GPSInitialize, GPSStart);
284306
285307static void gpsTask (__attribute__((unused )) void * parameters )
286308{
287- // 57600 baud = 5760 bytes per second
288- // PIOS serial buffers appear to be 32 bytes long
289- // that is a maximum of 5760/32 = 180 buffers per second
290- // that is 1/180 = 0.005555556 seconds per packet
291- // we must never wait more than 5ms since packet was last drained or it may overflow
292- // 100ms is way slow too, considering we do everything possible to make the sensor data as contemporary as possible
293- portTickType xDelay = 5 / portTICK_RATE_MS ;
294- uint32_t timeNowMs = xTaskGetTickCount () * portTICK_RATE_MS ;
309+ uint32_t timeNowMs = xTaskGetTickCount () * portTICK_RATE_MS ;
295310
296311#ifdef PIOS_GPS_SETS_HOMELOCATION
297312 portTickType homelocationSetDelay = 0 ;
@@ -353,8 +368,8 @@ static void gpsTask(__attribute__((unused)) void *parameters)
353368
354369 uint16_t cnt ;
355370 int res ;
356- // This blocks the task until there is something on the buffer (or 100ms? passes)
357- cnt = PIOS_COM_ReceiveBuffer (gpsPort , c , GPS_READ_BUFFER , xDelay );
371+ // This blocks the task until there is something in the buffer (or GPS_BLOCK_ON_NO_DATA_MS passes)
372+ cnt = PIOS_COM_ReceiveBuffer (gpsPort , c , GPS_READ_BUFFER , GPS_BLOCK_ON_NO_DATA_MS );
358373 res = PARSER_INCOMPLETE ;
359374 if (cnt > 0 ) {
360375 PERF_TIMED_SECTION_START (counterParse );
@@ -416,7 +431,7 @@ static void gpsTask(__attribute__((unused)) void *parameters)
416431 //
417432 // if (the fix is good) {
418433 if ((gpspositionsensor .PDOP < gpsSettings .MaxPDOP ) && (gpspositionsensor .Satellites >= gpsSettings .MinSatellites ) &&
419- (gpspositionsensor .Status == GPSPOSITIONSENSOR_STATUS_FIX3D ) &&
434+ (( gpspositionsensor .Status == GPSPOSITIONSENSOR_STATUS_FIX3D ) || ( gpspositionsensor . Status == GPSPOSITIONSENSOR_STATUS_FIX3DDGNSS ) ) &&
420435 (gpspositionsensor .Latitude != 0 || gpspositionsensor .Longitude != 0 )) {
421436 AlarmsClear (SYSTEMALARMS_ALARM_GPS );
422437#ifdef PIOS_GPS_SETS_HOMELOCATION
@@ -436,7 +451,7 @@ static void gpsTask(__attribute__((unused)) void *parameters)
436451 }
437452#endif
438453 // else if (we are at least getting what might be usable GPS data to finish a flight with) {
439- } else if ((gpspositionsensor .Status == GPSPOSITIONSENSOR_STATUS_FIX3D ) &&
454+ } else if ((( gpspositionsensor .Status == GPSPOSITIONSENSOR_STATUS_FIX3D ) || ( gpspositionsensor . Status == GPSPOSITIONSENSOR_STATUS_FIX3DDGNSS ) ) &&
440455 (gpspositionsensor .Latitude != 0 || gpspositionsensor .Longitude != 0 )) {
441456 AlarmsSet (SYSTEMALARMS_ALARM_GPS , SYSTEMALARMS_ALARM_WARNING );
442457 // else data is probably not good enough to fly
0 commit comments