Interacting with GPS output coordinates

I am Getting output coordinates well and they appear on the Serial Monitor from the code bellow but now i need it to run through a list of coordinate Positions for it to reach that i can manually enter into the cycle array at the top. my current issue is that i am unable to figure out how to use the gps.location.lat() values in If functions and later in a formula to give the relative angle from forward face to goal position. in summary i need to be able to use a long set of decimals in math's and an if statement against an array.

//Compass
#include <Wire.h>
#include <QMC5883LCompass.h>
QMC5883LCompass compass;

//Gps
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
int RXPin = 2;
int TXPin = 3;
int GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial gpsSerial(RXPin, TXPin);

//Cycle Array
int LatValue[] = { 179.572947 }; //Last Value Must be 0.00...etc.
int LngValue[] = { 126.588290 }; //Last Value Must be 0.00...etc.

void setup()
{
  //Compass
  Serial.begin(9600);
  Wire.begin();
  compass.init();

  //GPS
  gpsSerial.begin(GPSBaud);
}

void loop()
{
  //Compass
   int x, y, z;
  compass.read();
  x = compass.getX();
  y = compass.getY();
  z = compass.getZ();
  float heading = atan2(y, x);
  if(heading < 0) heading += 2*PI;
  float headingDegrees = heading * 180/M_PI;
  //GPS
while (gpsSerial.available() > 0)
if (gps.encode(gpsSerial.read()))
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
  Serial.print(" No GPS detected");
  while(true);
  }
  if (gps.location.isValid())
  {
  Serial.print("  Lat: ");
  Serial.print(gps.location.lat(), 6);
  Serial.print("  Long: ");
  Serial.print(gps.location.lng(), 6);
  }
  else
  {
    Serial.print("  Location: Not Available");
  }

  //Compass
  Serial.print("  Hed: ");
  Serial.print(headingDegrees);
  Serial.print(" deg");
  Serial.println();

  //Cycle Array
  if(LatValue = gps.location.lat() && LngValue = gps.location.lng())
  {
  //add 1 to Lat and Long value
  }
  if(LatValue = 0 && LngValue = 0)
  {
  //Stop Program
  }
  else
  {
  //move towards Lat and Long value
  }
}

Use the courseTo function in TinyGPS++ to determine the desired course heading. The distanceBetween function is also pretty handy, for example to determine if you have reached the goal.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.