Skip to content

Commit 8eb95d5

Browse files
committed
Implement system states. Update graphics.
1 parent 12cf38b commit 8eb95d5

File tree

10 files changed

+1508
-300
lines changed

10 files changed

+1508
-300
lines changed

Firmware/RTK_Surveyor/Base.ino

Lines changed: 4 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,3 @@
1-
//Wait for survey in to complete
2-
bool updateSurveyInStatus()
3-
{
4-
//If user wants to use fixed coordinates, do so immediately
5-
if (settings.fixedBase == true)
6-
{
7-
bool response = startFixedBase();
8-
if (response == true)
9-
{
10-
baseState = BASE_TRANSMITTING;
11-
return (true);
12-
}
13-
else
14-
{
15-
return (false);
16-
}
17-
}
18-
19-
//Update the LEDs only every second or so
20-
if (millis() - lastBaseUpdate > 1000)
21-
{
22-
lastBaseUpdate = millis();
23-
24-
if (baseState == BASE_SURVEYING_IN_NOTSTARTED)
25-
{
26-
//Check for <5m horz accuracy
27-
uint32_t accuracy = i2cGNSS.getHorizontalAccuracy(250); //This call defaults to 1100ms and can cause the core to crash with WDT timeout
28-
29-
float f_accuracy = accuracy;
30-
f_accuracy = f_accuracy / 10000.0; // Convert the horizontal accuracy (mm * 10^-1) to a float
31-
32-
if (f_accuracy > 0.0 && f_accuracy < 5.0)
33-
{
34-
//Current positional accuracy is within 5m so start survey
35-
surveyIn();
36-
}
37-
else
38-
{
39-
Serial.print(F("Waiting for Horz Accuracy < 5 meters: "));
40-
Serial.print(f_accuracy, 2); // Print the accuracy with 2 decimal places
41-
Serial.println();
42-
}
43-
} //baseState = Surveying In Not started
44-
else
45-
{
46-
bool response = i2cGNSS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (req can take a long time)
47-
if (response == true)
48-
{
49-
if (i2cGNSS.getSurveyInValid() == true)
50-
{
51-
Serial.println(F("Base survey complete! RTCM now broadcasting."));
52-
baseState = BASE_TRANSMITTING;
53-
54-
digitalWrite(baseStatusLED, HIGH); //Turn on LED
55-
}
56-
else
57-
{
58-
byte SIV = i2cGNSS.getSIV();
59-
60-
Serial.print(F("Time elapsed: "));
61-
Serial.print((String)i2cGNSS.getSurveyInObservationTime());
62-
Serial.print(F(" Accuracy: "));
63-
Serial.print((String)i2cGNSS.getSurveyInMeanAccuracy());
64-
Serial.print(F(" SIV: "));
65-
Serial.print(SIV);
66-
Serial.println();
67-
68-
SerialBT.print(F("Time elapsed: "));
69-
SerialBT.print((String)i2cGNSS.getSurveyInObservationTime());
70-
SerialBT.print(F(" Accuracy: "));
71-
SerialBT.print((String)i2cGNSS.getSurveyInMeanAccuracy());
72-
SerialBT.print(F(" SIV: "));
73-
SerialBT.print(SIV);
74-
SerialBT.println();
75-
76-
//If we are greater than a meter out of our objective, blink slow
77-
if (i2cGNSS.getSurveyInMeanAccuracy() > (settings.observationPositionAccuracy + 1.0))
78-
baseState = BASE_SURVEYING_IN_SLOW;
79-
else
80-
baseState = BASE_SURVEYING_IN_FAST;
81-
82-
if (i2cGNSS.getSurveyInObservationTime() > maxSurveyInWait_s)
83-
{
84-
Serial.printf("Survey-In took more than %d minutes. Restarting survey-in process.\n", maxSurveyInWait_s / 60);
85-
86-
resetSurvey();
87-
88-
surveyIn();
89-
}
90-
}
91-
}
92-
else
93-
{
94-
Serial.println(F("SVIN request failed"));
95-
}
96-
} //baseState = Surveying In Slow or fast
97-
} //Check every second
98-
99-
//Update the Base LED accordingly
100-
if (baseState == BASE_SURVEYING_IN_NOTSTARTED || baseState == BASE_SURVEYING_IN_SLOW)
101-
{
102-
if (millis() - baseStateBlinkTime > 2000)
103-
{
104-
baseStateBlinkTime = millis();
105-
Serial.println(F("Slow blink"));
106-
107-
if (digitalRead(baseStatusLED) == LOW)
108-
digitalWrite(baseStatusLED, HIGH);
109-
else
110-
digitalWrite(baseStatusLED, LOW);
111-
}
112-
}
113-
else if (baseState == BASE_SURVEYING_IN_FAST)
114-
{
115-
if (millis() - baseStateBlinkTime > 500)
116-
{
117-
baseStateBlinkTime = millis();
118-
Serial.println(F("Fast blink"));
119-
120-
if (digitalRead(baseStatusLED) == LOW)
121-
digitalWrite(baseStatusLED, HIGH);
122-
else
123-
digitalWrite(baseStatusLED, LOW);
124-
}
125-
}
126-
}
1271

1282
//Configure specific aspects of the receiver for base mode
1293
bool configureUbloxModuleBase()
@@ -186,22 +60,23 @@ bool configureUbloxModuleBase()
18660

18761
//Start survey
18862
//The ZED-F9P is slightly different than the NEO-M8P. See the Integration manual 3.5.8 for more info.
189-
void surveyIn()
63+
bool surveyIn()
19064
{
19165
resetSurvey();
19266

19367
bool response = i2cGNSS.enableSurveyMode(settings.observationSeconds, settings.observationPositionAccuracy); //Enable Survey in, with user parameters
19468
if (response == false)
19569
{
19670
Serial.println(F("Survey start failed"));
197-
return;
71+
return(false);
19872
}
73+
19974
Serial.printf("Survey started. This will run until %d seconds have passed and less than %0.03f meter accuracy is achieved.\n",
20075
settings.observationSeconds,
20176
settings.observationPositionAccuracy
20277
);
20378

204-
baseState = BASE_SURVEYING_IN_SLOW;
79+
return(true);
20580
}
20681

20782
void resetSurvey()
Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//Regularly update subsystems. Called from main loop (aka not tasks).
22

33
//Change between Rover or Base depending on switch state
4-
void checkSetupSwitch()
4+
void checkSetupButton()
55
{
66
//Check rover switch and configure module accordingly
77
//When switch is set to '1' = BASE, pin will be shorted to ground
@@ -40,89 +40,6 @@ void checkSetupSwitch()
4040
}
4141
}
4242

43-
void updateDisplay()
44-
{
45-
//Update the display if connected
46-
if (online.display == true)
47-
{
48-
if (millis() - lastDisplayUpdate > 1000)
49-
{
50-
lastDisplayUpdate = millis();
51-
52-
oled.clear(PAGE); // Clear the display's internal buffer
53-
54-
//Current battery charge level
55-
if (battLevel < 25)
56-
oled.drawIcon(45, 0, Battery_0_Width, Battery_0_Height, Battery_0, sizeof(Battery_0), true);
57-
else if (battLevel < 50)
58-
oled.drawIcon(45, 0, Battery_1_Width, Battery_1_Height, Battery_1, sizeof(Battery_1), true);
59-
else if (battLevel < 75)
60-
oled.drawIcon(45, 0, Battery_2_Width, Battery_2_Height, Battery_2, sizeof(Battery_2), true);
61-
else //batt level > 75
62-
oled.drawIcon(45, 0, Battery_3_Width, Battery_3_Height, Battery_3, sizeof(Battery_3), true);
63-
64-
//Bluetooth Address or RSSI
65-
if (radioState == BT_CONNECTED)
66-
{
67-
oled.drawIcon(4, 0, BT_Symbol_Width, BT_Symbol_Height, BT_Symbol, sizeof(BT_Symbol), true);
68-
}
69-
else
70-
{
71-
char macAddress[5];
72-
sprintf(macAddress, "%02X%02X", unitMACAddress[4], unitMACAddress[5]);
73-
oled.setFontType(0); //Set font to smallest
74-
oled.setCursor(0, 4);
75-
oled.print(macAddress);
76-
}
77-
78-
if (digitalRead(baseSwitch) == LOW)
79-
oled.drawIcon(27, 0, Base_Width, Base_Height, Base, sizeof(Base), true); //true - blend with other pixels
80-
else
81-
oled.drawIcon(27, 3, Rover_Width, Rover_Height, Rover, sizeof(Rover), true);
82-
83-
//Horz positional accuracy
84-
oled.setFontType(1); //Set font to type 1: 8x16
85-
oled.drawIcon(0, 18, CrossHair_Width, CrossHair_Height, CrossHair, sizeof(CrossHair), true);
86-
oled.setCursor(16, 20); //x, y
87-
oled.print(":");
88-
float hpa = i2cGNSS.getHorizontalAccuracy() / 10000.0;
89-
if (hpa > 30.0)
90-
{
91-
oled.print(F(">30"));
92-
}
93-
else if (hpa > 9.9)
94-
{
95-
oled.print(hpa, 1); //Print down to decimeter
96-
}
97-
else if (hpa > 1.0)
98-
{
99-
oled.print(hpa, 2); //Print down to centimeter
100-
}
101-
else
102-
{
103-
oled.print("."); //Remove leading zero
104-
oled.printf("%03d", (int)(hpa * 1000)); //Print down to millimeter
105-
}
106-
107-
//SIV
108-
oled.drawIcon(2, 35, Antenna_Width, Antenna_Height, Antenna, sizeof(Antenna), true);
109-
oled.setCursor(16, 36); //x, y
110-
oled.print(":");
111-
112-
if (i2cGNSS.getFixType() == 0) //0 = No Fix
113-
{
114-
oled.print("0");
115-
}
116-
else
117-
{
118-
oled.print(i2cGNSS.getSIV());
119-
}
120-
121-
oled.display();
122-
}
123-
}
124-
}
125-
12643
//Create or close UBX/NMEA files as needed (startup or as user changes settings)
12744
//Push new UBX packets to log as needed
12845
void updateLogs()

0 commit comments

Comments
 (0)