GPS used as Compass

can any body suggest me how to use GPS data to calculate heading of the robot

The $GPHDT sentence gives you the True Heading of the GPS device. The device calculates the heading by working out the deviation in successive location readings, so at low speeds it may not be particularly accurate, given the location precision of consumer GPS.

i am using the following module http://www.sparkfun.com/products/465 and trying out an NMEA library with GPRMC sentence and the max speed of my car is vey slow

Parse the relevant NMEA sentence $GPRMC

here is the code that i am using

#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.371021;
float dest_longitude = 68.355606;  
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("BOBBy Jawad Made");
  delay(3000);
}
void loop() {

  if (mygps.available() > 0 ) {

    if (myGPS.decode(mygps.read())) {

      myLCD.clear();
      myLCD.home();
      float lat; 
      float lon;
      lat=myGPS.gprmc_latitude();
      lon = myGPS.gprmc_longitude();
      myLCD.setCursor(0,0);
      myLCD.print("D:");
      float d=(round(myGPS.gprmc_distance_to(dest_latitude, dest_longitude, MTR)));

      float e=(d/0.3048);
      myLCD.print(e);
      myLCD.print("ft");
      if (e < 10){
        digitalWrite(13, HIGH);
      }
      if (e > 10){
        digitalWrite(13, LOW);
      }



      float mydir = calc_bearing (lat, lon, dest_latitude, dest_longitude);

      if (mydir < 0) { 
        mydir += 360; 
      }
      if (mydir > 180) { 
        mydir -= 360; 
      }
      // display relative direction to destination

      if (mydir < 0) {        
        myLCD.setCursor(1,8);
        myLCD.print('R');
        digitalWrite(6,HIGH);

        digitalWrite(13,LOW);
        // destination is to your left
      } 
      else {
        myLCD.setCursor(1,8);
        myLCD.print('L');
        digitalWrite(6,LOW);
        digitalWrite(13,HIGH);
      //delay(3000);  // destination is to your right
      }
      myLCD.print(abs(mydir), DEC);
      myLCD.print(223, BYTE);  // print °-character



    }
  }
}



int calc_bearing(float flat1, float flon1, float flat2, float flon2)
{
  float calc;
  float bear_calc;

  float x = 69.1 * (flat2 - flat1); 
  float y = 69.1 * (flon2 - flon1) * cos(flat1/57.3);

  calc=atan2(y,x);

  bear_calc= degrees(calc);

  if(bear_calc<=1){
    bear_calc=360+bear_calc; 
  }
  return bear_calc;
}

but how its showing the heading ?

secondly its not accurate

The NMEA library will return the heading, in degrees - http://www.maartenlamers.com/nmea/nmea.html#gprmc_course

Location is only accurate to ~10m with the consumer degraded GPS spec, so if your car moves less than 10m between readings, it's difficult for the device to get a good lock on heading. If true heading is important, you need a compass module.

yeah i know that but they vary a lot so i have used that to make it steady

is there any code that i can replace with this and change the Library or something like this

what if the true heading is not important

cutebuddy6: is there any code that i can replace with this and change the Library or something like this

To do what?

cutebuddy6: what if the true heading is not important

Then you probably don't need a compass module.

So what to use if i have to get the heading of my car

GPS then what sort of code should i use

Have you tried googling for information. You're not the first person to do this. I googled for 'arduino autonomous gps', and found a number of links to people that are successfully doing the same sort of thing.

Like http://ttjcrew.com/2009/07/mini-gps-autonomous-car-for-under-100/, for example.

yes thats avery good link this has been done on the RC car i am using the ride on Jeep /Barbie Jeep

Aside from scale, what's the difference?

Did you try googling, or binging or whichever search engine you prefer, for yourself?

Did you try googling, or binging or whichever search engine you prefer, for yourself?

Why should he? You’ll do it for him, and sort out the wheat from the chaff.

PaulS:

Did you try googling, or binging or whichever search engine you prefer, for yourself?

Why should he? You'll do it for him, and sort out the wheat from the chaff.

Fair point. Sometimes, I'm just too helpful. I can't say I did any sorting though. It was the first link that didn't point back to arduino.cc or to youtube.

Sometimes, I'm just too helpful.

I've pretty much refrained from posting in his threads. Doesn't seem to be trying to learn, and seems to be bouncing all over the place. Something doesn't work, and doesn't get it to work. He just moves on and mangles something else.

Well i am just so straight Forward :

Using the arduino and Proogramming for the first time and then Controlling Robot via it. and them making it autonomous so i am doing it step by step and solving the issue

cutebuddy6, you might want to get somebody where you are to help you use this forum. There are communication issues that they might help you with that might speed up your project success.