|
|
|
@ -1,7 +1,7 @@
@@ -1,7 +1,7 @@
|
|
|
|
|
/*
|
|
|
|
|
AP_GPS_UBLOX.cpp - Ublox GPS library for Arduino |
|
|
|
|
Code by Jordi Muñoz and Jose Julio. DIYDrones.com |
|
|
|
|
This code works with boards based on ATMega168 / 328 and ATMega1280 (Serial port 1) |
|
|
|
|
This code works with boards based on ATMega168/328 and ATMega1280 (Serial port 1) |
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and / or |
|
|
|
|
modify it under the terms of the GNU Lesser General Public |
|
|
|
@ -25,8 +25,8 @@
@@ -25,8 +25,8 @@
|
|
|
|
|
Lattitude : Lattitude * 10000000 (long value) |
|
|
|
|
Longitude : Longitude * 10000000 (long value) |
|
|
|
|
altitude : altitude * 100 (meters) (long value) |
|
|
|
|
Ground_speed : Speed (m / s) * 100 (long value) |
|
|
|
|
Ground_course : Course (degrees) * 100 (long value) |
|
|
|
|
ground_speed : Speed (m/s) * 100 (long value) |
|
|
|
|
ground_course : Course (degrees) * 100 (long value) |
|
|
|
|
new_data : 1 when a new data is received. |
|
|
|
|
You need to write a 0 to new_data when you read the data |
|
|
|
|
fix : 1: GPS FIX, 0: No fix (normal logic) |
|
|
|
@ -35,14 +35,13 @@
@@ -35,14 +35,13 @@
|
|
|
|
|
|
|
|
|
|
#include "AP_GPS_UBLOX.h" |
|
|
|
|
|
|
|
|
|
// Constructors // /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// //
|
|
|
|
|
// Constructors ////////////////////////////////////////////////////////////////
|
|
|
|
|
AP_GPS_UBLOX::AP_GPS_UBLOX() |
|
|
|
|
{ |
|
|
|
|
print_errors = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Public Methods // /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
|
|
|
|
|
// Public Methods ////////////////////////////////////////////////////////////////////
|
|
|
|
|
void AP_GPS_UBLOX::init(void) |
|
|
|
|
{ |
|
|
|
|
ck_a = 0; |
|
|
|
@ -51,13 +50,12 @@ void AP_GPS_UBLOX::init(void)
@@ -51,13 +50,12 @@ void AP_GPS_UBLOX::init(void)
|
|
|
|
|
new_data = 0; |
|
|
|
|
fix = 0; |
|
|
|
|
print_errors = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// initialize serial port
|
|
|
|
|
#if defined(__AVR_ATmega1280__) |
|
|
|
|
Serial1.begin(38400); // Serial port 1 on ATMega1280
|
|
|
|
|
#else |
|
|
|
|
Serial.begin(38400); |
|
|
|
|
Serial.begin(38400);
|
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -70,34 +68,30 @@ void AP_GPS_UBLOX::update(void)
@@ -70,34 +68,30 @@ void AP_GPS_UBLOX::update(void)
|
|
|
|
|
int numc; |
|
|
|
|
|
|
|
|
|
#if defined(__AVR_ATmega1280__) // If AtMega1280 then Serial port 1...
|
|
|
|
|
numc = Serial1.available(); |
|
|
|
|
numc = Serial1.available(); |
|
|
|
|
#else |
|
|
|
|
numc = Serial.available(); |
|
|
|
|
numc = Serial.available(); |
|
|
|
|
#endif |
|
|
|
|
Serial.print("numc "); |
|
|
|
|
Serial.println(numc,DEC); |
|
|
|
|
|
|
|
|
|
if (numc > 0){ |
|
|
|
|
Serial.println(" "); |
|
|
|
|
for (int i = 0;i < numc;i++){ // Process bytes received
|
|
|
|
|
#if defined(__AVR_ATmega1280__) |
|
|
|
|
data = Serial1.read(); |
|
|
|
|
#else |
|
|
|
|
data = Serial.read(); |
|
|
|
|
#endif |
|
|
|
|
Serial.print(data,HEX); |
|
|
|
|
Serial.println(","); |
|
|
|
|
switch(step){ // Normally we start from zero. This is a state machine
|
|
|
|
|
case 0:
|
|
|
|
|
if(data == 0xB5) // UBX sync char 1
|
|
|
|
|
step++; // OH first data packet is correct, so jump to the next step
|
|
|
|
|
|
|
|
|
|
switch(step){ |
|
|
|
|
case 0: |
|
|
|
|
if(data == 0xB5) |
|
|
|
|
step++; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
if(data == 0x62) // UBX sync char 2
|
|
|
|
|
step++; // ooh! The second data packet is correct, jump to the step 2
|
|
|
|
|
if(data == 0x62) |
|
|
|
|
step++; |
|
|
|
|
else
|
|
|
|
|
step = 0; // Nop, is not correct so restart to step zero and try again.
|
|
|
|
|
step = 0; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 2: |
|
|
|
@ -166,26 +160,25 @@ void AP_GPS_UBLOX::update(void)
@@ -166,26 +160,25 @@ void AP_GPS_UBLOX::update(void)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Private Methods //////////////////////////////////////////////////////////////
|
|
|
|
|
void AP_GPS_UBLOX::parse_gps(void) |
|
|
|
|
void |
|
|
|
|
AP_GPS_UBLOX::parse_gps(void) |
|
|
|
|
{ |
|
|
|
|
int j; |
|
|
|
|
//Verifing if we are in msg_class 1, you can change this "IF" for a "Switch" in case you want to use other UBX classes..
|
|
|
|
|
// In this case all the message im using are in msg_class 1, to know more about classes check PAGE 60 of DataSheet.
|
|
|
|
|
if(msg_class == 0x01)
|
|
|
|
|
{ |
|
|
|
|
switch(id) //Checking the UBX ID
|
|
|
|
|
{ |
|
|
|
|
if(msg_class == 0x01){ |
|
|
|
|
switch(id) {//Checking the UBX ID
|
|
|
|
|
case 0x02: // ID NAV - POSLLH
|
|
|
|
|
j = 0; |
|
|
|
|
time = join_4_bytes(&buffer[j]); // ms Time of week
|
|
|
|
|
j += 4; |
|
|
|
|
longitude = join_4_bytes(&buffer[j]); // lon * 10000000
|
|
|
|
|
longitude = join_4_bytes(&buffer[j]); // lon * 10,000,000
|
|
|
|
|
j += 4; |
|
|
|
|
lattitude = join_4_bytes(&buffer[j]); // lat * 10000000
|
|
|
|
|
lattitude = join_4_bytes(&buffer[j]); // lat * 10,000,000
|
|
|
|
|
j += 4; |
|
|
|
|
//altitude = join_4_bytes(&buffer[j]); // elipsoid heigth mm
|
|
|
|
|
j += 4; |
|
|
|
|
altitude = (float)join_4_bytes(&buffer[j]); // MSL heigth mm
|
|
|
|
|
altitude = (float)join_4_bytes(&buffer[j]) / 10; // MSL heigth mm
|
|
|
|
|
//j+=4;
|
|
|
|
|
/*
|
|
|
|
|
hacc = (float)join_4_bytes(&buffer[j]) / (float)1000; |
|
|
|
@ -198,7 +191,7 @@ void AP_GPS_UBLOX::parse_gps(void)
@@ -198,7 +191,7 @@ void AP_GPS_UBLOX::parse_gps(void)
|
|
|
|
|
|
|
|
|
|
case 0x03: //ID NAV - STATUS
|
|
|
|
|
//if(buffer[4] >= 0x03)
|
|
|
|
|
if((buffer[4] >= 0x03) && (buffer[5] & 0x01))
|
|
|
|
|
if((buffer[4] >= 0x03) && (buffer[5] & 0x01))
|
|
|
|
|
fix = 1; // valid position
|
|
|
|
|
else |
|
|
|
|
fix = 0; // invalid position
|
|
|
|
@ -223,8 +216,8 @@ void AP_GPS_UBLOX::parse_gps(void)
@@ -223,8 +216,8 @@ void AP_GPS_UBLOX::parse_gps(void)
|
|
|
|
|
ground_course /= 1000; // Rescale heading to deg * 100
|
|
|
|
|
j += 4; |
|
|
|
|
break;
|
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Join 4 bytes into a long
|
|
|
|
|