Challenge

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

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

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.

Overview of the Project:

 In this project, a Finite State Machine is used to manage the retraction and extension of an airplane's landing gear (FSM). The most efficient algorithm is the FSM, which is a mathematical processing model.

Actually an airplane has 3 gears for landing: Nose gear, Left gear, Right gear.

There is an electrically powered hydraulic pump that applies pressure to the gears to bring it down or pull it up.

There is a limit switch on each leg of the gear. One extra squat switch is installed in the nose gear to assess whether the plane is on the ground or not.

Goals:

  • Valve's direction can be controlled.
  • Controlling the retraction and extension of the landing gear on an aeroplane.

Code 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.

#include

#include

//declaring functions for each states

void GearDown();

void CheckingBeforeTakeOFF();

void RisingGear();

void GearUp();

void CheckBeforeLanding();

void LoweringGear();

//creating an array of 6 states in order call the function upon requirement

static void(*statetable[])(void)={GearDown, CheckingBeforeTakeOFF, RisingGear, GearUp, CheckBeforeLanding, LoweringGear};

//gear states

typedef enum State

{

GEAR_DOWN,

CHECKING_BEFORE_TAKEOFF,

RISING_GEAR,

GEAR_UP,

CHECK_BEFORE_LANDING,

LOWERING_GEAR,

}State_Type;

//switch states

typedef enum Switch

{

open, closed

}Switch_status;

//pilot lever states

typedef enum pilot_lever

{

down, falling, rising, up

}pilot_lever;

//hydraulic control states

typedef enum hydraulic_mechanism

{

enabled, disabled

}hydraulic_mechanism;

static volatile Switch_status squat_switch;

static volatile Switch_status limit_switch;

static volatile pilot_lever pl;

static volatile hydraulic_mechanism hm;

State_Type current_state;

//state table elements

typedef struct

{

char* current_state_indication;

char* light;

char* direction_valve_status;

int time;

char* hydraulic_control;

char* pilot_lever_status;

}State_Table;

//creating state table

static State_Table State_Machine[6]={

{"Gear Down", "Green", "Down", 3, "Enabled", "Down"},

{"Checking Before TakeOFF", "Green", "Down", 3, "Enabled", "rising"},

{"Rising Gear", "Red", "Up", 3, "Enabled", "Up"},

{"Gear Up", "Off", "Up", 3, "Disabled", "Up"},

{"Check Before Landing", "Red", "Down", 3, "Enabled", "falling"},

{"Lowering Gear", "Green", "Down", 3, "Enabled", "Down"}

};

int main()

{

while(1)

{

statetable[current_state](); //calling each state functions

}

}

//when airplane is grounded or parked

void GearDown(void)

{

current_state = GEAR_DOWN;

printf("Current state            : %s\n",State_Machine[current_state].current_state_indication);

printf("Pilots lever status      : %s\n",State_Machine[current_state].pilot_lever_status);

printf("Light status             : %s\n", State_Machine[current_state].light);

printf("Direction valve status   : %s\n", State_Machine[current_state].direction_valve_status);

printf("Hydraulic control status : %s\n", State_Machine[current_state].hydraulic_control);

printf("Time delay               : %d seconds\n\n", State_Machine[current_state].time);

printf("Enter the status of pilot's lever and squat switch: ");

fflush(stdout);

scanf("%d %d", &pl, &squat_switch);

if(pl == rising && squat_switch == open)

{

current_state = CHECKING_BEFORE_TAKEOFF;

printf("Current state            : %s\n",State_Machine[current_state].current_state_indication);

printf("Pilots lever status      : %s\n",State_Machine[current_state].pilot_lever_status);

printf("Light status             : %s\n", State_Machine[current_state].light);

printf("Direction valve status   : %s\n", State_Machine[current_state].direction_valve_status);

printf("Hydraulic control status : %s\n", State_Machine[current_state].hydraulic_control);

printf("Time delay               : %d seconds\n\n", State_Machine[current_state].time);

}

else

{

GearDown();

}

}

//when airplane is about to take off

void CheckingBeforeTakeOFF(void)

{

current_state = CHECKING_BEFORE_TAKEOFF;

printf("Enter the status of pilot's lever and squat switch: ");

fflush(stdout);

scanf("%d %d", &pl, &squat_switch);

if(pl == falling && squat_switch == closed)

{

GearDown();

}

else if(pl == up && squat_switch == open)

{

current_state = RISING_GEAR;

printf("Current state            : %s\n",State_Machine[current_state].current_state_indication);

printf("Pilots lever status      : %s\n",State_Machine[current_state].pilot_lever_status);

printf("Light status             : %s\n", State_Machine[current_state].light);

printf("Direction valve status   : %s\n", State_Machine[current_state].direction_valve_status);

printf("Hydraulic control status : %s\n", State_Machine[current_state].hydraulic_control);

printf("Time delay               : %d seconds\n\n", State_Machine[current_state].time);

}

}

//when airplane is taking off

void RisingGear(void)

{

current_state = RISING_GEAR;

printf("Enter the status of pilot's lever and limit switch:");

fflush(stdout);

scanf("%d %d", &pl, &limit_switch);

if(pl == falling && limit_switch == closed)

{

current_state = CHECK_BEFORE_LANDING;

printf("Current state            : %s\n",State_Machine[current_state].current_state_indication);

printf("Pilots lever status      : %s\n",State_Machine[current_state].pilot_lever_status);

printf("Light status             : %s\n", State_Machine[current_state].light);

printf("Direction valve status   : %s\n", State_Machine[current_state].direction_valve_status);

printf("Hydraulic control status : %s\n", State_Machine[current_state].hydraulic_control);

printf("Time delay               : %d seconds\n\n", State_Machine[current_state].time);

}

else if(pl == up && limit_switch == closed)

{

current_state = GEAR_UP;

printf("Current state            : %s\n",State_Machine[current_state].current_state_indication);

printf("Pilots lever status      : %s\n",State_Machine[current_state].pilot_lever_status);

printf("Light status             : %s\n", State_Machine[current_state].light);

printf("Direction valve status   : %s\n", State_Machine[current_state].direction_valve_status);

printf("Hydraulic control status : %s\n", State_Machine[current_state].hydraulic_control);

printf("Time delay               : %d seconds\n\n", State_Machine[current_state].time);

}

}

//when airplane is in airborne

void GearUp(void)

{

current_state = GEAR_UP;

printf("Enter the status of pilot's lever and hydraulic control: ");

fflush(stdout);

scanf("%d %d",&pl, &hm);

if(pl == falling && hm == enabled)

{

current_state = CHECK_BEFORE_LANDING;

printf("Current state            : %s\n",State_Machine[current_state].current_state_indication);

printf("Pilots lever status      : %s\n",State_Machine[current_state].pilot_lever_status);

printf("Light status             : %s\n", State_Machine[current_state].light);

printf("Direction valve status   : %s\n", State_Machine[current_state].direction_valve_status);

printf("Hydraulic control status : %s\n", State_Machine[current_state].hydraulic_control);

printf("Time delay               : %d seconds\n\n", State_Machine[current_state].time);

    }

else if(pl == up && hm == disabled)

{

GearUp();

}

}

//when airplane is about to land

void CheckBeforeLanding(void)

{

current_state = CHECK_BEFORE_LANDING;

printf("Enter the status of pilot's lever and hydraulic control: ");

fflush(stdout);

scanf("%d %d", &pl, &hm);

if(pl == down)

{

current_state = LOWERING_GEAR;

printf("Current state            : %s\n",State_Machine[current_state].current_state_indication);

printf("Pilots lever status      : %s\n",State_Machine[current_state].pilot_lever_status);

printf("Light status             : %s\n", State_Machine[current_state].light);

printf("Direction valve status   : %s\n", State_Machine[current_state].direction_valve_status);

printf("Hydraulic control status : %s\n", State_Machine[current_state].hydraulic_control);

printf("Time delay               : %d seconds\n\n", State_Machine[current_state].time);

}

else if(pl == falling)

{

CheckBeforeLanding();

}

}

//when airplane is landing

void LoweringGear(void)

{

current_state = LOWERING_GEAR;

printf("Enter the status of pilot's lever and limit switch:");

fflush(stdout);

scanf("%d %d", &pl, &limit_switch);

if(pl == rising)

{

current_state = CHECKING_BEFORE_TAKEOFF;

printf("Current state            : %s\n",State_Machine[current_state].current_state_indication);

printf("Pilots lever status      : %s\n",State_Machine[current_state].pilot_lever_status);

printf("Light status             : %s\n", State_Machine[current_state].light);

printf("Direction valve status   : %s\n", State_Machine[current_state].direction_valve_status);

printf("Hydraulic control status : %s\n", State_Machine[current_state].hydraulic_control);

printf("Time delay               : %d seconds\n\n", State_Machine[current_state].time);

}

else if(pl == down && limit_switch == open)

{

current_state = GEAR_DOWN;

printf("Current state            : %s\n",State_Machine[current_state].current_state_indication);

printf("Pilots lever status      : %s\n",State_Machine[current_state].pilot_lever_status);

printf("Light status             : %s\n", State_Machine[current_state].light);

printf("Direction valve status   : %s\n", State_Machine[current_state].direction_valve_status);

printf("Hydraulic control status : %s\n", State_Machine[current_state].hydraulic_control);

printf("Time delay               : %d seconds\n\n", State_Machine[current_state].time);

}

}

 Output :

Current state            : Gear Down

Pilots lever status      : Down

Light status             : Green

Direction valve status   : Down

Hydraulic control status : Enabled

Time delay               : 3 seconds

Enter the status of pilot's lever and squat switch: 2 0

Current state            : Checking Before TakeOFF

Pilots lever status      : rising

Light status             : Green

Direction valve status   : Down

Hydraulic control status : Enabled

Time delay               : 3 seconds

Enter the status of pilot's lever and squat switch: 3 0

Current state            : Rising Gear

Pilots lever status      : Up

Light status             : Red

Direction valve status   : Up

Hydraulic control status : Enabled

Time delay               : 3 seconds

Enter the status of pilot's lever and limit switch:3 1

Current state            : Gear Up

Pilots lever status      : Up

Light status             : Off

Direction valve status   : Up

Hydraulic control status : Disabled

Time delay               : 3 seconds

Enter the status of pilot's lever and hydraulic control: 1 0

Current state            : Check Before Landing

Pilots lever status      : falling

Light status             : Red

Direction valve status   : Down

Hydraulic control status : Enabled

Time delay               : 3 seconds

Enter the status of pilot's lever and hydraulic control: 0 0

Current state            : Lowering Gear

Pilots lever status      : Down

Light status             : Green

Direction valve status   : Down

Hydraulic control status : Enabled

Time delay               : 3 seconds

Enter the status of pilot's lever and limit switch:1 1

Enter the status of pilot's lever and limit switch:8

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RESULTS:

 

 

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.