Hi folks,
I am trying to make my own Antenna Tracker. At the moment I struggle with saving the longitude and latitude as a variable.
#include <Adafruit_GPS.h>
// TX - RX // RX - TX!!!
#include <TinyGPS++.h>
#define GPSSerial Serial1
#define XBeeSerial Serial2
Adafruit_GPS GPS1(&GPSSerial);
TinyGPSPlus GPSGround;
TinyGPSPlus GPSAir;
long LongitudeCopter = 0;
long LongitudeHome = 0;
long LatitudeCopter = 0;
long LatitudeHome = 0;
long AltitudeCopter = 0;
long AltitudeHome = 0;
long DeltaAltitude = 0;
float flatHome,flongHome,flat,flong;
float fDistanceBetween = 0;
float g_fCourseTo = 0;
long dAngleAlpha = 0;
void setup()
{
Serial.begin(115200);
GPS1.begin(9600);
GPSSerial.begin(9600);
XBeeSerial.begin(19200);
GPS1.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS1.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);
GPS1.sendCommand(PGCMD_ANTENNA);
delay(1000);
}
void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (GPSSerial.available() > 0)
if (GPSGround.encode(GPSSerial.read()));
while (XBeeSerial.available() > 0)
if (GPSAir.encode(XBeeSerial.read()));
gpsEncode();
displayInfo();
}
void gpsEncode()
{
if (GPSGround.location.isValid())
{
LongitudeHome = (GPSGround.location.lng());
LatitudeHome = (GPSGround.location.lat());
AltitudeHome = ((GPSGround.altitude.value())/100);
}
if (GPSAir.location.isValid())
{
LongitudeCopter = (GPSAir.location.lng());
LatitudeCopter = (GPSAir.location.lat());
AltitudeCopter = ((GPSAir.altitude.value())/100);
}
}
void displayInfo()
{
Serial.print(F("Ground Location: "));
if (GPSGround.location.isValid())
{
Serial.print(LatitudeHome);
Serial.print(F(","));
Serial.print(LongitudeHome);
Serial.print(F(","));
Serial.print(AltitudeHome);
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" Copter Location: "));
if (GPSAir.location.isValid())
{
Serial.print(LatitudeCopter);
Serial.print(F(","));
Serial.print(LongitudeCopter);
Serial.print(F(","));
Serial.print(AltitudeCopter);
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" Ground Date/Time: "));
if (GPSGround.date.isValid())
{
Serial.print(GPSGround.date.month());
Serial.print(F("/"));
Serial.print(GPSGround.date.day());
Serial.print(F("/"));
Serial.print(GPSGround.date.year());
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" Copter Date/Time: "));
if (GPSAir.date.isValid())
{
Serial.print(GPSAir.date.month());
Serial.print(F("/"));
Serial.print(GPSAir.date.day());
Serial.print(F("/"));
Serial.print(GPSAir.date.year());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}
When I change the types from long to float it changes a little. I need to make calculations with the coordinates.
Can someone please tell me, what I am doing wrong? The most i got until now was 47.21 / 7.31 and not something like 47.214521 / 7.316723.
Please excuse my english ![]()
Thank you!
Florian