Challenge

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

AIM:

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

OVERVIEW OF THE PROJECT:

*In this project we are going to find an retraction and extension of aeroplane,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.

*The program to find the retraction and extension of Airplane’s landing gear for an different states are doing in an source file inside an main file

*The following are the different states of an airplan gear extension

a)Initializing state machine of all condition

b)Gear down

c)checking before take off

d)raising gear

e)gear up condition

f)Check before landing

g)Lowering gear

Goals:

*The main goal is to write an code using the concept of finite state machine by using an typedef and also an enum

*Controlling the retraction and extension of Airplane’s landing gear and seeing in an different modes of an operation

*Controlling the direction of Valve of Airplane’s landing gear.

Program:

#include<stdio.h>

#include<stdlib.h>

//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 to call the function upon requirement
static void(*statetable[])(void)={GearDown, CheckingBeforeTakeOFF, RisingGear, GearUp, CheckBeforeLanding, LoweringGear};

typedef enum State//gear states
{
GEAR_DOWN,

CHECKING_BEFORE_TAKEOFF,

RISING_GEAR,

GEAR_UP,

CHECK_BEFORE_LANDING,

LOWERING_GEAR,
}State_Type;

typedef enum Switch//switch states
{
open, closed

}Switch_status;

typedef enum pilot_lever//pilot lever states
{
down, falling, rising, up

}pilot_lever;

typedef enum hydraulic_mechanism//hydraulic control states
{
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:

RESULT:

Thus a program code is created to control retraction and extension of airplanes landing gear implementation using Finite State Machine (FSM).

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.