Go Down

Topic: GPS used as Compass (Read 982 times) previous topic - next topic

cutebuddy6

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

dxw00d

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.

cutebuddy6

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

MarkT

Parse the relevant NMEA sentence  $GPRMC
[ I won't respond to messages, use the forum please ]

cutebuddy6

here is the code that i am using
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.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

dxw00d

#5
Feb 23, 2012, 11:12 am Last Edit: Feb 23, 2012, 11:18 am by dxw00d Reason: 1
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.

cutebuddy6

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

cutebuddy6

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

cutebuddy6

what if the true heading is not important

dxw00d


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


To do what?

dxw00d


what if the true heading is not important


Then you probably don't need a compass module.

cutebuddy6

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

GPS then what sort of code should i use

dxw00d

#12
Feb 24, 2012, 09:34 am Last Edit: Feb 24, 2012, 10:31 am by dxw00d Reason: 1
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.

cutebuddy6

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

dxw00d

#14
Feb 24, 2012, 12:24 pm Last Edit: Feb 24, 2012, 12:29 pm by dxw00d Reason: 1
Aside from scale, what's the difference?

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

Go Up