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

Commit 4578550

Browse files
committed
Added setDynamicModel (and made some minor corrections)
1 parent ab0bf7a commit 4578550

File tree

4 files changed

+166
-5
lines changed

4 files changed

+166
-5
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
Set Dynamic Model
3+
By: Paul Clark (PaulZC)
4+
Date: December 18th, 2019
5+
6+
Based extensively on Example3_GetPosition
7+
By: Nathan Seidle
8+
SparkFun Electronics
9+
Date: January 3rd, 2019
10+
License: MIT. See license file for more information but you can
11+
basically do whatever you want with this code.
12+
13+
This example shows how to change the Ublox module's dynamic platform model and then
14+
query its lat/long/altitude. We also turn off the NMEA output on the I2C port.
15+
This decreases the amount of I2C traffic dramatically.
16+
17+
Possible values for the dynamic model are: PORTABLE, STATIONARY, PEDESTRIAN, AUTOMOTIVE,
18+
SEA, AIRBORNE1g, AIRBORNE2g, AIRBORNE4g, WRIST, BIKE
19+
20+
Note: Long/lat are large numbers because they are * 10^7. To convert lat/long
21+
to something google maps understands simply divide the numbers by 10,000,000. We
22+
do this so that we don't have to use floating point numbers.
23+
24+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
25+
26+
Feel like supporting open source hardware?
27+
Buy a board from SparkFun!
28+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
29+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
30+
SAM-M8Q: https://www.sparkfun.com/products/15106
31+
32+
Hardware Connections:
33+
Plug a Qwiic cable into the GPS and a BlackBoard
34+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
35+
Open the serial monitor at 115200 baud to see the output
36+
*/
37+
38+
#include <Wire.h> //Needed for I2C to GPS
39+
40+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
41+
SFE_UBLOX_GPS myGPS;
42+
43+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
44+
45+
void setup()
46+
{
47+
Serial.begin(115200);
48+
while (!Serial); //Wait for user to open terminal
49+
Serial.println("SparkFun Ublox Example");
50+
51+
Wire.begin();
52+
53+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
54+
{
55+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
56+
while (1);
57+
}
58+
59+
//myGPS.enableDebugging(); // Uncomment this line to enable debug messages
60+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
61+
62+
// If we are going to change the dynamic platform model, let's do it here.
63+
// Possible values are:
64+
// PORTABLE, STATIONARY, PEDESTRIAN, AUTOMOTIVE, SEA, AIRBORNE1g, AIRBORNE2g, AIRBORNE4g, WRIST, BIKE
65+
66+
if (!myGPS.setDynamicModel(myGPS.PORTABLE)) // Set the dynamic model to PORTABLE
67+
{
68+
Serial.println("***!!! Warning: setDynamicModel failed !!!***");
69+
}
70+
else
71+
{
72+
Serial.println("Dynamic platform model changed successfully!");
73+
}
74+
75+
//myGPS.saveConfiguration(); //Uncomment this line to save the current settings to flash and BBR
76+
}
77+
78+
void loop()
79+
{
80+
//Query module only every second. Doing it more often will just cause I2C traffic.
81+
//The module only responds when a new position is available
82+
if (millis() - lastTime > 1000)
83+
{
84+
lastTime = millis(); //Update the timer
85+
86+
long latitude = myGPS.getLatitude();
87+
Serial.print(F("Lat: "));
88+
Serial.print(latitude);
89+
90+
long longitude = myGPS.getLongitude();
91+
Serial.print(F(" Long: "));
92+
Serial.print(longitude);
93+
Serial.print(F(" (degrees * 10^-7)"));
94+
95+
long altitude = myGPS.getAltitude();
96+
Serial.print(F(" Alt: "));
97+
Serial.print(altitude);
98+
Serial.print(F(" (mm)"));
99+
100+
Serial.println();
101+
}
102+
}

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ addGeofence KEYWORD2
125125
clearGeofences KEYWORD2
126126
getGeofenceState KEYWORD2
127127

128+
setDynamicModel KEYWORD2
129+
128130
#######################################
129131
# Constants (LITERAL1)
130132
#######################################

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ void SFE_UBLOX_GPS::setSerialRate(uint32_t baudrate, uint8_t uartPort, uint16_t
164164
_debugSerial->println(((uint32_t)payloadCfg[10] << 16) | ((uint32_t)payloadCfg[9] << 8) | payloadCfg[8]);
165165
}
166166

167-
sendCommand(packetCfg);
167+
sendCommand(packetCfg, maxWait);
168168
}
169169

170170
//Changes the I2C address that the Ublox module responds to
171171
//0x42 is the default but can be changed with this command
172172
boolean SFE_UBLOX_GPS::setI2CAddress(uint8_t deviceAddress, uint16_t maxWait)
173173
{
174174
//Get the current config values for the I2C port
175-
getPortSettings(COM_PORT_I2C); //This will load the payloadCfg array with current port settings
175+
getPortSettings(COM_PORT_I2C, maxWait); //This will load the payloadCfg array with current port settings
176176

177177
packetCfg.cls = UBX_CLASS_CFG;
178178
packetCfg.id = UBX_CFG_PRT;
@@ -1361,7 +1361,7 @@ boolean SFE_UBLOX_GPS::getSurveyMode(uint16_t maxWait)
13611361
//Control Survey-In for NEO-M8P
13621362
boolean SFE_UBLOX_GPS::setSurveyMode(uint8_t mode, uint16_t observationTime, float requiredAccuracy, uint16_t maxWait)
13631363
{
1364-
if (getSurveyMode() == false) //Ask module for the current TimeMode3 settings. Loads into payloadCfg.
1364+
if (getSurveyMode(maxWait) == false) //Ask module for the current TimeMode3 settings. Loads into payloadCfg.
13651365
return (false);
13661366

13671367
packetCfg.cls = UBX_CLASS_CFG;
@@ -1488,9 +1488,13 @@ boolean SFE_UBLOX_GPS::getPortSettings(uint8_t portID, uint16_t maxWait)
14881488
boolean SFE_UBLOX_GPS::setPortOutput(uint8_t portID, uint8_t outStreamSettings, uint16_t maxWait)
14891489
{
14901490
//Get the current config values for this port ID
1491-
if (getPortSettings(portID) == false)
1491+
if (getPortSettings(portID, maxWait) == false)
14921492
return (false); //Something went wrong. Bail.
14931493

1494+
// Let's make sure we wait for the ACK too (sendCommand will have returned as soon as the module sent its response)
1495+
// This is only required because we are doing two sendCommands in quick succession using the same class and ID
1496+
waitForResponse(UBX_CLASS_CFG, UBX_CFG_PRT, 100); // But we'll only wait for 100msec max
1497+
14941498
//Yes, this is the depreciated way to do it but it's still supported on v27 so it
14951499
//covers both ZED-F9P (v27) and SAM-M8Q (v18)
14961500

@@ -1512,9 +1516,13 @@ boolean SFE_UBLOX_GPS::setPortInput(uint8_t portID, uint8_t inStreamSettings, ui
15121516
{
15131517
//Get the current config values for this port ID
15141518
//This will load the payloadCfg array with current port settings
1515-
if (getPortSettings(portID) == false)
1519+
if (getPortSettings(portID, maxWait) == false)
15161520
return (false); //Something went wrong. Bail.
15171521

1522+
// Let's make sure we wait for the ACK too (sendCommand will have returned as soon as the module sent its response)
1523+
// This is only required because we are doing two sendCommands in quick succession using the same class and ID
1524+
waitForResponse(UBX_CLASS_CFG, UBX_CFG_PRT, 100); // But we'll only wait for 100msec max
1525+
15181526
packetCfg.cls = UBX_CLASS_CFG;
15191527
packetCfg.id = UBX_CFG_PRT;
15201528
packetCfg.len = 20;
@@ -1789,6 +1797,36 @@ boolean SFE_UBLOX_GPS::getGeofenceState(geofenceState &currentGeofenceState, uin
17891797
return(true);
17901798
}
17911799

1800+
//Change the dynamic platform model using UBX-CFG-NAV5
1801+
//Possible values are:
1802+
//PORTABLE,STATIONARY,PEDESTRIAN,AUTOMOTIVE,SEA,
1803+
//AIRBORNE1g,AIRBORNE2g,AIRBORNE4g,WRIST,BIKE
1804+
//WRIST is not supported in protocol versions less than 18
1805+
//BIKE is supported in protocol versions 19.2
1806+
boolean SFE_UBLOX_GPS::setDynamicModel(uint8_t newDynamicModel, uint16_t maxWait)
1807+
{
1808+
packetCfg.cls = UBX_CLASS_CFG;
1809+
packetCfg.id = UBX_CFG_NAV5;
1810+
packetCfg.len = 0;
1811+
packetCfg.startingSpot = 0;
1812+
1813+
if (sendCommand(packetCfg, maxWait) == false) //Ask module for the current navigation model settings. Loads into payloadCfg.
1814+
return (false);
1815+
1816+
// Let's make sure we wait for the ACK too (sendCommand will have returned as soon as the module sent its response)
1817+
// This is only required because we are doing two sendCommands in quick succession using the same class and ID
1818+
waitForResponse(UBX_CLASS_CFG, UBX_CFG_NAV5, 100); // But we'll only wait for 100msec max
1819+
1820+
payloadCfg[0] = 0x01; // mask: set only the dyn bit (0)
1821+
payloadCfg[1] = 0x00; // mask
1822+
payloadCfg[2] = newDynamicModel; // dynModel
1823+
1824+
packetCfg.len = 36;
1825+
packetCfg.startingSpot = 0;
1826+
1827+
return (sendCommand(packetCfg, maxWait)); //Wait for ack
1828+
}
1829+
17921830
//Given a spot in the payload array, extract four bytes and build a long
17931831
uint32_t SFE_UBLOX_GPS::extractLong(uint8_t spotToStart)
17941832
{

src/SparkFun_Ublox_Arduino_Library.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const uint8_t UBX_CFG_PRT = 0x00; //Used to configure port specifics
9999
const uint8_t UBX_CFG_RST = 0x04; //Used to reset device
100100
const uint8_t UBX_CFG_RATE = 0x08; //Used to set port baud rates
101101
const uint8_t UBX_CFG_CFG = 0x09; //Used to save current configuration
102+
const uint8_t UBX_CFG_NAV5 = 0x24; //Used to configure the navigation engine including the dynamic model
102103
const uint8_t UBX_CFG_VALSET = 0x8A; //Used for config of higher version Ublox modules (ie protocol v27 and above)
103104
const uint8_t UBX_CFG_VALGET = 0x8B; //Used for config of higher version Ublox modules (ie protocol v27 and above)
104105
const uint8_t UBX_CFG_VALDEL = 0x8C; //Used for config of higher version Ublox modules (ie protocol v27 and above)
@@ -344,6 +345,9 @@ class SFE_UBLOX_GPS
344345
boolean clearGeofences(uint16_t maxWait = 2000); //Clears all geofences
345346
boolean getGeofenceState(geofenceState &currentGeofenceState, uint16_t maxWait = 2000); //Returns the combined geofence state
346347

348+
//Change the dynamic platform model using UBX-CFG-NAV5
349+
boolean setDynamicModel(uint8_t newDynamicModel = PEDESTRIAN, uint16_t maxWait = 2000);
350+
347351
//Survey-in specific controls
348352
struct svinStructure
349353
{
@@ -417,6 +421,21 @@ class SFE_UBLOX_GPS
417421

418422
uint16_t rtcmFrameCounter = 0; //Tracks the type of incoming byte inside RTCM frame
419423

424+
enum dynModel // Possible values for the dynamic platform model
425+
{
426+
PORTABLE = 0,
427+
// 1 is not defined
428+
STATIONARY = 2,
429+
PEDESTRIAN,
430+
AUTOMOTIVE,
431+
SEA,
432+
AIRBORNE1g,
433+
AIRBORNE2g,
434+
AIRBORNE4g,
435+
WRIST, // Not supported in protocol versions less than 18
436+
BIKE // Supported in protocol versions 19.2
437+
};
438+
420439
private:
421440
//Depending on the sentence type the processor will load characters into different arrays
422441
enum SentenceTypes

0 commit comments

Comments
 (0)