ZED Manager Finite State Machine¶
This document describes the finite state machine (FSM) that manages the ZED GNSS module operation in the RTK Base firmware.
Overview¶
The ZED Manager (zed_f9p_manager) implements a state machine that controls the ZED-F9P or ZED-F20 GNSS module from initialization through to operational RTK fixed mode.
State Diagram¶
stateDiagram-v2
[*] --> ZED_INITIALIZATION
ZED_INITIALIZATION --> ZED_CONFIGURE : Power on / Reset complete
ZED_CONFIGURE --> ZED_TESTING : Production test not done
ZED_CONFIGURE --> ZED_GET_STARTUP_POSITION : Production test done
ZED_TESTING --> ZED_GET_STARTUP_POSITION : Production test complete
ZED_GET_STARTUP_POSITION --> ZED_WAIT_INPUT : Position valid, No stored ref position
ZED_GET_STARTUP_POSITION --> ZED_FIX_MODE : Position valid, Delta < threshold
ZED_GET_STARTUP_POSITION --> ZED_GET_STARTUP_POSITION : Timeout (15 min) → Error
ZED_WAIT_INPUT --> ZED_SURVEY : Survey button pressed
ZED_WAIT_INPUT --> ZED_WAIT_INPUT : Wait for user action
ZED_SURVEY --> ZED_GET_STARTUP_POSITION : Survey complete, Accuracy OK
ZED_SURVEY --> ZED_SURVEY : Survey timeout → Error, Can retry
ZED_FIX_MODE --> ZED_FIX_MODE : RTCM consistent
ZED_FIX_MODE --> ZED_FIX_MODE : RTCM inconsistent (30s) → Error
ZED_FIX_MODE --> ZED_SURVEY : User triggers new survey
ZED_FIX_MODE --> ZED_INITIALIZATION : ZED reset detected
note right of ZED_GET_STARTUP_POSITION
Waits 20s for RTCM corrections
Minimum 30s observation time
Max 15 min timeout
end note
note right of ZED_SURVEY
Default: 90 sec (Fast SVIN)
Max: 24 hours
Auto-restart when corrections arrive
end note
State Definitions¶
ZED_INITIALIZATION (0)¶
Description: Initial power-on or reset state.
Entry Actions: - Reset ZED module communication - Wait 2 seconds for ZED to fully boot
Exit Conditions:
- Automatic transition to ZED_CONFIGURE on first iteration
Duration: < 2 seconds
ZED_CONFIGURE (1)¶
Description: Configuration and initialization of the ZED module.
Entry Actions: - Verify UART baudrate with ZED - Load configuration valueset (ZED-F9P or ZED-F20 specific) - Configure measurement rate (1000ms default) - Fetch antenna status - Fetch unique ID
Exit Conditions:
- If production test NOT done → transition to ZED_TESTING
- If production test DONE → transition to ZED_GET_STARTUP_POSITION
Key Configurations:
- CFG_MSGOUT_UBX_NAV_SVIN_UART1: Survey-in message output
- CFG_RATE_MEAS: Measurement rate (default 1000ms)
ZED_TESTING (2)¶
Description: Production testing state for factory validation.
Entry Actions: - Run production tests (firmware version, satellite count, antenna)
Exit Conditions:
- Production test complete → transition to ZED_GET_STARTUP_POSITION
Note: This state is skipped during normal operation.
ZED_GET_STARTUP_POSITION (3)¶
Description: Determining the initial position to validate against stored reference.
Entry Actions:
- Clear ZED_ERROR_GET_STARTUP_POSITION error bit
- Start requesting RTCM corrections if reference position requires them
Exit Conditions:
- No stored reference position →
ZED_WAIT_INPUT - Position is valid (sufficient satellites, accuracy OK)
-
No reference position in NVS
-
Position matches reference →
ZED_FIX_MODE - Delta < 7m (without corrections)
-
Delta < 0.5m (with corrections + precise reference)
-
Timeout (15 minutes) → Set error bit
- Log warning
- Stay in state, set
ZED_ERROR_GET_STARTUP_POSITION
Timing Requirements: - Minimum 20 seconds wait for RTCM corrections - Minimum 30 seconds satellite observation time - Maximum 15 minutes total (900 seconds)
Accuracy Requirements:
- With corrections: accuracy < zed_survey_accuracy_corr (default 0.5m)
- Without corrections: accuracy < initial_accuracy (default 30m)
ZED_WAIT_INPUT (4)¶
Description: Waiting for user action to start survey-in.
Entry Actions: None
Exit Conditions:
- Survey button pressed → ZED_SURVEY
User Options: - Start survey-in via web UI, MQTT, or console - Set manual reference position
ZED_SURVEY (5)¶
Description: Survey-in mode for precise position determination.
Entry Actions:
- Enable SVIN message output (CFG_MSGOUT_UBX_NAV_SVIN_UART1 = 1)
- Start survey-in procedure
Exit Conditions:
- Survey complete with required accuracy →
ZED_GET_STARTUP_POSITION - Standard: accuracy < 1m for
zed_survey_min_time(default 90s) - With corrections: accuracy <
zed_survey_accuracy_corr_dynafterCORRECTED_SURVEY_IN_MIN_TIME -
System then re-evaluates position against reference in GET_STARTUP_POSITION state
-
Timeout → Set
ZED_ERROR_SURVEYerror bit - Default timeout: 90 minutes
-
Maximum timeout: 24 hours
-
Survey restart → Stay in
ZED_SURVEY - Triggered when corrections arrive after 30 seconds
- Limited to 1 automatic restart
Dynamic Accuracy:
zed_survey_accuracy_corr_dyn = (1.0/3600) * (elapsed_time)
if zed_survey_accuracy_corr_dyn > zed_survey_accuracy_corr:
zed_survey_accuracy_corr_dyn = zed_survey_accuracy_corr
Fast SVIN Mode: - Default survey time: 90 seconds - Achieved by feeding RTCM corrections during survey
ZED_FIX_MODE (6)¶
Description: Operational RTK fixed position mode.
Entry Actions:
- Configure ZED to fixed position mode using stored reference
- Reset RTCM consistency timestamp
- Clear ZED_ERROR_FIX error bit
Stay Conditions:
- RTCM stream is consistent → remain in ZED_FIX_MODE
- Reset timestamp when RTCM consistency confirmed
Error Conditions:
- RTCM inconsistent for 30 seconds → Set ZED_ERROR_FIX error bit
- ZED uptime resets (module restart detected) → ZED_INITIALIZATION
RTCM Consistency Check:
- Period: 30 seconds
- Must have received RTCM within period
- Track timestamp_last_rtcm_consistent_tick
Error Bits¶
The FSM maintains an error bitmask for fault detection:
graph TD
A[Error Bitmask] --> B[ZED_ERROR_SURVEY]
A --> C[ZED_ERROR_FIX]
A --> D[ZED_ERROR_ANTENNA]
A --> E[ZED_ERROR_GET_STARTUP_POSITION]
A --> F[ZED_ERROR_NO_RTCM]
A --> G[ZED_ERROR_PROBE]
A --> H[ZED_WARN_CORRECTING_REFPOS]
B -->|Bit 0| Survey timeout/failure
C -->|Bit 1| RTK fix lost
D -->|Bit 2| Antenna short/open
E -->|Bit 3| Startup position timeout
F -->|Bit 4| No RTCM corrections
G -->|Bit 5| ZED not responding
H -->|Bit 6| Determining real ref position
Error States¶
| Error Bit | Name | Severity | Trigger Condition | Auto-Clear |
|---|---|---|---|---|
ZED_ERROR_SURVEY |
Survey Failed | Error | Survey timeout | On survey restart |
ZED_ERROR_FIX |
Fix Lost | Error | RTCM inconsistent >30s | On RTCM restore |
ZED_ERROR_ANTENNA |
Antenna Fault | Error | Antenna status != OK | On antenna recovery |
ZED_ERROR_GET_STARTUP_POSITION |
Startup Timeout | Error | Position acquisition >15min | On next position OK |
ZED_ERROR_NO_RTCM |
No RTCM | Warning | RTCM requested but not received | On RTCM received |
ZED_ERROR_PROBE |
Probe Failed | Fatal | ZED not responding at startup | On successful probe |
ZED_WARN_CORRECTING_REFPOS |
Determining Position | Warning | Real position being calculated | When complete |
State Transition Table¶
| Current State | Event/Condition | Next State | Actions |
|---|---|---|---|
ZED_INITIALIZATION |
(automatic) | ZED_CONFIGURE |
None |
ZED_CONFIGURE |
config OK + prod test NOT done | ZED_TESTING |
Load config |
ZED_CONFIGURE |
config OK + prod test done | ZED_GET_STARTUP_POSITION |
Load config |
ZED_TESTING |
test complete | ZED_GET_STARTUP_POSITION |
None |
ZED_GET_STARTUP_POSITION |
valid pos + no ref | ZED_WAIT_INPUT |
Clear errors |
ZED_GET_STARTUP_POSITION |
delta < threshold | ZED_FIX_MODE |
Set fix mode |
ZED_GET_STARTUP_POSITION |
timeout | (stay) | Set error bit |
ZED_WAIT_INPUT |
survey triggered | ZED_SURVEY |
Start survey |
ZED_SURVEY |
survey OK | ZED_GET_STARTUP_POSITION |
Save position, re-evaluate |
ZED_SURVEY |
timeout | (stay) | Set error bit |
ZED_SURVEY |
corrections arrive | ZED_SURVEY |
Restart survey |
ZED_FIX_MODE |
RTCM OK | (stay) | Clear error |
ZED_FIX_MODE |
RTCM fail >30s | (stay) | Set error bit |
ZED_FIX_MODE |
ZED reset | ZED_INITIALIZATION |
Full restart |
Any state >= ZED_GET_STARTUP_POSITION |
survey button | ZED_SURVEY |
Start survey |
Timing Constants¶
| Constant | Value | State | Description |
|---|---|---|---|
ZED_MAIN_TASK_PERIOD_MS |
1000 ms | All | Main task loop period |
ZED_GET_STARTUP_POSE_TIMEOUT |
900 sec | ZED_GET_STARTUP_POSITION |
15 minute timeout |
ZED_GET_STARTUP_POSE_MIN_TIME |
30 sec | ZED_GET_STARTUP_POSITION |
Minimum observation |
ZED_GET_STARTUP_POSE_MIN_NAV_SAT |
4 satellites | ZED_GET_STARTUP_POSITION |
Minimum satellites |
ZED_SURVEY_MAX_TIME |
90 min (configurable) | ZED_SURVEY |
Survey timeout |
ZED_SURVEY_MIN_TIME |
90 sec (Fast SVIN) | ZED_SURVEY |
Minimum survey time |
CORRECTED_SURVEY_IN_MIN_TIME |
60 sec | ZED_SURVEY |
Min time with corrections |
ZED_RTCM_CONSISTENCY_CHECK_DELAY |
30 sec | ZED_FIX_MODE |
Check interval |
ZED_FIX_ERROR_DETECTION_DELAY |
30 sec | ZED_FIX_MODE |
Error trigger delay |
Reference Position Flags¶
The refpos structure contains flags indicating position characteristics:
| Flag | Name | Description |
|---|---|---|
REFPOS_LLA |
Lat/Lon/Alt | Position in LLA format |
REFPOS_HP |
High Precision | Position in 0.1mm precision |
REFPOS_CORR |
Corrected | Corrections used for this position |
REFPOS_REALPOS |
Real Position | Real antenna position determined |
Survey-in Flow¶
sequenceDiagram
participant User
participant ZED_Manager
participant ZED_Module
participant NVS
User->>ZED_Manager: Press Survey Button
ZED_Manager->>ZED_Manager: Check state >= GET_STARTUP_POSITION
ZED_Manager->>ZED_Module: UBX NAV-SVIN enable
ZED_Manager->>ZED_Module: Start Survey-in
loop Every Second
ZED_Module->>ZED_Manager: NAV-SVIN status
alt Survey < 90 sec
Note over ZED_Manager: Wait for min time
else Survey > 90 sec and accuracy OK
ZED_Manager->>ZED_Manager: Survey OK
ZED_Manager->>NVS: Save ref position
ZED_Manager->>ZED_Manager: Move to GET_STARTUP_POSITION
ZED_Manager->>ZED_Manager: Re-evaluate position delta
alt Delta < threshold
ZED_Manager->>ZED_Module: Set Fix Mode
else Delta > threshold
ZED_Manager->>ZED_Manager: Set ERROR or WAIT_INPUT
end
else Survey timeout
ZED_Manager->>ZED_Manager: Set ERROR_SURVEY
else Corrections arrive after 30s
ZED_Manager->>ZED_Module: Restart Survey
end
end
ZED_Manager->>User: Survey Complete
Key Functions¶
| Function | Location | Purpose |
|---|---|---|
zed_move_to_next_state() |
Line 287 | Main state transition handler |
zed_get_current_state() |
Line 272 | Get current FSM state |
zed_main_task() |
Line 847 | Main task loop with FSM |
zed_set_error_bits() |
Line 360 | Set/clear error bits |
zed_get_error_bitmask() |
Line 267 | Get current errors |
local_zed_start_survey() |
Line 678 | Initiate survey-in |
zed_survey_finished_cb() |
Line 637 | Survey completion handler |
zed_set_fix_mode() |
Line 409 | Configure fixed mode |
zed_set_normal_mode() |
Line 404 | Configure normal mode |
ask_for_rtcm_in() |
Line 816 | Request RTCM corrections |
ref_position_delta() |
Line 1172 | Calculate position delta |
Protection Rules¶
- Impatient User Protection
- Cannot jump directly to
ZED_SURVEYorZED_FIX_MODEbefore reachingZED_GET_STARTUP_POSITION -
Returns
ESP_FAILif attempted -
RTCM Resource Management
- When leaving a state that wanted RTCM, release RTCM requirement
-
Clears
ZED_ERROR_NO_RTCMerror bit -
ZED Reset Detection
- Monitors ZED uptime
- If uptime resets and state >
ZED_CONFIGURE, restart fromZED_INITIALIZATION
References¶
- Architecture - System architecture overview
- Console Commands - CLI commands for ZED
- REST API - API for state monitoring
- Source:
components/zed_f9p_manager/zed_f9p_manager.c