I am working on a project to display my drone's altitude above ground. After researching how GPS receivers determine and present their altitude readings (above sea level), it appears that I need to do some tweeking.
I am wondering how I might set my initial GPS altitude reading as a 0 reference point to then be able to compare all following altitude readings to this initial reference point (ground level).
Ultimately, I want to create an If statement in which if my drone goes at least 400 feet above the established reference point, I receive a warning on my remote LCD.
I am using a Arduino Uno R3, a SparkFun GPS Shield Kit (includes a SparkFun GPS Shield (SparkFun GPS Logger Shield - GPS-13750 - SparkFun Electronics) and a GPS Receiver - EM-506 (48 Channel) (https://www.sparkfun.com/products/12751) attached.
I already have the GPS on the drone comparing latitude and longitude coordinates and sending messages to an LCD screen attached to another Uno on my remote control if coordinates match a pre-set range. The two are communicating via two XBee Pro 60mW Wire Antenna - Series 1 (802.15.4) (XBee Pro 60mW Wire Antenna - Series 1 (802.15.4) - WRL-08742 - SparkFun Electronics).
Here is the "transmitter" code (Uno and GPS on drone) that I have working so far. The only altitude portion that I have so far is at the bottom (just displays current altitude):
#include <SoftwareSerial.h>
#include <TinyGPS.h>
//In this case, the GPS module's TX pin will connect to the Arduino's RXPIN which is pin 3.
#define RXPIN 2
#define TXPIN 3
// This is the serial rate for your terminal program.
// Set this value equal to the baud rate of your terminal program
#define TERMBAUD 9600
// Set this value equal to the baud rate of your GPS
#define GPSBAUD 4800
int flag=0;
// Create an instance of the TinyGPS object
TinyGPS gps;
// Initialize the SoftwareSerial library to the pins you defined above
SoftwareSerial uart_gps(RXPIN, TXPIN);
// This is where you declare prototypes for the functions that will be
// using the TinyGPS library.
void getgps(TinyGPS &gps);
// In the setup function, need to initialize two serial ports; the
// standard hardware serial port (Serial()) to communicate with the
// terminal program an another serial port (SoftwareSerial()) for the
// GPS.
void setup()
{
// Sets baud rate of your terminal program
Serial.begin(TERMBAUD);
// Sets baud rate of your GPS
uart_gps.begin(GPSBAUD);
//Serial.println("");
//Serial.println("GPS Shield QuickStart Example Sketch v12");
//Serial.println(" ...waiting for lock... ");
//Serial.println("");
}
// This is the main loop of the code. All it does is check for data on
// the RX pin of the Ardiuno, makes sure the data is valid NMEA sentences,
// then jumps to the getgps() function.
void loop()
{
while(uart_gps.available()) // While there is data on the RX pin...
{
int c = uart_gps.read(); // load the data into a variable...
if(gps.encode(c)) // if there is a new valid sentence...
{
getgps(gps); // then grab the data.
delay(4000); // delay in grabbing GPS data until to length of time required to display message
}
}
}
// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
// Define the variables that will be used
float latitude, longitude;
// Then call this function
gps.f_get_position(&latitude, &longitude);
if (latitude >= 41.479133 && latitude <= 41.493510 && longitude >= -71.541359 && longitude <= -71.522058)
{
flag=1;
Serial.write(flag);
}
else
{
flag=0;
Serial.write(flag);
}
// Can print the altitude and course values directly since there is only one value for the function
// Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());
}
Thank you very much! Your input is highly appreciated!