Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

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 expandibleexpandable, it will need to be redesigned. This document contains one such proposal, which will introduce sub-state macines machines (dubbed Modes) with their own states (dubbed Stages).

States, Modes, and Stages

Before we go forward, we must define these three words:

State - Lives in pathManager Path Manager and is a child class to pathManagerState

...

Stage - Is a specific function executed by an aircraft in a mode of flight. Stages are the states for the Modes (sub-state machines). Each mode has at least one stage.

  • For example, takeoff has two stages: rolling and climb.

  • Another example is landing, which has five stages: transition, slope, flare, decrab, and touchdown. Each mode will have at least one stage.

Intended Final Result

  1. Path Manager (that is, pathManager, pathManagerState, and their children) should not know which mode of flight we are in.

  2. Each mode needs to be an independent unit, ensuring expandibility

  3. Modes must be able to switch between each other without the help of Path Manager states.

  4. The modes must all be called via one singular execute() method call in a Path Manager state.

In the end, Path Manager will look like the following flowchart

...

The Enums

We will need to introduce a few new enums to represent different modes and stages within each mode:

Modes

Code Block
languagecpp
enum ModeEnum {MODE_TAKEOFF = 0, MODE_CRUISING, MODE_LANDING, MODE_TAXIING};

Stages

Takeoff

Code Block
enum TakeoffStages {
  TAKEOFF_ROLL = 0,
  TAKEOFF_CLIMB
};

Cruising

Code Block
enum CruisingStages {
  CRUISING = 0
};

...

Landing

Code Block
enum LandingStages {
  LANDING_TARANSITION = 0,
  LANDING_SLOPE,
  LANDING_FLARE,
  LANDING_DECRAB,
  LANDING_TOUCHDOWN
};

Taxiing

tbd…

The Classes

ModeSelector

Abstraction An abstraction layer that Path Manager interacts with directly. It ensures that Path Manager never knows what Mode of flight we are in

ModeSelector (Singleton)

- current_mode : Mode*

- current_mode_enum : ModeEnum

- telemetry_data : Telemetry_PIGO_t

- sensor_fusion_output : SFOutput_t

- private member variables for all required raw sensor data

// 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()

+ execute(Telemetry_PIGO_t, SFOutput_t, …) → void // Input data sent in via parameters

+ getCurrentMode() → Mode*

+ getCurrentModeEnum() → ModeEnum

+ setMode(Mode&) → 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.

Mode

- current_stage : ModeStage*

- stage_status : STAGE_ENUM

- mode_selector : ModeSelector*

- current_status : PathMan::_Path_Manager_Cycle_Status

+ getCurrentStage() → ModeStage*

+ execute() → void

+ setStage(ModeStage&) → void

+ getStageStatus() → STAGE_ENUM

+ getSelector() → ModeSelector&

+ Gettes and setters to access data in ModeSelector

* STAGE_ENUM is a substitute for TakeoffStages, LandingStages, etc.

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 a an abstract base class (ABC).

ModeStage (ABC)

+ operator ==(const ModeStage&) const → bool

+ enter(Mode*) = 0 → void

+ execute(Mode*) = 0 → void

+ exit(Mode*) = 0 → void

+ ~ModeStage() → void

Stage

Each individual stage class is like the state classes (ex. crusingState) in Path Manager.

Stage (Singleton)

- Stage()- 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’s Here is the flow of code when Path Manager’s ModeExecuter state calls ModeSelector::execute(params):

...