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, 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 ans extension of airplanes landing gear for an different states of an airplane gear extension
  • The following are the different states of an airplain gear extension

a) Initailizing 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

  • In an main.c file we are going to create an syntax of an function of an 10 and 17th line
  • all this functions are defines inside the header file along with initialize state machine are declared in type of def enum function.

Goals:

  • The main goal is to write a code using the concept of finite state machine by using an type and also an enum
  • Controlling the direction of Valve.
  • Controlling the retraction and extension of Airplane’s landing gear.

Highlights and deliverables of the project:

  • By seeing an above state flow diagram all the conditions for an function are inside the header file.
  • Along with the initialize state machine rhe functions are declined by an typedef enum functions
  • typedef is used because the type can be changed for an existing variable
  • where as enum is used because in the case of enum for each and every variable the number will get automatically located
  • a direction valve is controlled by the software to allow the hydraullic pressure to either raise or lower the landing gear
  • Implementing the control for the retraction and extension of airplanes landing gear using finite state machije with the knowledge of various states od switch and gear
  • the retraction and also an extension of an airplane landing gear is illustrated from project.

Main.c file:

#include //preprocessor directives

#include "states.h"//preprocessor directives

static void (*state_table[])(void) = {Gear_Down,Checking_Before_takeoff,Raising_Gear,//Calling an different finite state condition inside the void function

Gear_Up,Checking_Before_Landing,Lowering_Gear};

int main()//main function

{

Init_State_Machine();//Initializing the state of an machine

while(1)//calling an while loop to execute an different condition

{

state_table[current_state]();//Initializing an array of an current state inside that of an state table

}

}

Header.h File:

#ifndef STATES_H_//PREPROCESSOR DIRECTIVES

#define STATES_H_//PREPROCESSOR DIRECTIVES

void Init_State_machine();//CHECKING FOR AN STATE FOR AN INITIAL STATE OF THE MACHINE
void Gear_Down();//Calling void for an gear down condition

void Checking_Before_Takeoff();//Calling void for an before takeoff condition

Void Raising_Gear();//Calling void for an raising gear condition

Void Gear_Up();//calling void for an gear up condition

void Checking_Before_Landing();// Calling void for an checking before landing

void Lowering_Gear();//Calling void for an lowering gear

typedef enum State//calling an typedef and an enum for different states

{

GR_DWN,//gear down

CHK_BFR_TKFF,//checking before takeoff

RSING_GR,//raising gear

GR_UP,//gear up

CHK_BFR_LND,//checking before land

LWRNG_GR//lowerung gear

}

State_Type;//end of the typedef enum for an switch case

{

Open,//during an open state

Close,//during an close state

}

Switch_Status;//end of typedef enum function

typedef enum Pilot_Lever//calling an typedef enum for an pilot lever state

{

Rising,//during rising state

Falling,//during falling state

UP,//during up condition

Down,//during down condition

}

Pilot_Lever_Status;//end of typedef enum function

typedef enum Hydraulic_Mechanism//calling an typedef enum for an Hydraulic_Mechanism state

{

Working,//during working state

Malfunctioning////during Malfunctioning state

}

Hydraulic_Mechanism_Status;//end of typedef enum function

static volatile Switch_Status squat_switch;//static volatile switch state condition for an squat switch

static volatile Switch_Status limit_switch;//static volatile switch state condition for an limit switch

static volatile Pilot_Lever_Status Pilot_Lever;//static volatile switch state condition for an Pilot_Lever

Static volatile Hydraulic_Mechanism_Status hydraulic_Mechanism;//static volatile switch state condition for hydraulic_Mechanism_status

State_Type current_state;//end of state type loop

typedef struct//calling an structure inside an typedef''

{

char* current_state_indication;//calling pointer char for current state indication

char* light_status;//calling pointer char for light status

char* direction_value_status;//calling pointer char for direction_pump_control_status

char* hydraulic_pump_control_status;//calling pointer char for hydraullic_pump_control_status

}

State_Table;

static State_Table State_Machine[6] = {//an different state of an state machine

is called in an array of an state table with an static data type

{"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",00},

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

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

};

#endif /*STATES_H_*///end of an headerfile.

Checking before landing.s File:

#include "States.h"//preprocessor directives

#include<stdio.h>//preprocessor directives

void Checking_Before_landing ()//calling an cgeck before landing condition

{

current_state = CHK_BFR_LND;//checking for current state in check before land

printf("nCurrent state : %sn",State_Machine[current_state].current_state_indication);//console inut output statements

printf("nEnter the Pilot's Lever position and status of hydraullic Mechanism");

fflush(stdout);

scanf("%d %d",&pilot_lever,&hydraulic_mechanism);//console input output tatements

if(pilot_levver == DOWN && hydraulic_Mechanism == Working)// execution of if loop

{

current_state = LWRNG_GR;

printf("ncurrent state : %sn",state_Machine[current_state].current_state_indication);

printf("light status:%sn",statea-machine[current_state].light_status);

printf("Direction Valve Status:%sn",State_machine[current_status].direction_valve_status);

}

else if(pilot_lever == DOWN & hydraulic_mechanism == Mal functioning//execution of if else loop for pilot lever and also to an hydraiullic mechanism

{

current_state = LWRNG_GR;//lowering gear sent to an current state of the gear

printf("ncurrent state : %sn",state_Machine[current_state].current_state_indication);

printf("light status:%sn",statea-machine[current_state].light_status);

printf("Direction Valve Status:%sn",State_machine[current_status].direction_valve_status);

Printf("Gas Pressurized sppring system status:%sn",status:%sn",State_Machine[current_state].gas_pressurized_spring_status[hyraulic_mechanism]);

}

//console input statements

if(pilot_lever == (UP || Rising || Falling))//ending an if loop statements

{

Checking_Before_Landing();

}

Checking before takeoff.s File:

#include "States.h"//Preprocessor directives

#include<stdio.h>//preprocessor directives

void Checking_Before_Takeoff()//calling an void for checking_Before_Takeoff

state

{

current_state = CHK_BFR_TKFF;//Checking _Before_Takeoff state to an current state

printf("n Enter the pilot's Lever Position, Squat Switch Status and Hydraulic status:");//console input output statement

fflush(stdout);//to clear unwanted memory

scanf("%d %d %d", &pilot_lever, &squat_switch, &hydraaulic_mechanism)://console input output statement

printf("n wait for 2 secsn");//console input output statement

if(pilot_lever == Falling || squat_switch == Close)// execution of if loop

{

Gear_Down();

}

elseif(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == working//execution of an else if in other state condition

{

current_state = RISING_GR;

printf("ncurrent state : %sn",state_Machine[current_state].current_state_indication);

printf("light status:%sn",statea-machine[current_state].light_status);

printf("Direction Valve Status:%sn",State_machine[current_status].direction_valve_status);

}

else if(pilot_lever == UP & squat_switch == Open && hydraulic_mechanism == Mal functioning//execution of an else if in other state condition

{

current_state = LWRNG_GR;//lowering gear sent to an current state of the gear

printf("ncurrent state : %sn",state_Machine[current_state].current_state_indication);

printf("light status:%sn",statea-machine[current_state].light_status);

printf("Direction Valve Status:%sn",State_machine[current_status].direction_valve_status);

Printf("Gas Pressurized sppring system status:%sn",status:%sn",State_Machine[current_state].gas_pressurized_spring_status[hyraulic_mechanism]);

}

}

Gear down.s File:

#include "States.h"//Preprocessor directives

#include<stdio.h>//preprocessor directives

current_state =GR_DWM;//Checking _Before_Takeoff state to an current state

printf("n Enter the pilot's Lever Position, Squat Switch Status:");//console input output statement

fflush(stdout);//to clear unwanted memory

scanf("%d %d", &pilot_lever, &squat_switch)://console input output statement

if(pilot_lever == Rising && squat_switch == Open)// calling an if loop condition for raising and open state of an pilot gear

{

current_state = CHK_BFR_TKFF;

printf("ncurrent state : %sn",state_Machine[current_state].current_state_indication);//console input output statements

printf("light status:%sn",statea-machine[current_state].light_status);

}

else

{

Gear_Down();//end of an if else statement

}

}

Initial state.s File:

#include "States.h"//Preprocessor directives

void Init_State_Machine()//calling an void for initial satte machine

{

current_state = GR_DWN;//them geardown state is put to an current state of the machine

printf("nstate machine is initialized & program is in Gear_Down state & Light_status: %sn", State_Machine[current_state].light_status);//console output statements)

}

Lowering gear.s File:

#include "States.h"//Preprocessor directives

#include<stdio.h>//preprocessor directives

void Lowering_Gear();//Calling void for an lowering gear

{

current_state = LWRNG_GR;//Calling an void for LWRNG_GR state

printf("n Enter the Limit Switch Status, pilot's Lever Position:");//console input output statement

fflush(stdout);//to clear unwanted memory

scanf("%d %d", &Limit_switch, &pilot_lever)://console input output statements

if( squat_switch == CLose && pilot_lever == Rising )// calling an if loop condition for an close an raising state for limit switch and pilot lever for if statement

{

current_state = CHK_BFR_TKFF;

printf("ncurrent state : %sn",state_Machine[current_state].current_state_indication);//console input output statements

printf("light status:%sn",state_machine[current_state].light_status);//console input output statements

}

if(limit_switch == Open && pilot_lever == DOWN)// calling an if else statement

{

current_state =GR_DWM;//gear down initialized to an current state

printf("ncurrent state : %sn",state_Machine[current_state].current_state_indication);

printf("light status:%sn",statea-machine[current_state].light_status);

printf("Hydraulic control for landing Gear status:%sn", state_machine[currrent_state].hydraulic_pump_control_status);}

else{

Lowering_Gear();//end of else statement for an lowering gear state

}

}

Lowering gear.s File

#include "States.h"//Preprocessor directives

#include<stdio.h>//preprocessor directives

void Raising_Gear();

current_state = RISING_GR;

printf("n Enter the Limit Switch Status, pilot's Lever Position:");//console input output statement

fflush(stdout);//to clear unwanted memory

scanf("%d %d", &Limit_switch, &pilot_lever)://console input output statements

printf("nWait for 1 secn");//console input output statement

if(pilot_lever == Falling && limit_switch == Open)// execution of an if in other state condition of an pilot liver and an limit switch

{

current_state = CHK_BFR_TKFF;

printf("ncurrent state : %sn",state_Machine[current_state].current_state_indication);//console input output statements

printf("light status:%sn",state_machine[current_state].light_status);//console input output statements

printf("Hydraulic contaol for Landing Gear status:", State-machine[current_state].hydraulic_pump_control_status);

}

else if(limit_switch == Close && pilot_lever == UP)//executionof an else if in other state condition

{

current -state = GR_UP;

printf("ncurrent state : %sn",state_Machine[current_state].current_state_indication);//console input output statements

printf("light status:%sn",state_machine[current_state].light_status);//console input output statements

printf("Hydraulic contaol for Landing Gear status:", State-machine[current_state].hydraulic_pump_control_status);

}

else

{

Raising_Gear();//end of else statement for an Raising_Gear state

}

}

Expected Outputs:

  • First we have to enter the pilot lever position and also an squat position of an machine

  • By seeing the above table its easy to give the switch type also an type status of an machine.
  • Next we have to enter the limit of an swith status and an pilot lever status as land2, after an sec we are able to see the status is in an null state
  • if we enter the pilot lever statsu as 1 then the light status will turn to an greean
  • similarly we have to checl the conditions for an different modes or an state of themachime
  • in the below output attached image we can see clearly abot controllimg the retraction and extension of airplanes landing gear

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.

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.