Skip to content

Commit 2570b53

Browse files
author
Nathan Seidle
committed
Turning off SV sentences when output rate is above 1Hz.
1 parent 6d71ad9 commit 2570b53

File tree

4 files changed

+152
-57
lines changed

4 files changed

+152
-57
lines changed

Firmware/LEDs/LEDs.ino

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
const int batteryLevelLED_Red = 32;
3+
const int batteryLevelLED_Green = 33;
4+
5+
const int freq = 5000;
6+
const int ledRedChannel = 0;
7+
const int ledGreenChannel = 1;
8+
const int resolution = 8;
9+
10+
void setup() {
11+
ledcSetup(ledRedChannel, freq, resolution);
12+
ledcSetup(ledGreenChannel, freq, resolution);
13+
14+
ledcAttachPin(batteryLevelLED_Red, ledRedChannel);
15+
ledcAttachPin(batteryLevelLED_Green, ledGreenChannel);
16+
17+
ledcWrite(ledRedChannel, 128);
18+
ledcWrite(ledGreenChannel, 128);
19+
}
20+
21+
// the loop function runs over and over again forever
22+
void loop() {
23+
// ledcWrite(batteryLevelLED_Red, 128);
24+
//ledcWrite(batteryLevelLED_Green, 128);
25+
delay(1000); // wait for a second
26+
//ledcWrite(batteryLevelLED_Red, 128);
27+
//ledcWrite(batteryLevelLED_Green, 128);
28+
delay(1000); // wait for a second
29+
}

Firmware/RTK_Enclosed/RTK_Enclosed.ino

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
Set static position based on user input
2828
Wait for better pos accuracy before starting a survey in
2929
Can we add NTRIP reception over Wifi to the ESP32 to aid in survey in time?
30-
30+
31+
BT cast batt, RTK status, etc
3132
3233
Menu System:
3334
Test system? Connection to GPS?
@@ -38,6 +39,8 @@
3839
Allow user to enter permanent coordinates.
3940
Allow user to enable/disable detection of permanent base
4041
Set radius (5m default) for auto-detection of base
42+
Set nav rate. 4Hz is fun but may drown BT connection. 1Hz seems to be more stable.
43+
If more than 1Hz, turn off SV sentences.
4144
*/
4245

4346
#include <Wire.h> //Needed for I2C to GPS
@@ -68,19 +71,22 @@ SFE_UBLOX_GPS_ADD myGPS;
6871

6972
//This string is used to verify the firmware on the ZED-F9P. This
7073
//firmware relies on various features of the ZED and may require the latest
71-
//ublox firmware to work correctly. We check the module firmware at startup but
74+
//u-blox firmware to work correctly. We check the module firmware at startup but
7275
//don't prevent operation if firmware is mismatched.
7376
char latestZEDFirmware[] = "FWVER=HPG 1.13";
77+
78+
uint8_t gnssUpdateRate = 4; //Increasing beyond 1Hz with SV sentence on can drown the BT link
7479
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7580

7681
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7782
//Bits for the battery level LEDs
78-
#include "MAX17048.h" //Click here to get the library: http://librarymanager/All#MAX17048
79-
MAX17048 battMonitor;
83+
#include <SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library
84+
SFE_MAX1704X lipo(MAX1704X_MAX17048); // Create a MAX17048
8085

8186
// setting PWM properties
8287
const int freq = 5000;
83-
const int ledChannel = 0;
88+
const int ledRedChannel = 0;
89+
const int ledGreenChannel = 1;
8490
const int resolution = 8;
8591
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8692

@@ -109,8 +115,8 @@ const int positionAccuracyLED_10cm = 15;
109115
const int sd_cs = 25;
110116
const int zed_tx_ready = 26;
111117
const int zed_reset = 27;
112-
const int batteryLevelLED_Red = 34;
113-
const int batteryLevelLED_Green = 35;
118+
const int batteryLevelLED_Red = 32;
119+
const int batteryLevelLED_Green = 33;
114120
const int batteryLevel_alert = 36;
115121
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
116122

@@ -160,6 +166,8 @@ void setup()
160166
GPS.setRxBufferSize(SERIAL_SIZE_RX);
161167
GPS.setTimeout(1);
162168

169+
Wire.begin();
170+
163171
Serial.println("SparkFun RTK Surveyor v1.0");
164172

165173
pinMode(positionAccuracyLED_1cm, OUTPUT);
@@ -175,9 +183,17 @@ void setup()
175183
digitalWrite(baseStatusLED, LOW);
176184
digitalWrite(bluetoothStatusLED, LOW);
177185

178-
ledcSetup(ledChannel, freq, resolution);
179-
ledcAttachPin(batteryLevelLED_Red, ledChannel);
180-
ledcAttachPin(batteryLevelLED_Green, ledChannel);
186+
ledcSetup(ledRedChannel, freq, resolution);
187+
ledcSetup(ledGreenChannel, freq, resolution);
188+
189+
ledcAttachPin(batteryLevelLED_Red, ledRedChannel);
190+
ledcAttachPin(batteryLevelLED_Green, ledGreenChannel);
191+
192+
ledcWrite(ledRedChannel, 0);
193+
ledcWrite(ledGreenChannel, 0);
194+
195+
setupLiPo(); //Configure battery fuel guage monitor
196+
checkBatteryLevels(); //Display initial battery level
181197

182198
SerialBT.register_callback(btCallback);
183199
if (startBluetooth() == false)
@@ -193,24 +209,20 @@ void setup()
193209
lastBluetoothLEDBlink = millis();
194210
}
195211

196-
Wire.begin();
197-
198-
battMonitor.attatch(Wire); //Connect batt level LED stuff so we can see battery level at power-on
199-
200212
if (myGPS.begin() == false)
201213
{
202214
//Try again with power on delay
203215
delay(1000); //Wait for ZED-F9P to power up before it can respond to ACK
204216
if (myGPS.begin() == false)
205217
{
206-
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring."));
218+
Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring."));
207219
blinkError(ERROR_NO_I2C);
208220
}
209221
else
210-
Serial.println(F("Ublox GPS detected"));
222+
Serial.println(F("u-blox GPS detected"));
211223
}
212224
else
213-
Serial.println(F("Ublox GPS detected"));
225+
Serial.println(F("u-blox GPS detected"));
214226

215227
//Based on Example21_ModuleInfo
216228
if (myGPS.getModuleInfo(1100) == true) // Try to get the module info

Firmware/RTK_Enclosed/Rover.ino

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bool updateRoverStatus()
1919

2020
if (f_accuracy <= 0.02)
2121
{
22-
Serial.print(" 0.02m LED");
22+
Serial.print(" 0.01m LED");
2323
digitalWrite(positionAccuracyLED_1cm, HIGH);
2424
digitalWrite(positionAccuracyLED_10cm, HIGH);
2525
digitalWrite(positionAccuracyLED_100cm, HIGH);
@@ -105,11 +105,14 @@ bool configureUbloxModuleRover()
105105
response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, COM_PORT_USB, 0);
106106

107107
response &= setNMEASettings(); //Enable high precision NMEA and extended sentences
108-
response &= setSBAS(false); //Disable SBAS. Work around for RTK LED not working in v1.13 firmware.
108+
109+
//Is SBAS causing weird NMEA failures once we are in RTK mode?
110+
//response &= setSBAS(false); //Disable SBAS. Work around for RTK LED not working in v1.13 firmware.
111+
109112
return (response);
110113
}
111114

112-
//The Ublox library doesn't directly support NMEA configuration so let's do it manually
115+
//The u-blox library doesn't directly support NMEA configuration so let's do it manually
113116
bool setNMEASettings()
114117
{
115118
uint8_t customPayload[MAX_PAYLOAD_SIZE]; // This array holds the payload data bytes
@@ -142,7 +145,7 @@ bool setNMEASettings()
142145
return (true);
143146
}
144147

145-
//The Ublox library doesn't directly support SBAS control so let's do it manually
148+
//The u-blox library doesn't directly support SBAS control so let's do it manually
146149
bool setSBAS(bool enableSBAS)
147150
{
148151
uint8_t customPayload[MAX_PAYLOAD_SIZE]; // This array holds the payload data bytes

Firmware/RTK_Enclosed/System.ino

Lines changed: 87 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ void F9PSerialReadTask(void *e)
4848
}
4949
}
5050

51-
//Setup the Ublox module for any setup (base or rover)
51+
//Setup the u-blox module for any setup (base or rover)
5252
//In general we check if the setting is incorrect before writing it. Otherwise, the set commands have, on rare occasion, become
5353
//corrupt. The worst is when the I2C port gets turned off or the I2C address gets borked. We should only have to configure
54-
//a fresh Ublox module once and never again.
54+
//a fresh u-blox module once and never again.
5555
bool configureUbloxModule()
5656
{
5757
boolean response = true;
@@ -101,20 +101,32 @@ bool configureUbloxModule()
101101
response &= myGPS.setPortInput(COM_PORT_USB, (COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3)); //Set the USB port to everything
102102
}
103103

104-
105104
//Set output rate
106-
if (myGPS.getNavigationFrequency() != 4)
105+
if (myGPS.getNavigationFrequency() != gnssUpdateRate)
107106
{
108-
response &= myGPS.setNavigationFrequency(4); //Set output in Hz
107+
response &= myGPS.setNavigationFrequency(gnssUpdateRate); //Set output in Hz
109108
}
110109

111110
//Make sure the appropriate NMEA sentences are enabled
112111
if (getNMEASettings(UBX_NMEA_GGA, COM_PORT_UART1) != 1)
113112
response &= myGPS.enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_UART1);
114113
if (getNMEASettings(UBX_NMEA_GSA, COM_PORT_UART1) != 1)
115114
response &= myGPS.enableNMEAMessage(UBX_NMEA_GSA, COM_PORT_UART1);
116-
if (getNMEASettings(UBX_NMEA_GSV, COM_PORT_UART1) != 1)
117-
response &= myGPS.enableNMEAMessage(UBX_NMEA_GSV, COM_PORT_UART1);
115+
116+
//When receiving 15+ satellite information, the GxGSV sentences can be a large amount of data
117+
//If the update rate is >1Hz then this data can overcome the BT capabilities causing timeouts and lag
118+
if (gnssUpdateRate == 1)
119+
{
120+
if (getNMEASettings(UBX_NMEA_GSV, COM_PORT_UART1) != 1)
121+
response &= myGPS.enableNMEAMessage(UBX_NMEA_GSV, COM_PORT_UART1);
122+
}
123+
else
124+
{
125+
//Turn off satellite sentences
126+
if (getNMEASettings(UBX_NMEA_GSV, COM_PORT_UART1) != 0)
127+
response &= myGPS.disableNMEAMessage(UBX_NMEA_GSV, COM_PORT_UART1);
128+
}
129+
118130
if (getNMEASettings(UBX_NMEA_RMC, COM_PORT_UART1) != 1)
119131
response &= myGPS.enableNMEAMessage(UBX_NMEA_RMC, COM_PORT_UART1);
120132
if (getNMEASettings(UBX_NMEA_GST, COM_PORT_UART1) != 1)
@@ -467,36 +479,75 @@ void updateBattLEDs()
467479
{
468480
lastBattUpdate += 5000;
469481

470-
int battLevel = battMonitor.percent();
482+
checkBatteryLevels();
483+
}
484+
}
485+
486+
//When called, checks level of battery and updates the LED brightnesses
487+
//And outputs a serial message to USB and BT
488+
void checkBatteryLevels()
489+
{
490+
String battMsg = "";
471491

472-
Serial.print("Batt (");
473-
Serial.print(battLevel);
474-
Serial.print("%): ");
492+
int battLevel = lipo.getSOC();
475493

476-
if (battLevel < 10)
477-
{
478-
Serial.print("RED uh oh!");
479-
ledcWrite(batteryLevelLED_Red, 255);
480-
ledcWrite(batteryLevelLED_Green, 0);
481-
}
482-
else if (battLevel < 50)
483-
{
484-
Serial.print("Yellow ok");
485-
ledcWrite(batteryLevelLED_Red, 128);
486-
ledcWrite(batteryLevelLED_Green, 128);
487-
}
488-
else if (battLevel >= 50)
489-
{
490-
Serial.print("Green all good");
491-
ledcWrite(batteryLevelLED_Red, 0);
492-
ledcWrite(batteryLevelLED_Green, 255);
493-
}
494-
else
495-
{
496-
Serial.print("No batt");
497-
ledcWrite(batteryLevelLED_Red, 0);
498-
ledcWrite(batteryLevelLED_Green, 0);
499-
}
500-
Serial.println();
494+
battMsg += "Batt (";
495+
battMsg += battLevel;
496+
battMsg += "%): ";
497+
498+
battMsg += "Voltage: ";
499+
battMsg += lipo.getVoltage();
500+
battMsg += "V";
501+
502+
if (lipo.getChangeRate() > 0)
503+
battMsg += " Charging: ";
504+
else
505+
battMsg += " Discharging: ";
506+
battMsg += lipo.getChangeRate();
507+
battMsg += "%/hr ";
508+
509+
if (battLevel < 10)
510+
{
511+
battMsg += "RED uh oh!";
512+
ledcWrite(ledRedChannel, 255);
513+
ledcWrite(ledGreenChannel, 0);
501514
}
515+
else if (battLevel < 50)
516+
{
517+
battMsg += "Yellow ok";
518+
ledcWrite(ledRedChannel, 128);
519+
ledcWrite(ledGreenChannel, 128);
520+
}
521+
else if (battLevel >= 50)
522+
{
523+
battMsg += "Green all good";
524+
ledcWrite(ledRedChannel, 0);
525+
ledcWrite(ledGreenChannel, 255);
526+
}
527+
else
528+
{
529+
battMsg += "No batt";
530+
ledcWrite(ledRedChannel, 10);
531+
ledcWrite(ledGreenChannel, 0);
532+
}
533+
battMsg += "\n\r";
534+
SerialBT.print(battMsg);
535+
Serial.print(battMsg);
536+
}
537+
538+
//Configure the on board MAX17048 fuel gauge
539+
void setupLiPo()
540+
{
541+
// Set up the MAX17048 LiPo fuel gauge
542+
if (lipo.begin() == false)
543+
{
544+
Serial.println(F("MAX17048 not detected. Continuing."));
545+
return;
546+
}
547+
548+
//Always use hibernate mode
549+
if (lipo.getHIBRTActThr() < 0xFF) lipo.setHIBRTActThr((uint8_t)0xFF);
550+
if (lipo.getHIBRTHibThr() < 0xFF) lipo.setHIBRTHibThr((uint8_t)0xFF);
551+
552+
Serial.println(F("MAX17048 configuration complete"));
502553
}

0 commit comments

Comments
 (0)