Go Down

Topic: GPS varying Output (Read 2 times) previous topic - next topic

CrossRoads

I would think you'd need to perform the averaging here:
Code: [Select]

   if (myGPS.decode(mygps.read())) {
     // if so, set status led on
     digitalWrite(13, HIGH);
       
     // calculate direction to destination, relative to my own direction of movement
     float lat = myGPS.gprmc_latitude();
     float longi = myGPS.gprmc_longitude();

so make that section do 10 readings with the averaging as discussed:
Code: [Select]

float lat = 0;
float longi = 0;
for (int x = 0; x<10; x=x+1){
   if (myGPS.decode(mygps.read())) {
     // if so, set status led on
     digitalWrite(13, HIGH);
       
     // calculate direction to destination, relative to my own direction of movement
     lat = lat+ myGPS.gprmc_latitude();
     longi = longi + myGPS.gprmc_longitude();
}
lat = lat/10;
longi = longi/10;
}
// continue to the display code
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

cutebuddy6

#26
Feb 25, 2012, 08:17 am Last Edit: Feb 25, 2012, 08:28 am by cutebuddy6 Reason: 1
Is this ok
Code: [Select]


#include <math.h>
#include <nmea.h>
#include <LiquidCrystal.h>
#include <NewSoftSerial.h>
NewSoftSerial mygps(7, 8);
NMEA myGPS(GPRMC);
LiquidCrystal myLCD = LiquidCrystal(12, 11, 5, 4, 3, 2);
float dest_latitude =  25.37106;
float dest_longitude = 68.355681; 
void setup() {
  myLCD.begin(16,2);
  mygps.begin(4800);
  pinMode(13, OUTPUT);  // diagnostic led on Wiring-board
  pinMode(6, OUTPUT);
  myLCD.clear();
  myLCD.home();
  myLCD.print(":) :)");
  delay(1000);
}
void loop() {
  if (mygps.available() > 0 ) {
    float lat = 0;
    float longi = 0;
    for (int x = 0; x<10; x=x+1){
      if (myGPS.decode(mygps.read())) {
        // if so, set status led on
        digitalWrite(13, HIGH); 
        // calculate direction to destination, relative to my own direction of movement
        lat = lat+ myGPS.gprmc_latitude();
        longi = longi + myGPS.gprmc_longitude();
      }
      lat = lat/10;
      longi = longi/10;
    }
    // continue to the display code
    myLCD.setCursor(0,0);
    myLCD.print("D:");
    float d=(round(myGPS.gprmc_distance_to(dest_latitude, dest_longitude, MTR)));
    myLCD.print(d);
    myLCD.print("m");
    float mydir=0;
    for (int y=0;y<10;y++)
    {
      if (myGPS.gprmc_status() == 'A') {
        // calculate relative direction to destination
        d = myGPS.gprmc_course_to(dest_latitude, dest_longitude) - myGPS.gprmc_course();
        mydir=mydir+d; 
        if (d < 0) {
          d += 360;
        }
        if (d > 180) {
          d -= 360;
        }
      }
      mydir=mydir/10;
      myLCD.setCursor(1,1);
      myLCD.print(mydir);
      if(d<5)
      {
        digitalWrite(5,HIGH);
      }
      else {
        digitalWrite(5,LOW);
      }
      if(d>-5){
        digitalWrite(13,HIGH);
      }
      else {
        digitalWrite(13,LOW);
      }
    }
  }
}



CrossRoads

I don't see it doing anything with the new averaged values that are calculated.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

cutebuddy6

it still does not gives me good direction why?

PaulS

Quote
it still does not gives me good direction why?

Grow up. Learn to use capital letters and punctuation. Learn to read all replies before blurting "it doesn't work".

Do you have any idea how much, distance-wise, the variation of actual location that you are getting corresponds to?

Go Up