My university project includes the need for a flight computer/ data logger and auto-pilot system for a fixed wing UAV. Part of the project specification is that an only an Uno is allowed to be used.
I've coded an auto-pilot (gyro & accelerometer fed PID system) that works great on a program loop of a consistent time period. I've also got the Adafruit GPS shield working with NeoGPS (needed because of limited RAM), but the usual data retrieval function, a while() loop, is highly unstable. Which will likely botch the stabilization loop.
This Code;
#include <NMEAGPS.h>
#include <GPSport.h>
int gpstime;
unsigned long start;
NMEAGPS gps;
gps_fix fix;
void setup(){
DEBUG_PORT.begin(9600);
while (!DEBUG_PORT);
delay(500);
gpsPort.begin(9600);
}
void loop(){
start = millis();
while (!gps.available(gpsPort)){
}
if (gps.available(gpsPort)){
fix = gps.read();
}
gpstime = millis() - start;
if (fix.valid.location) {
//DEBUG_PORT.print( F("Location: ") ); Don't want the world to know where I am!
//DEBUG_PORT.print( fix.latitude(), 6 );
//DEBUG_PORT.print( F(",") );
//DEBUG_PORT.println( fix.longitude(), 6 );
}
else DEBUG_PORT.println(F("No Location Data available."));
DEBUG_PORT.print(F("GPS Read Time: "));
DEBUG_PORT.print(gpstime);
DEBUG_PORT.print(F(",\tGPS Second: "));
DEBUG_PORT.println( fix.dateTime.seconds );
}
Produces this:
GPS Read Time: 604, GPS Second: 34
GPS Read Time: 1202, GPS Second: 35
GPS Read Time: 832, GPS Second: 36
GPS Read Time: 974, GPS Second: 37
GPS Read Time: 996, GPS Second: 38
GPS Read Time: 1035, GPS Second: 39
GPS Read Time: 1159, GPS Second: 40
GPS Read Time: 754, GPS Second: 41
GPS Read Time: 1064, GPS Second: 42
GPS Read Time: 932, GPS Second: 43
GPS Read Time: 987, GPS Second: 44
GPS Read Time: 1273, GPS Second: 45
GPS Read Time: 727, GPS Second: 46
GPS Read Time: 1009, GPS Second: 47
GPS Read Time: 1062, GPS Second: 48
GPS Read Time: 946, GPS Second: 49
GPS Read Time: 1198, GPS Second: 50
GPS Read Time: 840, GPS Second: 51
GPS Read Time: 938, GPS Second: 52
GPS Read Time: 1008, GPS Second: 53
GPS Read Time: 1061, GPS Second: 54
My problem is that the "GPS Read Time" is inconsistent, if it was (at least within 10 milliseconds), I could run the stabilization code "n" times and then retrieve the GPS data.
I'm guessing this will be possible with PPS syncing? But I've struggled to find enough information to know if this will fix my problem (I'm not a programmer).
Thanks in advance! Also any tips on reducing RAM/ memory would also be greatly appreciated, I still need to add in the SD card writer and receiver code :o .
Here, "slash-dev" mentioned the NeoGPS acquires a fix every 1 second: https://stackoverflow.com/questions/43006844/want-to-get-gps-data-at-every-5-sec-using-arduino/43013240[/url]
GPS Datasheet if you need it: