Challenge

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

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.

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.

Description of the Hardware:

Actually an airplane has 3 gears for landing :


• Nose Gear


• Left Gear


• Right Gear


There is a hydraulic pump which is exerting pressure to the
gears to bring it down or pull it up and that pump is
electrically driven.

Limit switches:

Every leg of the gear has one limit switch.Nose gear has
one extra Squat Switch to determine whether the airplane
is in ground or not.

Consider this cases:


• There is a possibility that the plane is about to take off and
an emergency comes where pilot has to abort the take off


• When taking off,to ensure that its right time to raising the
gear,check for at least 4 seconds that squat switch is open

• Hydraulic Control can detect the rising edge and falling
edge of pilot’s lever


• In case of Hydraulic system failure,there are two gas
pressurized springs by which gears can be extended


• The case of failure of Squat Switch is ignored.

WHAT IS FINITE STATE MACHINE?

A finite state machine (FSM) is a mathematical model of computation used to design algorithms and computer programs. It consists of a finite set of states, transitions between states, and actions to be taken in each state. The FSM transitions between states based on its current state and inputs, and its behavior is determined by the actions associated with each state and transition. Finite state machines are widely used in computer science, engineering, and mathematics for the design and implementation of algorithms, systems, and processes.

code:

#include<stdio.h>

#include<stdlib.h>

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

{

GR_DWN,

CHK_BFR_TKFF,

RSING_GR,

GR_UP,

CHK_BFR_LND,

LWRNG_GR

}State_Type;

typedef enum Switch

{

Open,

Close//Plane is in ground

}Switch_Status;

typedef enum Pilot_Lever

{

Rising,

Falling,

UP,

DOWN

}Pilot_Lever_Status;

typedef enum Hydraulic_Mechanism

{

Working,

Malfunctioning

}Hydraulic_Mechanism_Status;

/* -----input for changing the State----- */

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;

typedef struct

{

char* current_state_indication;

char* light_status;

char* direction_valve_status;

char* hydraulic_pump_control_status;

char* gas_pressurized_spring_status[2];

}State_Table;

static State_Table State_Machine[6] = {

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

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

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

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

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

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

};

void Gear_Down(void)

{

printf("in gear down state\n");

current_state = GR_DWN;

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

printf("\nEnter the Pilot's Lever Position and Squat Switch Status:");

fflush(stdout);

scanf("%d %d",&pilot_lever,&squat_switch);

if(pilot_lever == Rising && squat_switch == Open)

{

current_state = CHK_BFR_TKFF;

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

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

}

else

{

Gear_Down();

}

}

void Checking_Before_Takeoff()

{

current_state = CHK_BFR_TKFF;

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

printf("\nEnter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:");

fflush(stdout);

scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);

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

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

{

Gear_Down();

}

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

{

current_state = RSING_GR;

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

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

printf("Direction Valve Status:%s\n\n",State_Machine[current_state].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);

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

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

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

}

}

void Raising_Gear()

{

current_state = RSING_GR;

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

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

fflush(stdout);

scanf("%d %d",&limit_switch,&pilot_lever);

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

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

{

current_state = CHK_BFR_LND;

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

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

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

}

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

{

current_state = GR_UP;

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

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

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

}

else

{

Raising_Gear();

}

}

void Gear_Up()

{

current_state = GR_UP;

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

printf("\nEnter the Pilot's Lever Position:");

fflush(stdout);

scanf("%d",&pilot_lever);

if(pilot_lever == Falling)

{

current_state = CHK_BFR_LND;

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

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

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

}

else

{

Gear_Up();

}

}

void Checking_Before_Landing()

{

current_state = CHK_BFR_LND;

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

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

fflush(stdout);

scanf("%d %d",&pilot_lever,&hydraulic_mechanism);

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

{

current_state = LWRNG_GR;

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

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

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

}

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

{

current_state = LWRNG_GR;

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

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

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

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

}

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

{

Checking_Before_Landing();

}

}

void Lowering_Gear()

{

current_state = LWRNG_GR;

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

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

fflush(stdout);

scanf("%d %d",&limit_switch,&pilot_lever);

if(pilot_lever == Rising)

{

current_state = CHK_BFR_TKFF;

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

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

}

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

{

current_state = GR_DWN;

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

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

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

}

if(limit_switch == Close)

{

Lowering_Gear();

}

}

void Init_State_Machine()

{

//System Initialized and its in State_A

current_state = GR_DWN;

printf("\nState Machine is initialized & Program is in Gear_Down State & Light Status is Green \n");

}

int main()

{

Init_State_Machine();

while(1)

{

switch (current_state)

{

case 0: Gear_Down();

break;

case 1: Checking_Before_Takeoff();

break;

case 2: Raising_Gear();

break;

case 3: Gear_Up();

break;

case 4: Checking_Before_Landing();

break;

case 5: Lowering_Gear();

break;

default: break;

}

}

}

project summery:

This code implements a state machine in C programming language for the control of an aircraft's landing gear. The state machine transitions from one state to another based on the inputs from the pilot's lever position, squat switch status, and hydraulic mechanism status. The code implements 6 different states of the landing gear, including "Gear Down", "Checking Before Takeoff", "Raising Gear", "Gear Up", "Checking Before Landing", and "Lowering Gear". Each state has its own set of characteristics and conditions for transitioning to the next state. The code uses a combination of functions, enums, and structures to implement the state machine.

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.