Go Down

Topic: Adafruit GPS Shield & Uno - Rapid/Consistent Data retrieval needed for UAV (Read 325 times) previous topic - next topic

srnet

I have asked my staff if I could invest in a higher capacity computer, but we aren't allowed. They want us to optimize our code, thanks though.
I can see the point of a learning exersize where you are limited in processing power and memory, but pushing the limits is perhaps not a good choice where there are safety implications, such as in a UAV. 
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

Power_Broker

It seems to me that the main problem is more of processing efficiency and not necessarily memory (although that may be a separate issue).

The biggest inefficiency I see is here:

Code: [Select]

while (!gps.available(gpsPort)){
  }


This is a blocking delay and is BAD JUJU. This will block your code for at least a whole second waiting for the next fix. The best thing to do is the following:

Code: [Select]

if (gps.available(gpsPort)){
  //do gps logging here
}


This way you only tie up processing power for the GPS when you get actual GPS data - the rest of the time the Arduino can process anything such as sensor polling from the IMU, printing debugging messages, datalogging, whatever else there is to be done.

I hope this helps.

Also, you will want to jack up the baud of both serial ports to around 115200. Depending on the GPS model, you can change the baud settings through certain configuration packets. There is also a chance you can change the refresh rate of the GPS with configuration packets. I know for certain you can make both of these changes for a NEO-6M GPS, but I don't know about the Adafruit one.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

PalmerEng4

It seems to me that the main problem is more of processing efficiency and not necessarily memory (although that may be a separate issue).

The biggest inefficiency I see is here:

Code: [Select]

while (!gps.available(gpsPort)){
  }


This is a blocking delay and is BAD JUJU. This will block your code for at least a whole second waiting for the next fix. The best thing to do is the following:

Code: [Select]

if (gps.available(gpsPort)){
  //do gps logging here
}


This way you only tie up processing power for the GPS when you get actual GPS data - the rest of the time the Arduino can process anything such as sensor polling from the IMU, printing debugging messages, datalogging, whatever else there is to be done.

I hope this helps.

Also, you will want to jack up the baud of both serial ports to around 115200. Depending on the GPS model, you can change the baud settings through certain configuration packets. There is also a chance you can change the refresh rate of the GPS with configuration packets. I know for certain you can make both of these changes for a NEO-6M GPS, but I don't know about the Adafruit one.
I'm planning on putting most of the code within the while loop, but I guess that's effectively the same? I'll give it a go.

I didn't know anything about the baud rates so that's really helpful cheers.

Power_Broker

I'm planning on putting most of the code within the while loop, but I guess that's effectively the same?
Yes.

Your code will work best if you test for "if" there is data, not "while" there isn't data - this is the most efficient and responsive way to handle GPS data.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Go Up