Skip to content

Commit c7a2223

Browse files
committed
Move to get/set val method for configuring ZED
1 parent 879d4b4 commit c7a2223

15 files changed

+375
-955
lines changed

Firmware/RTK_Surveyor/Base.ino

Lines changed: 88 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ bool configureUbloxModuleBase()
33
{
44
if (online.gnss == false) return (false);
55

6-
bool response = true;
7-
int maxWait = 2000;
8-
96
//If our settings haven't changed, and this is first config since power on, trust ZED's settings
107
if (settings.updateZEDSettings == false && firstPowerOn == true)
118
{
@@ -18,75 +15,73 @@ bool configureUbloxModuleBase()
1815

1916
i2cGNSS.checkUblox(); //Regularly poll to get latest data and any RTCM
2017

21-
const int baseNavigationFrequency = 1;
22-
23-
//In Base mode we force 1Hz
24-
response &= setRate(1);
25-
if (response == false)
26-
Serial.println("Set rate failed");
18+
i2cGNSS.setNMEAGPGGAcallbackPtr(NULL); // Disable GPGGA call back that may have been set during Rover NTRIP Client mode
2719

28-
i2cGNSS.checkUblox(); //Regularly poll to get latest data and any RTCM
20+
bool response = true;
2921

30-
i2cGNSS.setNMEAGPGGAcallbackPtr(NULL); // Disable GPGGA call back that may have been set during Rover NTRIP Client mode
31-
i2cGNSS.disableNMEAMessage(UBX_NMEA_GGA, COM_PORT_I2C); // Disable NMEA message that may have been set during Rover NTRIP Client mode
22+
//In Base mode we force 1Hz
23+
response &= i2cGNSS.newCfgValset16(UBLOX_CFG_RATE_MEAS, 1000);
24+
response &= i2cGNSS.addCfgValset16(UBLOX_CFG_RATE_NAV, 1);
3225

33-
response = i2cGNSS.setSurveyMode(0, 0, 0); //Disable Survey-In or Fixed Mode
34-
if (response == false)
35-
Serial.println("Disable TMODE3 failed");
26+
//Since we are at 1Hz, allow GSV NMEA to be reported at whatever the user has chosen
27+
response &= i2cGNSS.addCfgValset8(settings.ubxMessages[8].msgConfigKey, settings.ubxMessages[8].msgRate); //Update rate on module
3628

37-
// Set dynamic model
38-
if (i2cGNSS.getDynamicModel(maxWait) != DYN_MODEL_STATIONARY)
39-
{
40-
response &= i2cGNSS.setDynamicModel(DYN_MODEL_STATIONARY, maxWait);
41-
if (response == false)
42-
{
43-
Serial.println("setDynamicModel failed");
44-
return (false);
45-
}
46-
}
29+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_NMEA_ID_GGA_I2C, 0); // Disable NMEA message that may have been set during Rover NTRIP Client mode
4730

48-
#define OUTPUT_SETTING 14
31+
//Survey mode is only available on ZED-F9P modules
32+
if (zedModuleType == PLATFORM_F9P)
33+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_TMODE_MODE, 0); //Disable survey-in mode
4934

50-
//Turn on RTCM so that we can harvest RTCM over I2C and send out over WiFi
51-
//This is easier than parsing over UART because the library handles the frame detection
52-
getPortSettings(COM_PORT_I2C); //Load the settingPayload with this port's settings
53-
if (settingPayload[OUTPUT_SETTING] != (COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3))
54-
response &= i2cGNSS.setPortOutput(COM_PORT_I2C, COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3); //Set the I2C port to output UBX (config), and RTCM3 (casting)
55-
//response &= i2cGNSS.setPortOutput(COM_PORT_I2C, COM_TYPE_UBX | COM_TYPE_RTCM3); //Not a valid state. Goes to UBX+NMEA+RTCM3
35+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_NAVSPG_DYNMODEL, (dynModel)settings.dynamicModel); // Set dynamic model
5636

57-
//In base mode the Surveyor should output RTCM over all ports:
37+
//In base mode the RTK device should output RTCM over all ports:
5838
//(Primary) UART2 in case the Surveyor is connected via radio to rover
5939
//(Optional) I2C in case user wants base to connect to WiFi and NTRIP Caster
6040
//(Seconday) USB in case the Surveyor is used as an NTRIP caster connected to SBC or other
6141
//(Tertiary) UART1 in case Surveyor is sending RTCM to phone that is then NTRIP Caster
62-
response &= enableRTCMSentences(COM_PORT_UART2);
63-
response &= enableRTCMSentences(COM_PORT_UART1);
64-
response &= enableRTCMSentences(COM_PORT_USB);
65-
response &= enableRTCMSentences(COM_PORT_I2C); //Enable for plain radio so we can count RTCM packets for display
66-
67-
//If enabled, adjust GSV NMEA to be reported at 1Hz
68-
if (settings.ubxMessages[8].msgRate > baseNavigationFrequency)
69-
setMessageRateByName("UBX_NMEA_GSV", baseNavigationFrequency); //Update GSV setting in file
70-
71-
response &= configureGNSSMessageRates(COM_PORT_UART1, settings.ubxMessages); //In the interest of logging, make sure the appropriate messages are enabled
42+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_I2C, 1);
43+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1074_I2C, 1);
44+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1084_I2C, 1);
45+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1094_I2C, 1);
46+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1124_I2C, 1);
47+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_I2C, 1);
48+
49+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_USB, 1);
50+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1074_USB, 1);
51+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1084_USB, 1);
52+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1094_USB, 1);
53+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1124_USB, 1);
54+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_USB, 1);
55+
56+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_UART1, 1);
57+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1074_UART1, 1);
58+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1084_UART1, 1);
59+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1094_UART1, 1);
60+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1124_UART1, 1);
61+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_UART1, 1);
62+
63+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_UART2, 1);
64+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1074_UART2, 1);
65+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1084_UART2, 1);
66+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1094_UART2, 1);
67+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1124_UART2, 1);
68+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_UART2, 1);
69+
70+
response &= i2cGNSS.sendCfgValset8(UBLOX_CFG_MSGOUT_NMEA_ID_VTG_SPI, 0); //Dummy closing value - #31
7271

7372
if (response == false)
74-
{
75-
Serial.println("RTCM settings failed to enable");
76-
return (false);
77-
}
78-
79-
response &= i2cGNSS.saveConfiguration(); //Save the current settings to flash and BBR
80-
if (response == false)
81-
Serial.println("Module failed to save.");
73+
Serial.println("Base config fail");
8274

8375
return (response);
8476
}
8577

8678
//Start survey
8779
//The ZED-F9P is slightly different than the NEO-M8P. See the Integration manual 3.5.8 for more info.
88-
bool beginSurveyIn()
80+
bool surveyInStart()
8981
{
82+
i2cGNSS.setVal8(UBLOX_CFG_TMODE_MODE, 0); //Disable survey-in mode
83+
delay(100);
84+
9085
bool needSurveyReset = false;
9186
if (i2cGNSS.getSurveyInActive(100) == true) needSurveyReset = true;
9287
if (i2cGNSS.getSurveyInValid(100) == true) needSurveyReset = true;
@@ -95,17 +90,19 @@ bool beginSurveyIn()
9590
{
9691
Serial.println("Resetting survey");
9792

98-
if (resetSurvey() == false)
93+
if (surveyInReset() == false)
9994
{
10095
Serial.println("Survey reset failed");
101-
if (resetSurvey() == false)
102-
{
96+
if (surveyInReset() == false)
10397
Serial.println("Survey reset failed - 2nd attempt");
104-
}
10598
}
10699
}
107100

108-
bool response = i2cGNSS.enableSurveyMode(settings.observationSeconds, settings.observationPositionAccuracy, 5000); //Enable Survey in, with user parameters. Wait up to 5s.
101+
bool response = true;
102+
response &= i2cGNSS.setVal8(UBLOX_CFG_TMODE_MODE, 1); //Survey-in enable
103+
response &= i2cGNSS.setVal32(UBLOX_CFG_TMODE_SVIN_ACC_LIMIT, settings.observationPositionAccuracy * 10000);
104+
response &= i2cGNSS.setVal32(UBLOX_CFG_TMODE_SVIN_MIN_DUR, settings.observationSeconds);
105+
109106
if (response == false)
110107
{
111108
Serial.println("Survey start failed");
@@ -129,16 +126,25 @@ bool beginSurveyIn()
129126
return (true);
130127
}
131128

132-
bool resetSurvey()
129+
//Slightly modified method for restarting survey-in from: https://portal.u-blox.com/s/question/0D52p00009IsVoMCAV/restarting-surveyin-on-an-f9p
130+
bool surveyInReset()
133131
{
134132
int maxWait = 2000;
135133

136-
//Slightly modified method for restarting survey-in from: https://portal.u-blox.com/s/question/0D52p00009IsVoMCAV/restarting-surveyin-on-an-f9p
137-
bool response = i2cGNSS.setSurveyMode(maxWait, 0, 0); //Disable Survey-In or Fixed Mode
134+
bool response = true;
135+
136+
//Disable survey-in mode
137+
response &= i2cGNSS.setVal8(UBLOX_CFG_TMODE_MODE, 0);
138138
delay(1000);
139-
response &= i2cGNSS.enableSurveyMode(1000, 400.000, maxWait); //Enable Survey in with bogus values
139+
140+
//Enable Survey in with bogus values
141+
response &= i2cGNSS.newCfgValset8(UBLOX_CFG_TMODE_MODE, 1); //Survey-in enable
142+
response &= i2cGNSS.addCfgValset32(UBLOX_CFG_TMODE_SVIN_ACC_LIMIT, 40 * 10000); //40.0m
143+
response &= i2cGNSS.sendCfgValset32(UBLOX_CFG_TMODE_SVIN_MIN_DUR, 1000); //1000s
140144
delay(1000);
141-
response &= i2cGNSS.setSurveyMode(maxWait, 0, 0); //Disable Survey-In or Fixed Mode
145+
146+
//Disable survey-in mode
147+
response &= i2cGNSS.setVal8(UBLOX_CFG_TMODE_MODE, 0);
142148

143149
if (response == false)
144150
return (response);
@@ -158,7 +164,7 @@ bool resetSurvey()
158164
//Start the base using fixed coordinates
159165
bool startFixedBase()
160166
{
161-
bool response = false;
167+
bool response = true;
162168
int maxWait = 2000;
163169

164170
if (settings.fixedBaseCoordinateType == COORD_TYPE_ECEF)
@@ -178,20 +184,23 @@ bool startFixedBase()
178184

179185
//Units are cm with a high precision extension so -1234.5678 should be called: (-123456, -78)
180186
//-1280208.308,-4716803.847,4086665.811 is SparkFun HQ so...
181-
response = i2cGNSS.setStaticPosition(majorEcefX, minorEcefX,
182-
majorEcefY, minorEcefY,
183-
majorEcefZ, minorEcefZ,
184-
false,
185-
maxWait
186-
); //With high precision 0.1mm parts
187+
188+
response &= i2cGNSS.newCfgValset8(UBLOX_CFG_TMODE_MODE, 2); //Fixed
189+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_TMODE_POS_TYPE, 0); //Position in ECEF
190+
response &= i2cGNSS.addCfgValset32(UBLOX_CFG_TMODE_ECEF_X, majorEcefX);
191+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_TMODE_ECEF_X_HP, minorEcefX);
192+
response &= i2cGNSS.addCfgValset32(UBLOX_CFG_TMODE_ECEF_Y, majorEcefY);
193+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_TMODE_ECEF_Y_HP, minorEcefY);
194+
response &= i2cGNSS.addCfgValset32(UBLOX_CFG_TMODE_ECEF_Z, majorEcefZ);
195+
response &= i2cGNSS.sendCfgValset8(UBLOX_CFG_TMODE_ECEF_Z_HP, minorEcefZ);
187196
}
188197
else if (settings.fixedBaseCoordinateType == COORD_TYPE_GEODETIC)
189198
{
190199
//Add height of instrument (HI) to fixed altitude
191200
//https://www.e-education.psu.edu/geog862/node/1853
192201
//For example, if HAE is at 100.0m, + 2m stick + 73mm ARP = 102.073
193202
float totalFixedAltitude = settings.fixedAltitude + (settings.antennaHeight / 1000.0) + (settings.antennaReferencePoint / 1000.0);
194-
203+
195204
//Break coordinates into main and high precision parts
196205
//The type casting should not effect rounding of original double cast coordinate
197206
int64_t majorLat = settings.fixedLat * 10000000;
@@ -213,12 +222,14 @@ bool startFixedBase()
213222
// Serial.printf("major (should be 156022): %ld\r\n", majorAlt);
214223
// Serial.printf("minor (should be 84): %ld\r\n", minorAlt);
215224

216-
response = i2cGNSS.setStaticPosition(
217-
majorLat, minorLat,
218-
majorLong, minorLong,
219-
majorAlt, minorAlt,
220-
true, //Use lat/long as input
221-
maxWait);
225+
response &= i2cGNSS.newCfgValset8(UBLOX_CFG_TMODE_MODE, 2); //Fixed
226+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_TMODE_POS_TYPE, 1); //Position in LLH
227+
response &= i2cGNSS.addCfgValset32(UBLOX_CFG_TMODE_LAT, majorLat);
228+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_TMODE_LAT_HP, minorLat);
229+
response &= i2cGNSS.addCfgValset32(UBLOX_CFG_TMODE_LON, majorLong);
230+
response &= i2cGNSS.addCfgValset8(UBLOX_CFG_TMODE_LON_HP, minorLong);
231+
response &= i2cGNSS.addCfgValset32(UBLOX_CFG_TMODE_HEIGHT, majorAlt);
232+
response &= i2cGNSS.sendCfgValset8(UBLOX_CFG_TMODE_HEIGHT_HP, minorAlt);
222233
}
223234

224235
return (response);
@@ -250,7 +261,7 @@ void SFE_UBLOX_GNSS::processRTCM(uint8_t incoming)
250261
{
251262
rtcmLastReceived = millis();
252263
rtcmBytesSent++;
253-
264+
254265
ntripServerProcessRTCM(incoming);
255266

256267
espnowProcessRTCM(incoming);

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ void beginUART2()
336336
//Allows more time between when the UART interrupt occurs and when the FIFO buffer overruns
337337
//serialGNSS.setRxFIFOFull(50); //Available in >v2.0.5
338338
uart_set_rx_full_threshold(2, 50); //uart_num, threshold
339-
339+
340340
// if (pinUART2TaskHandle == NULL) xTaskCreatePinnedToCore(
341341
// pinUART2Task,
342342
// "UARTStart", //Just for humans
@@ -367,65 +367,6 @@ void pinUART2Task( void *pvParameters )
367367
vTaskDelete( NULL ); //Delete task once it has run once
368368
}
369369

370-
//Serial Read/Write tasks for the F9P must be started after BT is up and running otherwise SerialBT->available will cause reboot
371-
void startUART2Tasks()
372-
{
373-
//Reads data from ZED and stores data into circular buffer
374-
if (F9PSerialReadTaskHandle == NULL)
375-
xTaskCreate(
376-
F9PSerialReadTask, //Function to call
377-
"F9Read", //Just for humans
378-
readTaskStackSize, //Stack Size
379-
NULL, //Task input parameter
380-
F9PSerialReadTaskPriority, //Priority
381-
&F9PSerialReadTaskHandle); //Task handle
382-
383-
//Reads data from circular buffer and sends data to SD, SPP, or TCP
384-
if (handleGNSSDataTaskHandle == NULL)
385-
xTaskCreate(
386-
handleGNSSDataTask, //Function to call
387-
"handleGNSSData", //Just for humans
388-
handleGNSSDataTaskStackSize, //Stack Size
389-
NULL, //Task input parameter
390-
handleGNSSDataTaskPriority, //Priority
391-
&handleGNSSDataTaskHandle); //Task handle
392-
393-
//Reads data from BT and sends to ZED
394-
if (F9PSerialWriteTaskHandle == NULL)
395-
xTaskCreate(
396-
F9PSerialWriteTask, //Function to call
397-
"F9Write", //Just for humans
398-
writeTaskStackSize, //Stack Size
399-
NULL, //Task input parameter
400-
F9PSerialWriteTaskPriority, //Priority
401-
&F9PSerialWriteTaskHandle); //Task handle
402-
}
403-
404-
//Stop tasks - useful when running firmware update or WiFi AP is running
405-
void stopUART2Tasks()
406-
{
407-
//Delete tasks if running
408-
if (F9PSerialReadTaskHandle != NULL)
409-
{
410-
vTaskDelete(F9PSerialReadTaskHandle);
411-
F9PSerialReadTaskHandle = NULL;
412-
}
413-
if (handleGNSSDataTaskHandle != NULL)
414-
{
415-
vTaskDelete(handleGNSSDataTaskHandle);
416-
handleGNSSDataTaskHandle = NULL;
417-
}
418-
if (F9PSerialWriteTaskHandle != NULL)
419-
{
420-
vTaskDelete(F9PSerialWriteTaskHandle);
421-
F9PSerialWriteTaskHandle = NULL;
422-
}
423-
424-
//Give the other CPU time to finish
425-
//Eliminates CPU bus hang condition
426-
delay(100);
427-
}
428-
429370
void beginFS()
430371
{
431372
if (online.fs == false)
@@ -712,6 +653,9 @@ bool beginExternalTriggers()
712653
return (true);
713654
}
714655

656+
if (settings.dataPortChannel != MUX_PPS_EVENTTRIGGER)
657+
return(true); //No need to configure PPS if port is not selected
658+
715659
UBX_CFG_TP5_data_t timePulseParameters;
716660

717661
if (i2cGNSS.getTimePulseParameters(&timePulseParameters) == false)

0 commit comments

Comments
 (0)