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 the Airplane’s landing gear
*/

/*

To implement the Code for controlling the retraction and extension of an Airplane’s landing gear we will be using the Finite State Machine concept to make State Diagram and then State Table to make our algorithm and then implement that using c code.

Actually, an airplane has 3 gears for landing :
• Nose Gear
• Left Gear
• Right Gear
There is a hydraulic pump which is exerting pressure on the gears to bring them down or pull them up and that pump is electrically driven.

Here I am considering the following scenario:

6 Output States of the Machine( GearDown, DelayBeforeTakeOff, RaisingGear, GearUp, CheckBeforeLanding, LoweringGear).

3 status of indicator Light (Red, Green, OFF)

4 states of control input lever (Raising, Up, Falling, Down)

2 states of the limit switch (On, Off):- Every leg of the gear has one limit switch.

2 states of the squat switch (On, Off):- Nose gear has one Squat Switch to determine whether the airplane
is in the ground or not.

4 states of direction valve (Up, Down, Enable, Disable):- A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear

*/

State Diagram

State Table

Current State

Lever Control Input

Next State

Light

Limit Switch

Squat Switch

Direction Valve

Gear Down

Raising

Delay 4 sec before Take Off

Green

Open

Open

Down

Delay 4 sec before Take Off

Up

Raising Gear

Red

Open

Open

Up

Delay 4 sec before Take Off

Falling

Gear Down

Red

Open

Close

Down

Raising Gear

Up

Gear Up (Airborne)

Off

Closed

Open

disable

Raising Gear

Falling

Check before Landing

Red

Open

Open

Down

Gear Up (Airborne

Falling

Check before Landing

Red

closed

Open

enable

Check before Landing

Down

Lowering Gear

Red

open

open

Down

Lowering Gear

Down

Gear Down

Green

open

close

Down

Lowering Gear

Raising

Delay 4 sec before Take Off

Red

open

open

down

CODE:

#include<stdio.h>

typedef enum
{
Raising, Up, Falling, Down
}Lever;

typedef enum
{
GearDown, DelayBeforeTakeOff, RaisingGear,
GearUp, CheckBeforeLanding, LoweringGear
}State;

int main()
{
int input;
State Current_state = GearDown; // by default

printf("\n Different Lever control inputs for landing gear are as follows:");
printf("\n Enter '0' for Raising");
printf("\n Enter '1' for Up");
printf("\n Enter '2' for Falling");
printf("\n Enter '3' for Down");

while(1)
{
//for taking lever input
printf("\n Enter Lever Control Input: ");
fflush(stdout);
scanf("%d",&input);
fflush(stdin);

if((Current_state == GearDown)&&(input==Raising))
{
printf("\n Current State = waiting for 4 second before Take Off");
printf("\n Light = Green");
printf("\n Limit Switch => Open");
printf("\n Squat Switch => Open");
printf("\n Valve Direction => Down");
Current_state = DelayBeforeTakeOff;
printf("\n \n \n");
}

else if((Current_state == DelayBeforeTakeOff)&&(input==Up))
{
printf("\n Current State = Raising Landing Gear");
printf("\n Light = Red");
printf("\n Limit Switch => Open");
printf("\n Squat Switch => Open");
printf("\n Valve Direction => Up");
Current_state = RaisingGear;
printf("\n \n \n");
}

else if((Current_state == DelayBeforeTakeOff)&&(input==Falling))
{
printf("\n Current State = Gear Down");
printf("\n Light = Red");
printf("\n Limit Switch => Open");
printf("\n Squat Switch => Close");
printf("\n Valve Direction => Down");
Current_state = GearDown;
printf("\n \n \n");
}

else if((Current_state == RaisingGear)&&(input==Up))
{
printf("\n Current State = Gear Up (Airborne)");
printf("\n Light = OFF");
printf("\n Limit Switch => Closed");
printf("\n Squat Switch => Open");
printf("\n Valve Direction => Disabled");
Current_state = GearUp;
printf("\n \n \n");
}

else if((Current_state == RaisingGear)&&(input==Falling))
{
printf("\n Current State = Checking Before Landing");
printf("\n Light = Red");
printf("\n Limit Switch => Open");
printf("\n Squat Switch => Open");
printf("\n Valve Direction => Down");
Current_state = CheckBeforeLanding;
printf("\n \n \n");
}

else if((Current_state == GearUp)&&(input==Falling))
{
printf("\n Current State = Checking Before Landing");
printf("\n Light = Red");
printf("\n Limit Switch => Closed");
printf("\n Squat Switch => Open");
printf("\n Valve Direction => Enabled");
Current_state = CheckBeforeLanding;
printf("\n \n \n");
}

else if((Current_state == CheckBeforeLanding)&&(input==Down))
{
printf("\n Current State = Lowering Landing Gear");
printf("\n Light = Red");
printf("\n Limit Switch => Open");
printf("\n Squat Switch => Open");
printf("\n Valve Direction => Down");
Current_state = LoweringGear;
printf("\n \n \n");
}

else if((Current_state == LoweringGear)&&(input==Down))
{
printf("\n Current State = Landing Gear Down");
printf("\n Light = Green");
printf("\n Limit Switch => Open");
printf("\n Squat Switch => Close");
printf("\n Valve Direction => Down");
Current_state = GearDown;
printf("\n \n \n");
}

else if((Current_state == LoweringGear)&&(input==Raising))
{
printf("\n Current State = Waiting for 4 seconds before Take Off");
printf("\n Light = Red");
printf("\n Limit Switch => Open");
printf("\n Squat Switch => Open");
printf("\n Valve Direction => Down");
Current_state = DelayBeforeTakeOff;
printf("\n \n \n");
}

else
{
printf("\n Wrong input Command Retry \n \n \n ");
}
}

return (0);
}

OUTPUT:

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.