Skip to content

Commit 0841266

Browse files
authored
Merge pull request #731 from sparkfun/AddFlexTilt
Add support for tilt sensor
2 parents d2ecd5e + 077ac0c commit 0841266

File tree

7 files changed

+87
-32
lines changed

7 files changed

+87
-32
lines changed

Firmware/RTK_Everywhere/Begin.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ void beginBoard()
713713
present.brand = BRAND_SPARKPNT;
714714
present.psram_2mb = true;
715715
present.gnss_lg290p = true;
716-
present.antennaPhaseCenter_mm = 42.0; // Default to SPK6618H APC, average of L1/L2
716+
present.antennaPhaseCenter_mm = 37.5; // APC of SPK-6E helical L1/L2/L5 antenna
717717
present.needsExternalPpl = true; // Uses the PointPerfect Library
718718
present.gnss_to_uart = true;
719719

@@ -775,7 +775,7 @@ void beginBoard()
775775
present.brand = BRAND_SPARKPNT;
776776
present.psram_2mb = true;
777777

778-
present.antennaPhaseCenter_mm = 42.0; // Default to SPK6618H APC, average of L1/L2
778+
present.antennaPhaseCenter_mm = 62.0; // APC from drawings
779779
present.radio_lora = true;
780780
present.fuelgauge_bq40z50 = true;
781781
present.charger_mp2762a = true;
@@ -786,7 +786,7 @@ void beginBoard()
786786
present.gnss_to_uart = true;
787787

788788
present.gpioExpanderSwitches = true;
789-
present.microSd = true;
789+
// present.microSd = true; // TODO remove comment out - v1.0 hardware does not have pullup on #CD so card detection does not work
790790
present.microSdCardDetectLow = true;
791791

792792
present.display_i2c0 = true;

Firmware/RTK_Everywhere/GNSS_LG290P.ino

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,31 @@ bool GNSS_LG290P::configureRover()
365365

366366
response &= setMinCnoRadio(settings.minCNO);
367367

368+
//If we are on a platform that supports tilt
369+
if (present.tiltPossible == true)
370+
{
371+
//And tilt is present and enabled
372+
if (present.imu_im19 == true && settings.enableTiltCompensation == true)
373+
{
374+
//Configure GNSS to support the tilt sensor
375+
376+
// Tilt sensor requires 5Hz at a minimum
377+
if (settings.measurementRateMs > 200)
378+
{
379+
systemPrintln("Increasing GNSS measurement rate to 5Hz for tilt support");
380+
settings.measurementRateMs = 200;
381+
}
382+
383+
// On the LG290P Flex module, UART 3 of the GNSS is connected to the IMU UART 1
384+
response &= setBaudRate(3, 115200);
385+
386+
if (response == false && settings.debugGnss)
387+
systemPrintln("configureRover: setBaud failed.");
388+
389+
// Enable of GGA, RMC, GST for tilt sensor is done in enableNMEA()
390+
}
391+
}
392+
368393
// Set the fix rate. Default on LG290P is 10Hz so set accordingly.
369394
response &= setRate(settings.measurementRateMs / 1000.0); // May require save/reset
370395
if (settings.debugGnss && response == false)
@@ -649,7 +674,6 @@ bool GNSS_LG290P::enableNMEA()
649674
{
650675
bool response = true;
651676
bool gpggaEnabled = false;
652-
bool gpzdaEnabled = false;
653677

654678
int portNumber = 1;
655679

@@ -686,10 +710,6 @@ bool GNSS_LG290P::enableNMEA()
686710
{
687711
if (strcmp(lgMessagesNMEA[messageNumber].msgTextName, "GGA") == 0)
688712
gpggaEnabled = true;
689-
690-
// ZDA not supported on LG290P
691-
// if (strcmp(lgMessagesNMEA[messageNumber].msgTextName, "ZDA") == 0)
692-
// gpzdaEnabled = true;
693713
}
694714
}
695715
}
@@ -708,24 +728,47 @@ bool GNSS_LG290P::enableNMEA()
708728
// If firmware is 4 or higher, use setMessageRateOnPort, otherwise setMessageRate
709729
if (lg290pFirmwareVersion >= 4)
710730
{
711-
// Enable GGA / ZDA on port 2 (ESP32) only
731+
// Enable GGA on UART 2 (connected to ESP32) only
712732
if (gpggaEnabled == false)
713733
response &= _lg290p->setMessageRateOnPort("GGA", 1, 2);
714-
715-
// if (gpggaEnabled == false)
716-
// response &= _lg290p->setMessageRateOnPort("GGA", 1, 1);
717734
}
718735
else
719736
{
720-
// Enable GGA / ZDA on all ports. It's the best we can do.
737+
// Enable GGA on all UARTs. It's the best we can do.
721738
if (gpggaEnabled == false)
722739
response &= _lg290p->setMessageRate("GGA", 1);
723-
724-
// if (gpzdaEnabled == false)
725-
// response &= _lg290p->setMessageRate("ZDA", 1);
726740
}
727741
}
728742

743+
// If this is Flex, we may need to enable NMEA for Tilt IMU
744+
if (present.tiltPossible == true)
745+
{
746+
if (present.imu_im19 == true && settings.enableTiltCompensation == true)
747+
{
748+
// Regardless of user settings, enable GGA, RMC, GST on UART3
749+
// If firmware is 4 or higher, use setMessageRateOnPort, otherwise setMessageRate
750+
if (lg290pFirmwareVersion >= 4)
751+
{
752+
// Enable GGA/RMS/GST on UART 3 (connected to the IMU) only
753+
response &= _lg290p->setMessageRateOnPort("GGA", 1, 3);
754+
response &= _lg290p->setMessageRateOnPort("RMC", 1, 3);
755+
response &= _lg290p->setMessageRateOnPort("GST", 1, 3);
756+
}
757+
else
758+
{
759+
// GST not supported below 4
760+
systemPrintf(
761+
"Current LG290P firmware: v%d (full form: %s). Tilt compensation requires GST on firmware v4 "
762+
"or newer. Please "
763+
"update the "
764+
"firmware on your LG290P to allow for these features. Please see "
765+
"https://bit.ly/sfe-rtk-lg290p-update\r\n Marking tilt compensation offline.",
766+
lg290pFirmwareVersion, gnssFirmwareVersion);
767+
768+
present.imu_im19 = false;
769+
}
770+
}
771+
}
729772
return (response);
730773
}
731774

Firmware/RTK_Everywhere/SD.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bool sdCardPresent(void)
117117
}
118118
else
119119
{
120-
//reportFatalError("sdCardPresent: gpioExpander not online.");
120+
// reportFatalError("sdCardPresent: gpioExpander not online.");
121121
return (false);
122122
}
123123
}
@@ -168,7 +168,7 @@ bool sdCardPresent(void)
168168
}
169169

170170
xSemaphoreGive(sdCardSemaphore);
171-
171+
172172
if (response != 1)
173173
{
174174
previousCardPresentBySW = false;

Firmware/RTK_Everywhere/States.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void stateUpdate()
115115
webServerStop(); // Stop the web config server
116116
baseCasterDisableOverride(); // Disable casting overrides
117117

118-
// Start the UART connected to the GNSS receiver for NMEA and UBX data (enables logging)
118+
// Start the UART connected to the GNSS receiver for NMEA data (enables logging)
119119
if (tasksStartGnssUart() == false)
120120
displayRoverFail(1000);
121121
else
@@ -228,7 +228,7 @@ void stateUpdate()
228228

229229
webServerStop(); // Stop the web config server
230230

231-
// Start the UART connected to the GNSS receiver for NMEA and UBX data (enables logging)
231+
// Start the UART connected to the GNSS receiver for NMEA data (enables logging)
232232
if (tasksStartGnssUart() && gnss->configureBase())
233233
{
234234
// settings.gnssConfiguredBase is set by gnss->configureBase()
@@ -575,7 +575,7 @@ void stateUpdate()
575575

576576
displayNtpStart(500); // Show 'NTP'
577577

578-
// Start UART connected to the GNSS receiver for NMEA and UBX data (enables logging)
578+
// Start UART connected to the GNSS receiver for NMEA data (enables logging)
579579
if (tasksStartGnssUart() && ntpConfigureUbloxModule())
580580
{
581581
settings.lastState = STATE_NTPSERVER_NOT_STARTED; // Record this state for next POR

Firmware/RTK_Everywhere/System.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void settingsToDefaults()
402402
static const Settings defaultSettings;
403403
settings = defaultSettings;
404404

405-
checkArrayDefaults(); // This does not call recordSystemSettings
405+
checkArrayDefaults(); // This does not call recordSystemSettings
406406
checkGNSSArrayDefaults(); // This calls recordSystemSettings if any GNSS defaults are applied
407407
}
408408

Firmware/RTK_Everywhere/Tilt.ino

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ void tiltUpdate()
6060
}
6161

6262
if (tiltState != TILT_STARTED) // If we failed to begin, disable future attempts
63+
{
6364
tiltFailedBegin = true;
65+
tiltState = TILT_DISABLED;
66+
}
6467
break;
6568

6669
case TILT_STARTED:
@@ -260,8 +263,8 @@ void printTiltDebug()
260263
// Start communication with the IM19 IMU
261264
void beginTilt()
262265
{
263-
tiltSensor = new IM19();
264266

267+
tiltSensor = new IM19();
265268
if (SerialForTilt == nullptr)
266269
SerialForTilt = new HardwareSerial(1); // Use UART1 on the ESP32 to receive IMU corrections
267270

@@ -292,8 +295,15 @@ void beginTilt()
292295
result &= tiltSensor->sendCommand("NAVI_OUTPUT=UART1,ON");
293296

294297
// Set the distance of the IMU from the center line - x:6.78mm y:10.73mm z:19.25mm
295-
if (present.imu_im19 == true)
298+
if (productVariant == RTK_TORCH)
296299
result &= tiltSensor->sendCommand("LEVER_ARM=-0.00678,-0.01073,-0.0314"); // From stock firmware
300+
else if (productVariant == RTK_FLEX)
301+
{
302+
result &= tiltSensor->sendCommand("LEVER_ARM=0.03391,0.00272,0.02370"); // -28.2, 0. -23.7mm
303+
304+
//Send AT+INSTALL_ANGLE=180,0,0 if the IM19 module is mounted on the back of the GNSS receiver (so the IM19 faces downward instead of upward), before sending the save command.
305+
result &= tiltSensor->sendCommand("INSTALL_ANGLE=180,0,-90"); //IMU is mounted facing down
306+
}
297307

298308
// Set the overall length of the GNSS setup in meters: rod length 1800mm + internal length 96.45mm + antenna
299309
// POC 19.25mm = 1915.7mm
@@ -309,7 +319,10 @@ void beginTilt()
309319
result &= tiltSensor->sendCommand(clubVector);
310320

311321
// Configure interface type. This allows IM19 to receive Unicore-style binary messages
312-
result &= tiltSensor->sendCommand("GNSS_CARD=UNICORE");
322+
if (productVariant == RTK_TORCH)
323+
result &= tiltSensor->sendCommand("GNSS_CARD=UNICORE");
324+
else if (productVariant == RTK_FLEX)
325+
result &= tiltSensor->sendCommand("GNSS_CARD=OEM");
313326

314327
// Configure as tilt measurement mode
315328
result &= tiltSensor->sendCommand("WORK_MODE=408"); // From stock firmware
@@ -324,7 +337,7 @@ void beginTilt()
324337
// Unknown new command for v2
325338
result &= tiltSensor->sendCommand("CORRECT_HOLDER=ENABLE"); // From stock firmware
326339

327-
// Trigger IMU on PPS from UM980
340+
// Trigger IMU on PPS from GNSS
328341
result &= tiltSensor->sendCommand("SET_PPS_EDGE=RISING");
329342

330343
// Enable magnetic field mode
@@ -1017,7 +1030,7 @@ void tiltDetect()
10171030
if (present.tiltPossible == false)
10181031
return;
10191032

1020-
// Start test if not previously detected
1033+
// Skip test if previously detected as present
10211034
if (settings.detectedTilt == true)
10221035
{
10231036
present.imu_im19 = true; // Allow tiltUpdate() to run
@@ -1053,6 +1066,7 @@ void tiltDetect()
10531066
{
10541067
present.imu_im19 = true; // Allow tiltUpdate() to run
10551068
settings.detectedTilt = true;
1069+
settings.gnssConfiguredRover = false; // Update rover settings
10561070
break;
10571071
}
10581072
}
@@ -1061,10 +1075,8 @@ void tiltDetect()
10611075

10621076
#endif // COMPILE_IM19_IMU
10631077

1064-
if (settings.enableImuDebug == true)
1065-
systemPrintf("Tilt sensor %sdetected\r\n", settings.detectedTilt ? "" : "not ");
1066-
1067-
settings.testedTilt = true;
1078+
systemPrintf("Tilt sensor %sdetected\r\n", settings.detectedTilt ? "" : "not ");
1079+
settings.testedTilt = true; //Record this test so we don't do it again
10681080
recordSystemSettings();
10691081
return;
10701082
}

Firmware/RTK_Everywhere/menuSystem.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ void menuInstrument()
14291429
systemPrintf("1) Set Antenna Height (a.k.a. Pole Length): %0.3lfm\r\n",
14301430
settings.antennaHeight_mm / (double)1000.0);
14311431

1432-
systemPrintf("2) Set Antenna Phase Center (a.k.a. ARP): %0.1fmm\r\n", settings.antennaPhaseCenter_mm);
1432+
systemPrintf("2) Set Antenna Phase Center: %0.1fmm\r\n", settings.antennaPhaseCenter_mm);
14331433

14341434
systemPrint("3) Report Tip Altitude: ");
14351435
systemPrintf("%s\r\n", settings.outputTipAltitude ? "Enabled" : "Disabled");

0 commit comments

Comments
 (0)