Context
Path Manager is a state machine in ZeroPilot that determines how we get our plane from point A to B. Over the past few months, Path Manager’s complexity has increased grealty with the introduction of landing and takeoff states. In the future, it will only get more complex. To make Path Manager more modular and expandable, it will need to be redesigned. This document contains one such proposal, which will introduce sub-state machines (dubbed Modes) with their own states (dubbed Stages).
...
An abstraction layer that Path Manager interacts with directly. It ensures that Path Manager never knows what Mode mode of flight we are in.
In the code, this class is PathModeSelector
.
ModeSelector (Singleton) |
- current_mode : ModeModeParent* - current_mode_enum : ModeEnum - telemetryis_data : Telemetry_PIGO_t - sensor_fusion_output : SFOutput_t - private member variables for all required raw sensor data error : bool - static singleton : PathModeSelector* // The following are all output data - altitude_airspeed_input : AltitudeAirspeedInput_t - altitude_airspeed_input : AltitudeAirspeedInput_t - Individual member variables that will need to be used/sent down by telemetry |
- ModeSelector() + static getInstance() → ModeSelector* + execute(Telemetry_PIGO_t, SFOutput_t, …) → void // Input data sent in via parameters + getCurrentMode() → ModeModeParent* + getCurrentModeEnum() → ModeEnum + setModesetCurrentMode(ModeModeParent&) → void + setCurrentModeEnum(ModeEnum) → Void + getters and setters for all output data |
Mode
Is akin to the pathManager
class in ZeroPilot. One of these classes will exist for each mode of flight: Crusing, Landing, Takeoff, Taxiing, etc.
Examples in the code of this class include CruisingMode
and LandingMode
.
Mode (Singleton) |
- current_stage : ModeStage* - stage_status : STAGE_ENUM - mode_selector : ModeSelector* - current_status : PathMan::_Path_Manager_Cycle_Status |
- Mode() + getCurrentStagestatic getInstance() → ModeStage*ModeParent + execute() → void + getCurrentStage() → ModeStage* + setStagesetCurrentStage(ModeStage&) → void + getStageStatusgetCurrentStageEnum() → STAGE_ENUM + setCurrentStageEnum(STAGE_ENUM) → void + getSelectorgetModeSelector() → ModeSelector& + Gettes and setters to access data in ModeSelector and ModeParent |
* STAGE_ENUM is a substitute for TakeoffStages, LandingStages, etc.
WAIT! POLYMORPHISM
With many different Mode
Classes , we need some way of storing them all within the same pointer current_mode
in the ModeSelector
class. To accomplish this, we will declare an abstract base class, ModeParent
(or PathMode
in the code) which will be the parent to all Mode
classes.
ModeParent |
# current_status : PathMan::_Path_Manager_Cycle_Status # telemetry_data : Telemetry_PIGO_t # sf_data : SFOutput_t # imu_data : IMU_Data_t + bool operator==(const ModeParent&) |
+ execute(Telemetry_PIGO_t, SFOutput_t, IMU_Data_t) = 0 → void + getTelemetryData() → Telemetry_PIGO_t + getSensorFusionData() → SFOutput_t + getImuData() → IMU_Data_t |
ModeStage
Is akin to the pathManagerState
class in ZeroPilot. Each of these classes will represent a stage in a mode of flight (ex. landingFlareStage
in landing or takeoffClimbStage
in takeoff). This will be an abstract base class (ABC).
An example of this class in the code is LandingModeStageManager
and CruisingModeStageManager
.
ModeStage (ABC) |
+ operator ==(const ModeStage&) const → bool |
+ enter(Mode*) = 0 → void + execute(Mode*) = 0 → void + exit(Mode*) = 0 → void + ~ModeStage() → void |
...
Each individual stage class is like the state classes (ex. crusingState
commsWithTelemetry
) in Path Manager.
Examples of this class include CruisingFlight
and LandingTransitionStage
.
Stage (Singleton) |
- Stage(const Stage&) - Stage& operator =(const Stage&) - any additional parameters |
- Stage() + enter(Mode*) → void + execute(Mode*) → void + exit(Mode*) → void + static getInstance() → Stage& + getters for private data |
Flow of Code
Here is the flow of code when Path Manager’s ModeExecuter
state calls ModeSelector::execute(params)
:
...