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

Commit e106c22

Browse files
committed
Add altitudeMSL
1 parent 5d5387d commit e106c22

File tree

2 files changed

+55
-17
lines changed

2 files changed

+55
-17
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,8 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
899899
SIV = extractByte(23 - packetCfg.startingSpot);
900900
longitude = extractLong(24 - packetCfg.startingSpot);
901901
latitude = extractLong(28 - packetCfg.startingSpot);
902-
altitude = extractLong(36 - packetCfg.startingSpot);
902+
altitude = extractLong(32 - packetCfg.startingSpot);
903+
altitudeMSL = extractLong(36 - packetCfg.startingSpot);
903904
groundSpeed = extractLong(60 - packetCfg.startingSpot);
904905
headingOfMotion = extractLong(64 - packetCfg.startingSpot);
905906
pDOP = extractLong(76 - packetCfg.startingSpot);
@@ -910,6 +911,7 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
910911
moduleQueried.longitude = true;
911912
moduleQueried.latitude = true;
912913
moduleQueried.altitude = true;
914+
moduleQueried.altitudeMSL = true;
913915
moduleQueried.SIV = true;
914916
moduleQueried.fixType = true;
915917
moduleQueried.carrierSolution = true;
@@ -921,7 +923,7 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
921923
}
922924

923925
//Get the current 3D high precision positional accuracy - a fun thing to watch
924-
//Returns a float representing the 3D accuracy in millimeters
926+
//Returns a long representing the 3D accuracy in millimeters
925927
uint32_t SFE_UBLOX_GPS::getPositionAccuracy(uint16_t maxWait)
926928
{
927929
packetCfg.cls = UBX_CLASS_NAV;
@@ -959,9 +961,7 @@ int32_t SFE_UBLOX_GPS::getLongitude(uint16_t maxWait)
959961
return(longitude);
960962
}
961963

962-
//Get the current altitude in mm according to mean sea level
963-
//Ellipsoid model: https://www.esri.com/news/arcuser/0703/geoid1of3.html
964-
//Difference between Ellipsoid Model and Mean Sea Level: https://eos-gnss.com/elevation-for-beginners/
964+
//Get the current altitude in mm according to ellipsoid model
965965
int32_t SFE_UBLOX_GPS::getAltitude(uint16_t maxWait)
966966
{
967967
if(moduleQueried.altitude == false) getPVT();
@@ -970,6 +970,17 @@ int32_t SFE_UBLOX_GPS::getAltitude(uint16_t maxWait)
970970
return(altitude);
971971
}
972972

973+
//Get the current altitude in mm according to mean sea level
974+
//Ellipsoid model: https://www.esri.com/news/arcuser/0703/geoid1of3.html
975+
//Difference between Ellipsoid Model and Mean Sea Level: https://eos-gnss.com/elevation-for-beginners/
976+
int32_t SFE_UBLOX_GPS::getAltitudeMSL(uint16_t maxWait)
977+
{
978+
if(moduleQueried.altitudeMSL == false) getPVT();
979+
moduleQueried.altitudeMSL = false; //Since we are about to give this to user, mark this data as stale
980+
981+
return(altitudeMSL);
982+
}
983+
973984
//Get the number of satellites used in fix
974985
uint8_t SFE_UBLOX_GPS::getSIV(uint16_t maxWait)
975986
{
@@ -1030,6 +1041,24 @@ uint16_t SFE_UBLOX_GPS::getPDOP(uint16_t maxWait)
10301041
//Get the current protocol version of the Ublox module we're communicating with
10311042
//This is helpful when deciding if we should call the high-precision Lat/Long (HPPOSLLH) or the regular (POSLLH)
10321043
uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
1044+
{
1045+
if(moduleQueried.versionNumber == false) getProtocolVersion();
1046+
moduleQueried.versionNumber = false;
1047+
return(versionHigh);
1048+
}
1049+
1050+
//Get the current protocol version of the Ublox module we're communicating with
1051+
//This is helpful when deciding if we should call the high-precision Lat/Long (HPPOSLLH) or the regular (POSLLH)
1052+
uint8_t SFE_UBLOX_GPS::getProtocolVersionLow(uint16_t maxWait)
1053+
{
1054+
if(moduleQueried.versionNumber == false) getProtocolVersion();
1055+
moduleQueried.versionNumber = false;
1056+
return(versionLow);
1057+
}
1058+
1059+
//Get the current protocol version of the Ublox module we're communicating with
1060+
//This is helpful when deciding if we should call the high-precision Lat/Long (HPPOSLLH) or the regular (POSLLH)
1061+
boolean SFE_UBLOX_GPS::getProtocolVersion(uint16_t maxWait)
10331062
{
10341063
//Send packet with only CLS and ID, length of zero. This will cause the module to respond with the contents of that CLS/ID.
10351064
packetCfg.cls = UBX_CLASS_MON;
@@ -1043,7 +1072,7 @@ uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
10431072
packetCfg.startingSpot = 40 + (30*extensionNumber);
10441073

10451074
if(sendCommand(packetCfg, maxWait) == false)
1046-
return(0); //If command send fails then bail
1075+
return(false); //If command send fails then bail
10471076

10481077
#ifdef DEBUG
10491078
Serial.print("Extension ");
@@ -1060,10 +1089,13 @@ uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
10601089
//Now we need to find "PROTVER=18.00" in the incoming byte stream
10611090
if(payloadCfg[0] == 'P' && payloadCfg[6] == 'R')
10621091
{
1063-
byte versionHigh = (payloadCfg[8] - '0') * 10 + (payloadCfg[9] - '0'); //Convert '18' to 18
1064-
return(versionHigh);
1092+
versionHigh = (payloadCfg[8] - '0') * 10 + (payloadCfg[9] - '0'); //Convert '18' to 18
1093+
versionLow = (payloadCfg[11] - '0') * 10 + (payloadCfg[12] - '0'); //Convert '00' to 00
1094+
return(versionLow);
10651095
}
10661096
}
10671097

1068-
return(0);
1098+
moduleQueried.versionNumber = true; //Mark this data as new
1099+
1100+
return(true);
10691101
}

src/SparkFun_Ublox_Arduino_Library.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
//Uncomment the following line to enable a variety of debug statements
4141
//This will increase the codeword and RAM footprint of the library
42-
//#define DEBUG
42+
#define DEBUG
4343

4444
#ifdef DEBUG
4545
#define debug Serial //Point debug statements to print to Serial port
@@ -207,7 +207,8 @@ class SFE_UBLOX_GPS
207207
boolean getPVT(uint16_t maxWait = 1000); //Query module for latest group of datums and load global vars: lat, long, alt, speed, SIV, accuracies, etc.
208208
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.
209209
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.
210-
int32_t getAltitude(uint16_t maxWait = 250); //Returns the current altitude in mm above mean sea level (most common output of GPS receivers).
210+
int32_t getAltitude(uint16_t maxWait = 250); //Returns the current altitude in mm above ellipsoid
211+
int32_t getAltitudeMSL(uint16_t maxWait = 250); //Returns the current altitude in mm above mean sea level
211212
uint8_t getSIV(uint16_t maxWait = 250); //Returns number of sats used in fix
212213
uint8_t getFixType(uint16_t maxWait = 250); //Returns the type of fix: 0=no, 3=3D, 4=GNSS+Deadreckoning
213214
uint8_t getCarrierSolutionType(uint16_t maxWait = 250); //Returns RTK solution: 0=no, 1=float solution, 2=fixed solution
@@ -242,8 +243,8 @@ class SFE_UBLOX_GPS
242243
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,
243244

244245
uint8_t getProtocolVersionHigh(uint16_t maxWait = 1000); //Returns the PROTVER XX.00 from UBX-MON-VER register
245-
//uint8_t getProtocolVersionLow(uint16_t maxWait = 1000); //Returns the PROTVER 00.XX from UBX-MON-VER register
246-
//float getProtocolVersion(uint16_t maxWait = 1000); //Returns the combination of high&low portions from PROTVER in UBX-MON-VER register
246+
uint8_t getProtocolVersionLow(uint16_t maxWait = 1000); //Returns the PROTVER 00.XX from UBX-MON-VER register
247+
boolean getProtocolVersion(uint16_t maxWait = 1000); //Queries module, loads low/high bytes
247248

248249
//Survey-in specific controls
249250
struct svinStructure {
@@ -256,15 +257,18 @@ class SFE_UBLOX_GPS
256257
//The major datums we want to globally store
257258
int32_t latitude; //Degrees * 10^-7 (more accurate than floats)
258259
int32_t longitude; //Degrees * 10^-7 (more accurate than floats)
259-
int32_t altitude; //Number of mm above Mean Sea Level
260+
int32_t altitude; //Number of mm above ellipsoid
261+
int32_t altitudeMSL; //Number of mm above Mean Sea Level
260262
uint8_t SIV; //Number of satellites used in position solution
261263
uint8_t fixType; //Tells us when we have a solution aka lock
262264
uint8_t carrierSolution; //Tells us when we have an RTK float/fixed solution
263265
int32_t groundSpeed; //mm/s
264-
int32_t headingOfMotion; //degress * 10^-5
265-
uint16_t pDOP; //Positional dillution of precision
266+
int32_t headingOfMotion; //degrees * 10^-5
267+
uint16_t pDOP; //Positional dilution of precision
268+
uint8_t versionLow; //Loaded from getProtocolVersion().
269+
uint8_t versionHigh;
266270

267-
uint16_t rtcmFrameCounter = 0;
271+
uint16_t rtcmFrameCounter = 0; //Tracks the type of incoming byte inside RTCM frame
268272

269273
private:
270274

@@ -329,12 +333,14 @@ class SFE_UBLOX_GPS
329333
uint16_t longitude : 1;
330334
uint16_t latitude : 1;
331335
uint16_t altitude : 1;
336+
uint16_t altitudeMSL : 1;
332337
uint16_t SIV : 1;
333338
uint16_t fixType : 1;
334339
uint16_t carrierSolution : 1;
335340
uint16_t groundSpeed : 1;
336341
uint16_t headingOfMotion : 1;
337342
uint16_t pDOP : 1;
343+
uint16_t versionNumber : 1;
338344
} moduleQueried;
339345

340346
uint16_t rtcmLen = 0;

0 commit comments

Comments
 (0)