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

Aim:

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

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.

1.Here controlling the retraction and extension of Airplanes landing gear:

  • State_Type
  • Switch_Status
  • Pilot_Lever_Status
  • Hydraulic_Mechanism

Goals:

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

Controlling Direction Valve:

  • pilot's lever state is lever UP then its will must be direction will be UP
  • pilot's lever state is lever DOWN then its will must be direction will be DOWN

Controlling Airplane's Gear:

  • Limit Switch CLOSED then it is gear is UP
  • limit switch OPEND then it is gear is DOWN

Key Highlights of the project:

A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.

  • Direction valve is DOWN then it will be GEAR DOWN.
  • Direction vave is UP then it will be Raising gear (Takeoff).
  • Control of hydraulic pump for the landing gear part is disable then it will be Gear UP(airborne).
  • Direction valve is DOWN then it will be Lowering Gear (Landing).

Delivarables Of this Project:

Implementing the control for the retraction and extension of Airplane’s landing gear using the Finite state machine with the knowledge of various states of switch and gear.

State Machine is initialized & Program is in Gear_Down State & Light_Status : Green

Enter the Pilot's Lever Position and Squat Switch Status:0 0

Enter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:2 0 0

pilot's lever Position,Squat Switch Status and Hydraulic Mechanism Status :2 0 1

Enter the Limit Switch Status, Pilot's Lever Position :1 2

Enter the Pilot's Lever Position:1

Enter the Pilot's Lever Position and Status of Hydraulic Mechanism:3 1

Enter the Limit_Switch Status,Pilot_Lever Status ::3 0

Expected Outcomes:

The student will be getting the Knowledge of Finite State Machine algorithm which is used to achieve the control over the retraction and extension of Airplane’s landing gear using the switch and gear states of Airplane.

Code:

//State.h file

#ifndef STATE_H_

#define STATE_H_

#include<stdio.h> //header file

#include<stdlib.h> //header file

//function declaration

void Init_State_Machine();

void Gear_Down();

void Checking_Before_Takeoff();

void Raising_Gear();

void Gear_Up();

void Checking_Before_Landing();

void Lowering_Gear();

typedef enum State //declares an alternative name as state

{

GR_DOWN, //here calling the different state

CHK_BFR_TKOFF,

RISING_GR,

GEAR_UP,

CHK_BFR_LAND,

LOWERING_GR

}State_Type;

typedef enum Switch //declares an alternative name as switch

{

Open, //here calling the different switch

Close

}Switch_Status;

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

{

Raising, //here calling the different pilot lever

Falling,

UP,

DOWN

}Pilot_Lever_Status;

typedef enum Hydraulic_Mechanism //declares an alternative name as hydraulic mechnism

{

Working, //here calling the different hydraulic mechanism

Malfunctioning

}Hydraulic_Mechanism_Status;

//A function that has a scope that is limited to its object file

static volatile Switch_Status Squat_Switch;

static volatile Switch_Status limit_switch;

static volatile Pilot_Lever_Status pilot_lever;

static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;

State_Type current_state; //current state is the state type

typedef struct //declaration of structure using typedef

{

char* current_state_indication;

char* light_status;

char* direction_valve_status;

char* Landing_Gear_Hydraulic_Control_status;

char* gas_pressurized_spring_system_status[2];

}State_Table;

//calling the state_ Table

static State_Table State_Machine[6]={

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

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

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

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

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

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

};

#endif /* STATE_H_ */

// Project_2.c File

#include "State.h" //state header file

#include<stdio.h> //preprocessor header file

#include<stdlib.h>

//using state table the condition controlling the retraction and extension of airoplane's landig gear

static void(*state_table[])(void) = {Gear_Down,Checking_Before_Takeoff,Raising_Gear,Gear_Up,

Checking_Before_Landing,Lowering_Gear};

// main function

int main()

{

Init_State_Machine(); //declare initial state machine

//while loop executed

while(1)

{

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

}

}

void Init_State_Machine() //initial state machine condition

{

current_state = GR_DOWN; //current state is gear down

printf("\n State Machine is initialized & Program is in Gear_Down_state & Light_Status :%s\n",State_Machine[current_state].light_status);

//dispaly state machine is initialized and gear down state with status of light

}

void Gear_Down(void) //gear down condition

{

current_state = GR_DOWN; //current state is gear down

printf("\nEnter the pilot's Lever Position, Squat Switch Status "); //writes to console enter the pilot lever position and //squat switch status

fflush(stdout); //to clear standard out console buffer

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

//if pilot lever is raising and switch is open

if(pilot_lever == Raising && Squat_Switch == Open)

{

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

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

printf("\nLight State :%s\n",State_Machine[current_state].light_status); //print light status

}

else

{

Gear_Down(); //gear down statement

}

}

void Checking_Before_Takeoff() //checking before takeoff condition

{

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

printf("\n Enter the pilot's lever Position,Squat Switch Status and Hydraulic Mechanism Status :"); // writes to console //dispaly enter pilot lever position,switch squat, hydraulic mechanism status

fflush(stdout); //to clear standard out console buffer

scanf("%d %d %d",&pilot_lever,&Squat_Switch,&hydraulic_mechanism); //reads to console poilot lever, squat switch, //hydraulic mechanism

printf("\n Wait for 2 sec\n"); //dispaly wiat for two sec

if(pilot_lever == Falling || Squat_Switch == Close) //if pilot lever is falling then switch is open

{

Gear_Down(); //gear down condition

}

else if(pilot_lever == UP && Squat_Switch == Open && hydraulic_mechanism == Working) //lever is up , switch is //open and hydraulic mechanism is working

{

current_state = RISING_GR; //current state is rising gear

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

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

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

}

else if(pilot_lever == UP && Squat_Switch == Open && hydraulic_mechanism == Malfunctioning) //pilot lever is //up,switch is open and hyd mechanism is malfunctioning

{

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

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

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

}

}

void Raising_Gear() // raising gear operation

{

current_state = RISING_GR; // current state is raising gear

printf("\n Enter the Limit Switch Status,Pilots Lever Status:"); //writes to console enter limit switch and pilot lever status

fflush(stdout); //to clear standard out console buffer

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

printf("\n Wait for 1 sec\n"); //display wait for 1 sec

if(pilot_lever == Falling && limit_switch == Open) //if pilot lever is falling then limit switch is open

{

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

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

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

printf("Hydraulic Control for Landing Gear State :%s\n\n",State_Machine[current_state].Landing_Gear_Hydraulic_Control_status); //print landing grar hydraulic control //status

}

else if(limit_switch == Close && pilot_lever == UP) //limit switch close then poilot lever is open

{

current_state = GEAR_UP; //current state is gear up

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

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

printf("\n Hydraulic Control for landing Gear Status :%s\n",State_Machine[current_state].Landing_Gear_Hydraulic_Control_status); //print landing grar hydraulic control //status

}

else

{

Raising_Gear(); //raising gear operation is perform

}

}

void Gear_Up() //gear up condition

{

current_state = GEAR_UP; //current state is gear up

printf("\n Enter the Pilot's lever Position :"); //writes to console display enter pilot lever position

fflush(stdout); //to clear standard out console buffer

scanf("%d",&pilot_lever); //reads to console pilot lever

if(pilot_lever == Falling) //if pilot lever is falling

{

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

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

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

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

}

else

{

Gear_Up(); //gear up operation is perform

}

}

void Checking_Before_Landing() //checking before landing condition

{

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

printf("\n Enter the Pilot's Lever Position and Hydraulic Mechanism Status :"); //writes to console enter the pilot lever //position and hydraulic mechanism

fflush(stdout); //to clear standard out console buffer

scanf("%d %d",&pilot_lever, &hydraulic_mechanism); //reads to console pilot lever and hydraulic mechanism

if(pilot_lever == DOWN && hydraulic_mechanism == Working) //if pilot lever is down then hydraulic mechanism is //working

{

current_state = LOWERING_GR; //current state is lowering gear

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

printf("\nLight State: %s\n",State_Machine[current_state].light_status); //print light status

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

}

else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning) //pilot lever is down then hydraulic //mechanism is malfunctioning

{

current_state = LOWERING_GR; //current state is lowering gear

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

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

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

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

}

if(pilot_lever == (UP||Raising||Falling)) //if pilot lever is up,raising or falling

{

Checking_Before_Landing(); //landing gear operation is perform

}

}

void Lowering_Gear() //lowering gear condition

{

current_state = LOWERING_GR; //current state is lowering gear

printf("\n Enter the limit switch Squat Status.pilot's lever Position :"); //writes to console display enter the limit switch //status and pilot switch status

fflush(stdout); //to clear standard out console buffer

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

if(limit_switch == Close && pilot_lever == Raising) //if limit switch is close then pilot lever is raising

{

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

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

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

}

if(limit_switch == Open && pilot_lever == DOWN) //if limit switch is open then pilot lever is down

{

current_state = GR_DOWN; //current state is gear down

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

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

printf("Hydraulic Control For Landing Gear Status :%s\n",State_Machine[current_state].Landing_Gear_Hydraulic_Control_status); //print //Landing_Gear_Hydraulic_Control_status

}

else

{

Lowering_Gear(); //lowering gear operation is perform

}

}

Output:

Conclusion:

We write a code for control retraction and extension of airplanes landing gear implementation using Finite State Machine (FSM) this is run succesfully.

Embedded Live batch-9

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.