Distance between coordinates
hi all,
i having trouble getting correct distance between coordinates.
i using 1sheeld coordinates phone , adafruit breakout (gps module) coordinates of device.
when upload code , turn on serial monitor gives me output of around 5,000 same value if 1 of coordinates (0,0). despite me testing code , knowing individually 1sheeld , gps module give correct coordinates, when put 1sheeld produces output of (0,0).
summarising, the bulk of code works, unable 1sheeld output correct coordinates when combined code. if has idea how fix appreciated
i having trouble getting correct distance between coordinates.
i using 1sheeld coordinates phone , adafruit breakout (gps module) coordinates of device.
when upload code , turn on serial monitor gives me output of around 5,000 same value if 1 of coordinates (0,0). despite me testing code , knowing individually 1sheeld , gps module give correct coordinates, when put 1sheeld produces output of (0,0).
summarising, the bulk of code works, unable 1sheeld output correct coordinates when combined code. if has idea how fix appreciated
code: [select]
#include <onesheeld.h>
#include <adafruit_gps.h>
#include <softwareserial.h>
softwareserial myserial(3, 2);
adafruit_gps gpsm(&myserial);
#define gpsecho false
#define custom_settings
#define include_gps_shield
boolean usinginterrupt = false;
void useinterrupt(boolean);
float lat_gps,long_gps,lat_gpsm,long_gpsm;
float lonr1,lonr2,latr1,latr2;
char charlat [10];
char charlon [10];
char readings [80];
float dlat,dlon,a,e,d;
float r = 6371.00;
float todegrees = 57.295779;
char sb[10];
void setup()
{
{ onesheeld.begin();
}
serial.begin(115200);
gpsm.begin(9600);
gpsm.sendcommand(pmtk_set_nmea_update_1hz);
gpsm.sendcommand(pgcmd_antenna);
useinterrupt(true);
delay(1000);
myserial.println(f(pmtk_q_release));
}
signal(timer0_compa_vect) {
char c = gpsm.read();
#ifdef udr0
if (gpsecho)
if (c) udr0 = c;
#endif
}
void useinterrupt(boolean v) {
if (v) {
ocr0a = 0xaf;
timsk0 |= _bv(ocie0a);
usinginterrupt = true;
} else {
timsk0 &= ~_bv(ocie0a);
usinginterrupt = false;
}
uint32_t timer = millis();
pinmode(led_builtin, output);
}
void loop()
{
if (! usinginterrupt) {
char c = gpsm.read();
if (gpsecho)
if (c) serial.print(c);
}
if (gpsm.newnmeareceived()) {
if (!gpsm.parse(gpsm.lastnmea()))
return;
}
lat_gpsm = gpsm.latitudedegrees;
long_gpsm = gpsm.longitudedegrees;
{
lat_gps = gps.getlatitude();
long_gps = gps.getlongitude();
}
{ void calcdist();
lonr1 = long_gps*(pi/180);
lonr2 = long_gpsm*(pi/180);
latr1 = lat_gps*(pi/180);
latr2 = lat_gpsm*(pi/180);
dlon = lonr2 - lonr1;
dlat = latr2 - latr1;}
a = (sq(sin(dlat/2))) + cos(latr1) * cos(latr2) * (sq(sin(dlon/2)));
e = 2 * atan2(sqrt(a), sqrt(1-a)) ;
d = r * e;
serial.print ( d );
}
nothing wrong. add println(s) show dlon, dlat, etc before "haversine" them
you might consider using equirectangular projection instead of haversine. it's simpler , faster.
you might consider using equirectangular projection instead of haversine. it's simpler , faster.
Arduino Forum > Using Arduino > Project Guidance > Distance between coordinates
arduino
Comments
Post a Comment