Challenge

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

/*Airplane Landing Gear using FSM

date: 24/11/2023

Vishnu V Nair*/

#include <stdio.h>

//Landing gear state

typedef enum

{

GEAR_DOWN,

BEFORE_TAKEOFF,

GEAR_RAISING,

GEAR_LOWERING,

BEFORE_LANDING,

GEAR_UP

} Airplane_state;

//Pilot lever state

typedef enum

{

LEVER_RISING,

LEVER_UP,

LEVER_FALLING,

LEVER_DOWN

} Lever_state;

//Limit switch state

typedef enum

{

OPEN,

CLOSE

} Switch_state;

//Direction valve state

typedef enum

{

VALVE_UP,

VALVE_DOWN

} Valve_state;

Airplane_state currentState = GEAR_DOWN; //Initial state of landing gear is GEAR_DOWN

Valve_state valvestate = VALVE_DOWN; //Initial state of direction valve is VALVE_DOWN

//Landing gear FSM function

void landinggear_state (Lever_state leverstate, Switch_state switchstate)

{

switch (currentState)

{

case GEAR_DOWN:

if (LEVER_RISING == leverstate && OPEN == switchstate)

{

printf ("Flight on Ground\n");

printf ("Light= GREEN\n");

currentState = BEFORE_TAKEOFF;

valvestate = VALVE_UP;

}

break;

case BEFORE_TAKEOFF:

if (LEVER_UP == leverstate || VALVE_UP == valvestate)

{

printf ("Checking before Takeoff\n");

printf ("Light= RED\n");

currentState = GEAR_RAISING;

}

else if (LEVER_FALLING == leverstate || CLOSE == switchstate)

{

printf ("Light= RED\n");

currentState = GEAR_DOWN;

}

break;

case GEAR_RAISING:

printf ("Flight Airborne\n");

if (CLOSE == switchstate && LEVER_UP == leverstate)

{

printf ("Landing Gear Control Disabled\n");

printf ("Light= OFF\n");

currentState = GEAR_UP;

}

else if (LEVER_FALLING == leverstate && OPEN == switchstate)

{

printf ("Light= RED\n");

currentState = BEFORE_LANDING;

}

break;

case GEAR_UP:

if (LEVER_FALLING == leverstate && CLOSE == switchstate)

{

printf ("Landing Gear Control Eabled\n");

printf ("Light= RED\n");

currentState = BEFORE_LANDING;

}

break;

case BEFORE_LANDING:

valvestate = VALVE_DOWN; //Valve state to VALVE_DOWN

if (LEVER_DOWN == leverstate || VALVE_DOWN == valvestate)

{

printf ("Landing Gear Initiated\n");

printf ("Light= RED\n");

currentState = GEAR_LOWERING;

}

break;

case GEAR_LOWERING:

if (LEVER_UP == leverstate || OPEN == switchstate)

{

printf ("Prepare Landing\n");

printf ("Light= GREEN\n");

printf("Flight Landed");

currentState = GEAR_DOWN;

}

else if (LEVER_RISING == leverstate || OPEN == switchstate)

{

printf ("Light= RED\n");

currentState = BEFORE_LANDING;

}

}

}

//Main Function

int main ()

{

//Transition of Landing gear state machine

landinggear_state (LEVER_RISING, OPEN);

landinggear_state (LEVER_UP, OPEN);

landinggear_state (LEVER_UP, CLOSE);

landinggear_state (LEVER_FALLING, CLOSE);

landinggear_state (LEVER_DOWN, CLOSE);

landinggear_state (LEVER_UP, OPEN);

return 0;

}

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.