Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit e5575f5

Browse files
committed
Lat/Long/Alt/AltEllipsoid added.
1 parent 3dddb6e commit e5575f5

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

Diff for: examples/Example3_GetPosition/Example3_GetPosition.ino

+13-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void setup()
3232
{
3333
Serial.begin(115200);
3434
while (!Serial); //Wait for user to open terminal
35-
Serial.println("Ublox high precision accuracy example");
35+
Serial.println("Reading Lat/Long Example");
3636

3737
Wire.begin();
3838

@@ -44,7 +44,6 @@ void setup()
4444
}
4545

4646
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
47-
4847
}
4948

5049
void loop()
@@ -56,14 +55,24 @@ void loop()
5655
//Every other second print the current 3D position accuracy
5756
if(millis() - lastTime > 1000)
5857
{
59-
long lat = myGPS.getLatitude();
58+
long latitude = myGPS.getLatitude();
6059
Serial.print("Lat: ");
61-
Serial.print(lat);
60+
Serial.print(latitude);
6261

6362
long longitude = myGPS.getLongitude();
6463
Serial.print(" Long: ");
6564
Serial.print(longitude);
6665
Serial.println(" (degrees * 10^-7)");
66+
67+
long altitude = myGPS.getAltitude();
68+
Serial.print(" Alt (above mean sea level): ");
69+
Serial.print(altitude);
70+
Serial.println(" (mm)");
71+
72+
long altitudeEllipsoid = myGPS.getAltitudeEllipsoid();
73+
Serial.print(" AltMSL (above Ellipsoid model surface of earth): ");
74+
Serial.print(altitudeEllipsoid);
75+
Serial.println(" (mm)");
6776
}
6877

6978
}

Diff for: src/SparkFun_Ublox_Arduino_Library.cpp

+48-2
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ uint32_t SFE_UBLOX_GPS::getPositionAccuracy(uint16_t maxWait)
649649
}
650650
//Get the current latitude in degrees
651651
//Returns a long representing the number of degrees *10^-7
652-
uint32_t SFE_UBLOX_GPS::getLatitude(uint16_t maxWait)
652+
int32_t SFE_UBLOX_GPS::getLatitude(uint16_t maxWait)
653653
{
654654
//Query the module for the latest lat/long
655655
packetCfg.cls = UBX_CLASS_NAV;
@@ -671,7 +671,7 @@ uint32_t SFE_UBLOX_GPS::getLatitude(uint16_t maxWait)
671671

672672
//Get the current longitude in degrees
673673
//Returns a long representing the number of degrees *10^-7
674-
uint32_t SFE_UBLOX_GPS::getLongitude(uint16_t maxWait)
674+
int32_t SFE_UBLOX_GPS::getLongitude(uint16_t maxWait)
675675
{
676676
//Query the module for the latest lat/long
677677
packetCfg.cls = UBX_CLASS_NAV;
@@ -689,4 +689,50 @@ uint32_t SFE_UBLOX_GPS::getLongitude(uint16_t maxWait)
689689
pos |= payloadCfg[7] << 8*3;
690690

691691
return(pos);
692+
}
693+
694+
//Get the current altitude in mm according to the Ellipsoid model.
695+
//Ellipsoid model: https://www.esri.com/news/arcuser/0703/geoid1of3.html
696+
//Difference between Ellipsoid Model and Mean Sea Level: https://eos-gnss.com/elevation-for-beginners/
697+
int32_t SFE_UBLOX_GPS::getAltitudeEllipsoid(uint16_t maxWait)
698+
{
699+
//Send packet with only CLS and ID, length of zero. This will cause the module to respond with the contents of that CLS/ID.
700+
packetCfg.cls = UBX_CLASS_NAV;
701+
packetCfg.id = UBX_NAV_POSLLH;
702+
packetCfg.len = 0;
703+
704+
if(sendCommand(packetCfg, maxWait) == false)
705+
return(0); //If command send fails then bail
706+
707+
//We got a response, now parse the byte fields
708+
uint32_t alt = 0;
709+
alt |= payloadCfg[12] << 8*0;
710+
alt |= payloadCfg[13] << 8*1;
711+
alt |= payloadCfg[14] << 8*2;
712+
alt |= payloadCfg[15] << 8*3;
713+
714+
return(alt);
715+
}
716+
717+
//Get the current altitude in mm according to mean sea level
718+
//Ellipsoid model: https://www.esri.com/news/arcuser/0703/geoid1of3.html
719+
//Difference between Ellipsoid Model and Mean Sea Level: https://eos-gnss.com/elevation-for-beginners/
720+
int32_t SFE_UBLOX_GPS::getAltitude(uint16_t maxWait)
721+
{
722+
//Send packet with only CLS and ID, length of zero. This will cause the module to respond with the contents of that CLS/ID.
723+
packetCfg.cls = UBX_CLASS_NAV;
724+
packetCfg.id = UBX_NAV_POSLLH;
725+
packetCfg.len = 0;
726+
727+
if(sendCommand(packetCfg, maxWait) == false)
728+
return(0); //If command send fails then bail
729+
730+
//We got a response, now parse the byte fields
731+
uint32_t alt = 0;
732+
alt |= payloadCfg[16] << 8*0;
733+
alt |= payloadCfg[17] << 8*1;
734+
alt |= payloadCfg[18] << 8*2;
735+
alt |= payloadCfg[19] << 8*3;
736+
737+
return(alt);
692738
}

Diff for: src/SparkFun_Ublox_Arduino_Library.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ class SFE_UBLOX_GPS
174174

175175
uint32_t getPositionAccuracy(uint16_t maxWait = 500); //Returns the 3D accuracy of the current high-precision fix, in mm. Supported on NEO-M8P, ZED-F9P,
176176

177-
uint32_t getLatitude(uint16_t maxWait = 250); //Returns the current latitude in degrees * 10^-7. Auto selects between HighPrecision and Regular depending on ability of module.
178-
uint32_t getLongitude(uint16_t maxWait = 250); //Returns the current longitude in degrees * 10-7. Auto selects between HighPrecision and Regular depending on ability of module.
177+
int32_t getLatitude(uint16_t maxWait = 250); //Returns the current latitude in degrees * 10^-7. Auto selects between HighPrecision and Regular depending on ability of module.
178+
int32_t getLongitude(uint16_t maxWait = 250); //Returns the current longitude in degrees * 10-7. Auto selects between HighPrecision and Regular depending on ability of module.
179+
int32_t getAltitude(uint16_t maxWait = 250); //Returns the current altitude in mm above mean sea level (most common output of GPS receivers).
180+
int32_t getAltitudeEllipsoid(uint16_t maxWait = 250); //Returns the current altitude in mm, ellipsoid model.
179181

180182
struct svinStructure {
181183
boolean active;

0 commit comments

Comments
 (0)