Challenge

Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear

Project - 2 (Finite State Machine)

Embedded C Essential Course

Problem Statement

Implement the Code for controlling the retraction and extension of Airplane's landing gear

Description of the Hardware

Actually an airplane has 3 gears for landing :

  1. Nose Gear
  2. Left Gear
  3. Right Gear

There is a hydraulic pump which is exerting pressure to the gears to bring it down or pull it up and that pump is electrically driven.

Limit switches

Every leg of the gear has one limit switch. Nose gear has one extra Squat Switch to determine whether the airplane is in ground or not.

Switch State

Limit Switch CLOSED

Limit Switch OPENED

State of Gears

Gear is UP

Gear is DOWN

Switch State

Squat Switch CLOSED

Squat Switch OPENED

State of Airplane

Airplane is grounded and Gears are locked

Airplane is taking off/landing/airborne

A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear

Status of Direction Valve

Direction valve = : Down

Direction valve = Up

Control of hydraulic pump for the landing gear part is disabled

Direction valve = down

States of landing gear

(Gear Down) (Parked at bay or Landed)

Raising Gear(Taking Off)

Gear Up(Airborne)

Lowering Gear (Landing)

Input for the Direction Valve

Pilot's Lever State

Lever UP

Lever Down

Direction Valve State

Direction valve = Up

Direction valve = Down

Pilot's Lever State

Lever Rising Edge

Lever Falling Edge

Light Status

Red

Every gear has one light. According to the state of the gear,color of light is changing

Landing Gear State

Gear is up

Gear is down

Gear in transit(Raising or Lowering)

Light Status

OFF

Green

Red

Consider this cases:

  1. There is a possibility that the plane is about to take off and an emergency comes where pilot has to abort the take off
  2. When taking off,to ensure that its right time to raising the gear,check for at least 4 seconds that squat switch is open
  3. When the airplane is parked at the bay and nose gear is down,then the nose gear is always experiencing a pressure on it due to airplane weight,weight of luggage and weight of passengers boarding on the airplane.Hydraulic mechanism is monitoring the pressure exerted on the nose gear and to neutralize that pressure its applying a pressure on the opposite direction
  4. Hydraulic Control can detect the rising edge and falling
  5. edge of pilot’s lever
  6. In case of Hydraulic system failure,there are two gas pressurized springs by which gears can be extended
  7. The case of failure of Squat Switch is ignored

Overview of the Project: (5 to 6 lines)

In this project, controlling the retraction and extension of Airplane’s landing gear can be implemented using Finite State Machine (FSM). FSM is the most efficient algorithm which is mathematical model of computation.

Goals ( 2 to 3 points)

Controlling the direction of Valve.

Controlling the retraction and extension of Airplane’s landing gear.

Key Highlights of the Project: (4 to 5 points)

A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.

Deliverables of this project: (4 to 5 points)

Implementing the control for the retraction and extension of Airplane’s landing gear using the Finite state machine with the knowledge of various states of switch and gear.

Expected Outcomes: (4 to 5 points)

The student will be getting the Knowledge of Finite State Machine algorithm which is used to achieve the control over the retraction and extension of Airplane’s landing gear using the switch and gear states of Airplane.

Let's go through the program step by step to understand how it controls the landing gear based on the given problem statement.

  1. We start by including the necessary header files and defining the enumerations for the landing gear states, direction valve states, pilot's lever states, and gear light colors.
  1. The “raiseGear()”function is defined to simulate the process of raising the landing gear. In a real implementation, you would add the necessary code to control the hydraulic pump and wait for the gear to be fully raised.
  1. Similarly, the “lowerGear()”function simulates the process of lowering the landing gear. You would add the appropriate code to control the hydraulic pump and wait for the gear to be fully lowered in a real implementation.
  1. The “controlLandingGear()”function is where the main logic for controlling the landing gear resides. It takes the lever state, valve state, and squat switch state as input and determines the appropriate action based on the current gear state.
  1. Inside the “controlLandingGear()”function, we have a static variable “gearState” to keep track of the current state of the landing gear, and another static variable “gearLightColor” to keep track of the color of the gear light.
  1. The function uses a switch statement to handle different gear states “(GEAR_UP, GEAR_DOWN, GEAR_TRANSIT)”and performs the corresponding actions based on the input states.
  1. When the gear is in the GEAR_UP state, the function checks if the lever is in the down position (LEVER_DOWN). If the squat switch is closed “(squatSwitchClosed == 1)”, it prints a message that lowering the gear is not possible. Otherwise, it calls the “lowerGear()”function, sets the gear state to GEAR_TRANSIT, and changes the gear light color to red (LIGHT_RED).
  1. When the gear is in the GEAR_DOWN state, the function checks if the lever is in the up position (LEVER_UP). If so, it calls the “raiseGear()”function, sets the gear state to GEAR_TRANSIT, and changes the gear light color to red (LIGHT_RED).
  1. When the gear is in the GEAR_TRANSIT state, the function checks the valve state and squat switch state to determine the next gear state and gear light color. If the valve is up (VALVE_UP) and the squat switch is open “(squatSwitchClosed == 0)”, the gear state is set to GEAR_UP, and the gear light color is changed to green (LIGHT_GREEN). If the valve is down (VALVE_DOWN) and the squat switch is closed “(squatSwitchClosed == 1)”, the gear state is set to GEAR_DOWN, and the gear light color is changed to green (LIGHT_GREEN).
  1. After determining the gear state and gear light color, the function prints the current gear state and light status.
  1. The main() function demonstrates the usage of the “controlLandingGear()”function by simulating the take-off and landing scenarios.
  1. In the take-off scenario, the function calls “controlLandingGear()”with different lever states (LEVER_DOWN and LEVER_UP), valve states (VALVE_DOWN and VALVE_UP), and squat switch states (1 and 0) to simulate the sequence of actions. The function prints the gear state and light status after each call.
  1. Similarly, in the landing scenario, the function calls “controlLandingGear()”with different input states to simulate the sequence of actions during landing.

AIM:

To write a C program using Finite State Machine(FSM) for controlling the retraction and extension of Airplane's landing gear.

C Code:


#include

// Enumeration for the states of the landing gear
typedef enum {
GEAR_UP,
GEAR_DOWN,
GEAR_TRANSIT
} LandingGearState;

// Enumeration for the states of the direction valve
typedef enum {
VALVE_UP,
VALVE_DOWN
} DirectionValveState;

// Enumeration for the states of the pilot's lever
typedef enum {
LEVER_UP,
LEVER_DOWN
} PilotLeverState;

// Enumeration for the colors of the gear lights
typedef enum {
LIGHT_OFF,
LIGHT_GREEN,
LIGHT_RED
} GearLightColor;

// Function to simulate raising the landing gear
void raiseGear() {
printf("Raising landing gear...n");
// Simulate the time taken to raise the gear
// You can add delays or time calculations here
printf("Gear raised.n");
}

// Function to simulate lowering the landing gear
void lowerGear() {
printf("Lowering landing gear...n");
// Simulate the time taken to lower the gear
// You can add delays or time calculations here
printf("Gear lowered.n");
}

// Function to simulate the landing gear control
void controlLandingGear(PilotLeverState leverState, DirectionValveState valveState, int squatSwitchClosed) {
static LandingGearState gearState = GEAR_UP;
static GearLightColor gearLightColor = LIGHT_OFF;

switch (gearState) {
case GEAR_UP:
if (leverState == LEVER_DOWN) {
if (squatSwitchClosed) {
printf("Cannot lower gear while the squat switch is closed.n");
} else {
lowerGear();
gearState = GEAR_TRANSIT;
gearLightColor = LIGHT_RED;
}
}
break;

case GEAR_DOWN:
if (leverState == LEVER_UP) {
raiseGear();
gearState = GEAR_TRANSIT;
gearLightColor = LIGHT_RED;
}
break;

case GEAR_TRANSIT:
if (valveState == VALVE_UP && !squatSwitchClosed) {
gearState = GEAR_UP;
gearLightColor = LIGHT_GREEN;
} else if (valveState == VALVE_DOWN && squatSwitchClosed) {
gearState = GEAR_DOWN;
gearLightColor = LIGHT_GREEN;
}
break;
}

// Print the current gear state and light status
printf("Landing Gear State: ");
switch (gearState) {
case GEAR_UP:
printf("Gear is upn");
break;
case GEAR_DOWN:
printf("Gear is downn");
break;
case GEAR_TRANSIT:
printf("Gear in transitn");
break;
}

printf("Light Status: ");
switch (gearLightColor) {
case LIGHT_OFF:
printf("OFFn");
break;
case LIGHT_GREEN:
printf("Greenn");
break;
case LIGHT_RED:
printf("Redn");
break;
}
printf("n");
}

int main() {
// Simulating the take-off scenario
printf("Take-off Scenario:n");
printf("-----------------n");
controlLandingGear(LEVER_DOWN, VALVE_DOWN, 1); // Gear is down, squat switch closed
controlLandingGear(LEVER_DOWN, VALVE_UP, 1); // Gear is up, squat switch closed
controlLandingGear(LEVER_DOWN, VALVE_UP, 0); // Gear in transit, squat switch open
controlLandingGear(LEVER_UP, VALVE_UP, 0); // Gear is up, squat switch open
printf("n");

// Simulating the landing scenario
printf("Landing Scenario:n");
printf("-----------------n");
controlLandingGear(LEVER_UP, VALVE_UP, 0); // Gear is up, squat switch open
controlLandingGear(LEVER_DOWN, VALVE_UP, 0); // Gear in transit, squat switch open
controlLandingGear(LEVER_DOWN, VALVE_DOWN, 0); // Gear is down, squat switch open
controlLandingGear(LEVER_DOWN, VALVE_DOWN, 1); // Gear is down, squat switch closed
printf("n");

return 0;
}

OUTPUT CONSOLE:

Take-off Scenario:

-----------------

Cannot lower gear while the squat switch is closed.

Landing Gear State: Gear is up

Light Status: OFF

Cannot lower gear while the squat switch is closed.

Landing Gear State: Gear is up

Light Status: OFF

Lowering landing gear...

Gear lowered.

Landing Gear State: Gear in transit

Light Status: Red

Landing Gear State: Gear is up

Light Status: Green

Landing Scenario:

-----------------

Landing Gear State: Gear is up

Light Status: Green

Lowering landing gear...

Gear lowered.

Landing Gear State: Gear in transit

Light Status: Red

Landing Gear State: Gear in transit

Light Status: Red

Landing Gear State: Gear is down

Light Status: Green

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.