Ultimately, I am trying to program a robot that can follow my phone using GPS Latitude and Longitude(but this code is not completed yet as I am yet to program the motors).
For this code, I am trying to get the GPS Latitude and Longitude of a phone using the Blynk software which helps to connect the phone to arduino. Then I am trying to get the GPS Latitude and Longitude of the Arduino using a GPS NEO 6M. After that I calculate the distance between the 2 GPS points and the degrees I need to make my robot turn(using the bearings value) and face in the direction of the phone.
However, I am getting error: 'gps' was not declared in this scope.
The code is this:
#include <SoftwareSerial.h>
#include <BlynkSimpleSerialBLE.h>
#include <TinyGPS++.h>
#include <math.h>
#define TxD 8
#define RxD 9
SoftwareSerial serial_connection(0,1);
SoftwareSerial bluetoothSerial(TxD, RxD);
TinyGPSPlus arduino;
float lat2 = gps.getLat();
float lat1 = arduino.location.lat();
float lon2 = gps.getLon();
float lon1 = arduino.location.lng();
double latR1;
double latR2;
double lonR1;
double lonR2;
double dlon;
double dlat;
double a;
double e;
double d;
double R = 6371.00;
double toDegrees = 57.295779;
char sb[10];
char auth[] = "b3a6efffe4424417b71b3184fc24c61b";
BLYNK_WRITE(V2)
{
GpsParam gps(param);
Serial.println("Received remote GPS: ");
Serial.print(gps.getLat(), 7);
Serial.print(", ");
Serial.println(gps.getLon(), 7);
}
void setup()
{
//calcDist();
Serial.begin(9600);
bluetoothSerial.begin(9600);
Blynk.begin(bluetoothSerial, auth);
serial_connection.begin(9600);
Serial.println("GPS Start");
}
void loop()
{
Blynk.run();
while(serial_connection.available())
{
Serial.println("There is connection to GPS!");
arduino.encode(serial_connection.read());
}
if(arduino.location.isUpdated())
{
Serial.println("Satellite Count:");
Serial.println(arduino.satellites.value());
Serial.println("Latitude:");
Serial.println(arduino.location.lat(), 6);
Serial.println("Longitude:");
Serial.println(arduino.location.lng(), 6);
Serial.println("Speed MPH:");
Serial.println(arduino.speed.mph());
Serial.println("Altitude Feet:");
Serial.println(arduino.altitude.feet());
Serial.println("");
}
}
void calcDist()
{
Serial.begin(9600);
float delLat = abs(lat1-lat2)*111194.9;
float delLong = 111194.9*abs(lon1-lon2)*cos(radians((lat1+lat2)/2));
float distance = sqrt(pow(delLat,2)+pow(delLong,2));
Serial.print("Distance to destination(KM): ");
Serial.println(distance,7);
lonR1 = lon1*(PI/180);
lonR2 = lon2*(PI/180);
latR1 = lat1*(PI/180);
latR2 = lat2*(PI/180);
dlon = lonR2 - lonR1;
dlat = latR2 - latR1;
double x = cos(latR2)*sin(lonR2-lonR1);
double y = cos(latR1)*sin(latR2)-sin(latR1)*cos(latR2)*cos(lonR2-lonR1);
float brRad = atan2(x, y);
float reqBear = toDegrees*brRad;
Serial.print("Bearing(°): ");
Serial.println(reqBear, 7);
}
I need help in making gps.getLat() and gps.getLon() in the correct scope so that I am able to access it without errors coming up.
The part of the code which has gps.getLat() and gps.getLon() is here:
float lat2 = gps.getLat();
float lat1 = arduino.location.lat();
float lon2 = gps.getLon();
float lon1 = arduino.location.lng();
and
BLYNK_WRITE(V2)
{
GpsParam gps(param);
Serial.println("Received remote GPS: ");
Serial.print(gps.getLat(), 7);
Serial.print(", ");
Serial.println(gps.getLon(), 7);
}
So once again, I need help in making(or declaring) gps.getLat() and gps.getLon() in the correct scope so that I am able to access it without errors coming up.
Would anyone be able to help me?