Challenge

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

Implementation of the code for controlling the retraction and extension of airplane’s landing gear

Aim:

  • To implement the code for control retraction and extension of airplanes landing gear implementation using Finite State Machine (FSM).

Objective:

  • Controlling the direction of valve.
  • Controlling the retraction and extension of airplane’s landing gear.

Principle:

  • The airplane has three gears for landing such as nose gear, left gear and right gear.
  • There is a hydraulic pump which is exerting pressure tothe gears to bring it down or pull it up using electrical driven pump.
  • When the direction of the valve is down then it is landed or gear down position.
  • Similarly when the direction of valve is up then it is in rising gear or taking off.
  • When gear is up then light status is off.
  • Gear is down then the light status is green.
  • Gear is raising or lowering then the colour of light is red.

Process:

  • Gear down
  • Checking before take off
  • Raising gear
  • Gear up
  • Checking before landing
  • Lowering gear

State Type

GR_DWN

CHK_BFR_TKFF

RSING_GR

GR_UP

CHK_BFR_LND

LWRNG_GR

Switch Status

Open

Close

Pilot Lever Status

Rising

Falling

Up

Down

Hydraulic Mechanics Status

Working

Malfunctioning

Program:

/*

* main.c

*/

#include<stdio.h>

#include "States.h"//states header file

static void(*state_table[])(void) = {Gear_Down, Checking_Before_Takeoff,Raising_Gear, Gear_Up, Checking_Before_Landing, Lowering_Gear};//using state table the condition controlling the retraction and extension of airplane landing gear are called

int main()

{

Init_State_Machine(); //intial state machine is declared

while(1)

{

state_table[current_state]();//current state is declared in the state table

}

}

/*

* states.h

*/

#ifndef STATES_H_

#define STATES_H_

void Init_State_Machine();//intial state of the machine is declared using void

void Gear_Down();//gear down is declared using void

void Checking_Before_Takeoff();//checking before takeoff is declared using void

void Raising_Gear();//raising gear operation is declared using void

void Gear_Up();//gear up operation is declared using

void Checking_Before_Landing();//checking before landing is declared using void

void Lowering_Gear();//lowering gear is declared using void

typedef enum State//declares an alternative name as state

{

GR_DWN,

CHK_BFR_TKFF,

RSING_GR,

GR_UP,

CHK_BFR_LND,

LWRNG_GR

}State_Type;//state type is declared

typedef enum Switch//declares the alternative name as switch

{

Open,

Close

}Switch_Status;//status of switch

typedef enum Pilot_Lever//declares the alternative name as pilot lever

{

Rising,

Falling,

UP,

DOWN

}Pilot_Lever_Status;//the pilot lever status

typedef enum Hydraulic_Mechanism//alternative name as hydraulic mechanism

{

Working,

Malfunctioning

}Hydraulic_Mechanism_Status;//hydraulic mechanism status is declared

static volatile Switch_Status squat_switch;//switch status stored in main memory as squat switch

static volatile Switch_Status limit_switch;//switch status stored in main memory as limit switch

static volatile Pilot_Lever_Status pilot_lever;//pilot lever status stored in main memory as pilot lever

static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;//hydraulic mechanism status stored in main memory as hydraulic mechanism

State_Type current_state;//current state is the state type

typedef struct//structure is declared using typedef

{

char* current_state_indication;//current state indication is declared using character

char* light_status;//light status declared using character

char* direction_valve_status;//direction_valve_status declared using character

char* hydraulic_pump_control_status;//hydraulic_pump_control_status declared using character

char* gas_pressurized_spring_status[2];//gas_pressurized_spring_status declared using character

}State_Table;//state table declaration

static State_Table State_Machine[6] = {

{"GearDown","Green","Down","Enabled",0,0},

{"Checking Before Take Off","Green","Down","Enabled",0,0},

{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},

{"Gear Up","Off","Null","Disabled",0,0},

{"Checking Before Landing","Red","Down","Enabled",0,0},

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

};

#endif /* STATES_H_ */

/*

* Init_State_Machine.c

*/

#include"States.h"// state header file is declared

void Init_State_Machine()//initial state machine condition

{

current_state = GR_DWN;//current state is gear down condition

printf("\nState Machine is initialized & Program is in Gear_Down State & Light Status: %s\n"

,State_Machine[current_state].light_status);//display state machine is initialized and gear down state with status of light

}

/*

* geardown.c

*/

#include"States.h"

#include<stdio.h>

void Gear_Down(void)//gear down condition

{

current_state = GR_DWN;//current state is gear down

printf("\n Enter the Pilot's Lever Position and Squat Switch Status:");//display enter the pilot lever position and squat switch status

fflush(stdout);//clears cache memory

scanf("%d %d",&pilot_lever,&squat_switch);//reads pilot lever and squat switch

if(pilot_lever == Rising && squat_switch == Open)//if pilot lever is rising and switch is open

{

current_state = CHK_BFR_TKFF;//current state is check before takeoff

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state

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

}

else//else condition

{

current_state = GR_DWN;//current state is gear down

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state

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

Gear_Down();//gear down state

}

}

/*

* checkingbeforetakeoff.c

*/

#include"States.h"

#include<stdio.h>

void Checking_Before_Takeoff()//checking before takeoff condition

{

current_state = CHK_BFR_TKFF;//current state is checking before takeoff

printf("\nEnter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:");//display the pilot lever position , switch status and hydraulic mechanism status

fflush(stdout);

scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);//read pilot lever, switch and hydraulic mechanism

printf("\nWait for 3 secs\n");

if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)

{

current_state = RSING_GR;//current state is rising gear

printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);//display current state

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

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

}

else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Malfunctioning)

{

current_state = RSING_GR;

printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);//display current state

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

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

printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);//display gas pressurized spring system status

}

else if(pilot_lever == Falling || squat_switch == Close)

{

current_state = GR_DWN;

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state

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

Gear_Down();

}

}

/*

* risinggear.c

*/

#include"States.h"

#include<stdio.h>

void Raising_Gear()

{

current_state = RSING_GR;

printf("\nEnter the Limit Switch Status,Pilots Leaver Status:");//display the pilot lever position , switch status

fflush(stdout);

scanf("%d %d",&limit_switch,&pilot_lever);//read pilot lever, limit switch

printf("\nWait for 3 sec\n");

if(pilot_lever == Falling && limit_switch == Open)

{

current_state = CHK_BFR_LND;//current state is checking before landing

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state

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

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);//display hydraulic control for landing gear status

}

else if(limit_switch == Close && pilot_lever == UP)

{

current_state = GR_UP;//current state is gear up

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state

printf("Light Status: %s\n", State_Machine[current_state].light_status);//display current state

printf("Hydraulic Control for Landing Gear Status:%s\n", State_Machine[current_state].hydraulic_pump_control_status);//display hydraulic control for landing gear status

}

else

{

current_state = RSING_GR;

printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);//display current state

printf("Light Status: %s\n", State_Machine[current_state].light_status);//display current state

printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);//display hydraulic control for landing gear status

printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);//display gas pressurized spring status

Raising_Gear();

}

}

/*

* gearup.c

*/

#include<stdio.h>

#include"States.h"

void Gear_Up()//gear up condition

{

current_state = GR_UP;//current state is gear up operation

printf("\nEnter the Pilot's Lever Position:");//display to Enter the Pilot's Lever Position

fflush(stdout);

scanf("%d",&pilot_lever);// read the pilot lever

if(pilot_lever == Falling)

{

current_state = CHK_BFR_LND;//current state is checking before landing

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state

printf("Light Status:%s\n", State_Machine[current_state].light_status);//display current state

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);//display hydraulic control for landing gear status

}

else

{

current_state = GR_UP;//current state is gear up

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state

printf("Light Status: %s\n", State_Machine[current_state].light_status);//display current state

printf("Hydraulic Control for Landing Gear Status:%s\n", State_Machine[current_state].hydraulic_pump_control_status);//display hydraulic control for landing gear status

Gear_Up();

}

}

/*

* checkingbeforelanding.c

*/

#include "States.h"

#include<stdio.h>

void Checking_Before_Landing()//checking before landing condition

{

current_state = CHK_BFR_LND;//current state is checking before landing

printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:");// display Enter the Pilot's Lever Position and Status of Hydraulic Mechanism

fflush(stdout);

scanf("%d %d",&pilot_lever,&hydraulic_mechanism);// read the pilot lever is down and hydraulic mechanism

if(pilot_lever == DOWN && hydraulic_mechanism == Working)

{

current_state = LWRNG_GR;//current state is lowering gear

printf("\nCurrent State:%s\n", State_Machine[current_state].current_state_indication);//display the current state

printf("Light Status:%s\n", State_Machine[current_state].light_status);//display the light status

printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);//display the direction valve status

}

else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)

{

current_state = LWRNG_GR;//current state is lowering gear

printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);//display the current state

printf("Light Status:%s\n", State_Machine[current_state].light_status);//display the light status

printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);//display the direction valve status

printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);//display the gas_pressurized_spring_status

}

else if(pilot_lever == (UP || Rising || Falling))

{

current_state = CHK_BFR_LND;//current state is checking before landing

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display the current state

printf("Light Status:%s\n",State_Machine[current_state].light_status);//display the light status

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);//display the direction valve status

Checking_Before_Landing();

}

}

/*

* loweringgear.c

*/

#include "States.h"

#include<stdio.h>

void Lowering_Gear()// lowering gear condition

{

current_state = LWRNG_GR;//current state is lowering gear

printf("\nEnter the Limit Switch Status,Pilots Leaver Status:");// diaplay the Enter the Limit Switch Status,Pilots Leaver Status

fflush(stdout);

scanf("%d %d",&limit_switch,&pilot_lever);// read the switch and lever status

if(limit_switch == Close && pilot_lever == Rising )

{

current_state = CHK_BFR_TKFF;//current status is checking before take off

printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);//display the current state

printf("Light Status:%s\n",State_Machine[current_state].light_status);//dislay the light status

}

else if(limit_switch == Open && pilot_lever == DOWN)

{

current_state = GR_DWN;//current state is gear down

printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);//display the current state

printf("Light Status:%s\n",State_Machine[current_state].light_status);//dislay the light status

printf("Hydraulic Controlfor Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);//display the hydraulic pump control for landing control

}

else

{

current_state = LWRNG_GR;//current state is lowering gear

printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);//display the current state

printf("Light Status:%s\n",State_Machine[current_state].light_status);//display the current state

Lowering_Gear();

}

}

Output:

the input give from above the flowchart

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.