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

Commit 3d3df64

Browse files
committed
Add ground speed, heading, and pDOP.
1 parent 9dcc2ff commit 3d3df64

File tree

4 files changed

+100
-46
lines changed

4 files changed

+100
-46
lines changed

examples/Example3_GetPosition/Example3_GetPosition.ino

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void setup()
4545

4646
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
4747

48-
48+
4949
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
5050
myGPS.setNavigationFrequency(4); //Set output to 4 times a second
5151

@@ -83,41 +83,55 @@ void setup()
8383
byte RTK = myGPS.getCarrierSolutionType();
8484
Serial.print(" RTK: ");
8585
Serial.print(RTK);
86-
if(RTK == 1) Serial.println("High precision float fix!");
87-
if(RTK == 2) Serial.println("High precision fix!");
86+
if (RTK == 1) Serial.println("High precision float fix!");
87+
if (RTK == 2) Serial.println("High precision fix!");
88+
89+
long speed = myGPS.getGroundSpeed();
90+
Serial.print(" Speed: ");
91+
Serial.print(speed);
92+
Serial.print(" (mm/s)");
93+
94+
long heading = myGPS.getHeading();
95+
Serial.print(" Heading: ");
96+
Serial.print(heading);
97+
Serial.print(" (degrees * 10^-5)");
98+
99+
int pDOP = myGPS.getPDOP();
100+
Serial.print(" pDOP: ");
101+
Serial.print(pDOP / 100.0, 2);
88102

89103
while (1);
90104
}
91105

92106
void loop()
93107
{
94-
/* myGPS.checkUblox(); //See if new data is available. Process bytes as they come in.
95-
96-
delay(250); //Don't pound too hard on the I2C bus
97-
98-
//Every other second print the current 3D position accuracy
99-
if (millis() - lastTime > 1000)
100-
{
101-
long latitude = myGPS.getLatitude();
102-
Serial.print("Lat: ");
103-
Serial.print(latitude);
104-
105-
while (1);
106-
107-
long longitude = myGPS.getLongitude();
108-
Serial.print(" Long: ");
109-
Serial.print(longitude);
110-
Serial.print(" (degrees * 10^-7)");
111-
112-
long altitude = myGPS.getAltitude();
113-
Serial.print(" Alt (above mean sea level): ");
114-
Serial.print(altitude);
115-
Serial.print(" (mm)");
116-
117-
long altitudeEllipsoid = myGPS.getAltitudeEllipsoid();
118-
Serial.print(" AltMSL (above Ellipsoid model surface of earth): ");
119-
Serial.print(altitudeEllipsoid);
120-
Serial.println(" (mm)");
121-
}*/
108+
/* myGPS.checkUblox(); //See if new data is available. Process bytes as they come in.
109+
110+
delay(250); //Don't pound too hard on the I2C bus
111+
112+
//Every other second print the current 3D position accuracy
113+
if (millis() - lastTime > 1000)
114+
{
115+
long latitude = myGPS.getLatitude();
116+
Serial.print("Lat: ");
117+
Serial.print(latitude);
118+
119+
while (1);
120+
121+
long longitude = myGPS.getLongitude();
122+
Serial.print(" Long: ");
123+
Serial.print(longitude);
124+
Serial.print(" (degrees * 10^-7)");
125+
126+
long altitude = myGPS.getAltitude();
127+
Serial.print(" Alt (above mean sea level): ");
128+
Serial.print(altitude);
129+
Serial.print(" (mm)");
130+
131+
long altitudeEllipsoid = myGPS.getAltitudeEllipsoid();
132+
Serial.print(" AltMSL (above Ellipsoid model surface of earth): ");
133+
Serial.print(altitudeEllipsoid);
134+
Serial.println(" (mm)");
135+
}*/
122136

123137
}

examples/NEO-M8P-2/Example4_StartRTCMBase/Example4_StartRTCMBase.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void setup()
3737

3838
Wire.begin();
3939

40-
myGPS.begin(Wire); //Connect to the Ublox module using Wire port
40+
myGPS.begin(); //Connect to the Ublox module using Wire port
4141
if (myGPS.isConnected() == false)
4242
{
4343
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
@@ -114,10 +114,10 @@ void setup()
114114
Serial.println("Survey valid!");
115115

116116
response = true;
117-
response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, UBX_RTCM_I2C_PORT, 1); //Enable message 1005 to output through I2C port, message every second
118-
response &= myGPS.enableRTCMmessage(UBX_RTCM_1077, UBX_RTCM_I2C_PORT, 1);
119-
response &= myGPS.enableRTCMmessage(UBX_RTCM_1087, UBX_RTCM_I2C_PORT, 1);
120-
response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, UBX_RTCM_I2C_PORT, 10); //Enable message every 10 seconds
117+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_I2C, 1); //Enable message 1005 to output through I2C port, message every second
118+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1077, COM_PORT_I2C, 1);
119+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1087, COM_PORT_I2C, 1);
120+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, COM_PORT_I2C, 10); //Enable message every 10 seconds
121121

122122
if (response == true)
123123
{

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,9 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
802802
longitude = extractLong(24 - packetCfg.startingSpot);
803803
latitude = extractLong(28 - packetCfg.startingSpot);
804804
altitude = extractLong(36 - packetCfg.startingSpot);
805+
groundSpeed = extractLong(60 - packetCfg.startingSpot);
806+
headingOfMotion = extractLong(64 - packetCfg.startingSpot);
807+
pDOP = extractLong(76 - packetCfg.startingSpot);
805808

806809
//Mark all datums as fresh (not read before)
807810
//moduleQueried ThisStruct;
@@ -812,6 +815,9 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
812815
moduleQueried.SIV = true;
813816
moduleQueried.fixType = true;
814817
moduleQueried.carrierSolution = true;
818+
moduleQueried.groundSpeed = true;
819+
moduleQueried.headingOfMotion = true;
820+
moduleQueried.pDOP = true;
815821

816822
return(true);
817823
}
@@ -896,6 +902,33 @@ uint8_t SFE_UBLOX_GPS::getCarrierSolutionType(uint16_t maxWait)
896902
return(carrierSolution);
897903
}
898904

905+
//Get the ground speed in mm/s
906+
int32_t SFE_UBLOX_GPS::getGroundSpeed(uint16_t maxWait)
907+
{
908+
if(moduleQueried.groundSpeed == false) getPVT();
909+
moduleQueried.groundSpeed = false; //Since we are about to give this to user, mark this data as stale
910+
911+
return(groundSpeed);
912+
}
913+
914+
//Get the heading of motion (as opposed to heading of car) in degrees * 10^-5
915+
int32_t SFE_UBLOX_GPS::getHeading(uint16_t maxWait)
916+
{
917+
if(moduleQueried.headingOfMotion == false) getPVT();
918+
moduleQueried.headingOfMotion = false; //Since we are about to give this to user, mark this data as stale
919+
920+
return(headingOfMotion);
921+
}
922+
923+
//Get the positional dillution of precision * 10^-2
924+
uint16_t SFE_UBLOX_GPS::getPDOP(uint16_t maxWait)
925+
{
926+
if(moduleQueried.pDOP == false) getPVT();
927+
moduleQueried.pDOP = false; //Since we are about to give this to user, mark this data as stale
928+
929+
return(pDOP);
930+
}
931+
899932
//Get the current protocol version of the Ublox module we're communicating with
900933
//This is helpful when deciding if we should call the high-precision Lat/Long (HPPOSLLH) or the regular (POSLLH)
901934
uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)

src/SparkFun_Ublox_Arduino_Library.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class SFE_UBLOX_GPS
187187

188188
boolean setPortOutput(uint8_t portID, uint8_t comSettings, uint16_t maxWait = 250); //Configure a given port to output UBX, NMEA, RTCM3 or a combination thereof
189189
boolean setPortInput(uint8_t portID, uint8_t comSettings, uint16_t maxWait = 250); //Configure a given port to input UBX, NMEA, RTCM3 or a combination thereof
190+
boolean getPortSettings(uint8_t portID, uint16_t maxWait = 250); //Returns the current protocol bits in the UBX-CFG-PRT command for a given port
190191

191192
boolean setI2COutput(uint8_t comSettings, uint16_t maxWait = 250); //Configure I2C port to output UBX, NMEA, RTCM3 or a combination thereof
192193
boolean setUART1Output(uint8_t comSettings, uint16_t maxWait = 250); //Configure UART1 port to output UBX, NMEA, RTCM3 or a combination thereof
@@ -195,10 +196,6 @@ class SFE_UBLOX_GPS
195196
boolean setSPIOutput(uint8_t comSettings, uint16_t maxWait = 250); //Configure SPI port to output UBX, NMEA, RTCM3 or a combination thereof
196197

197198
boolean setNavigationFrequency(uint8_t navFreq, uint16_t maxWait = 250); //Set the number of nav solutions sent per second
198-
199-
boolean setRTCMport(uint8_t portID, boolean enableRTCM3, uint16_t maxWait = 250); //Enable/Disable RTCM3 (both input and output) for a given port
200-
201-
boolean getPortSettings(uint8_t portID, uint16_t maxWait = 250); //Returns the current protocol bits in the UBX-CFG-PRT command for a given port
202199

203200
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,
204201

@@ -209,6 +206,9 @@ class SFE_UBLOX_GPS
209206
uint8_t getSIV(uint16_t maxWait = 250); //Returns number of sats used in fix
210207
uint8_t getFixType(uint16_t maxWait = 250); //Returns the type of fix: 0=no, 3=3D, 4=GNSS+Deadreckoning
211208
uint8_t getCarrierSolutionType(uint16_t maxWait = 250); //Returns RTK solution: 0=no, 1=float solution, 2=fixed solution
209+
int32_t getGroundSpeed(uint16_t maxWait = 250); //Returns speed in mm/s
210+
int32_t getHeading(uint16_t maxWait = 250); //Returns heading in degrees * 10^-7
211+
uint16_t getPDOP(uint16_t maxWait = 250); //Returns positional dillution of precision * 10^-2
212212

213213
uint8_t getProtocolVersionHigh(uint16_t maxWait = 1000); //Returns the PROTVER XX.00 from UBX-MON-VER register
214214
//uint8_t getProtocolVersionLow(uint16_t maxWait = 1000); //Returns the PROTVER 00.XX from UBX-MON-VER register
@@ -222,12 +222,16 @@ class SFE_UBLOX_GPS
222222
float meanAccuracy;
223223
} svin;
224224

225-
int32_t latitude;
226-
int32_t longitude;
227-
int32_t altitude;
228-
uint8_t SIV;
229-
uint8_t fixType;
230-
uint8_t carrierSolution;
225+
//The major datums we want to globally store
226+
int32_t latitude; //Degrees * 10^-7 (more accurate than floats)
227+
int32_t longitude; //Degrees * 10^-7 (more accurate than floats)
228+
int32_t altitude; //Number of mm above Mean Sea Level
229+
uint8_t SIV; //Number of satellites used in position solution
230+
uint8_t fixType; //Tells us when we have a solution aka lock
231+
uint8_t carrierSolution; //Tells us when we have an RTK float/fixed solution
232+
int32_t groundSpeed; //mm/s
233+
int32_t headingOfMotion; //degress * 10^-5
234+
uint16_t pDOP; //Positional dillution of precision
231235

232236
uint16_t rtcmFrameCounter = 0;
233237

@@ -297,6 +301,9 @@ class SFE_UBLOX_GPS
297301
uint16_t SIV : 1;
298302
uint16_t fixType : 1;
299303
uint16_t carrierSolution : 1;
304+
uint16_t groundSpeed : 1;
305+
uint16_t headingOfMotion : 1;
306+
uint16_t pDOP : 1;
300307
} moduleQueried;
301308

302309
uint16_t rtcmLen = 0;

0 commit comments

Comments
 (0)