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
===================================================================
Over View:
============
1. Controlling the plane state using lever state from user.
2. Squat switch status from user and accordingly changing the status.
3. Lever raising and lever falling status from hydraulic system control.
4. Detailing about the each state.
5. Checking the Hydraulic control system status at each state. If failed then two pressurized springs to get into action.
6. Printing output values at each state.
Outputs of the program:
===================
Squat switch status
Hydraulic pump status
Limit switch status
Lights status
Direction valve status
Next state
Delay
Hydraulic control status
Program code:
=================
#include
//Global variables
int Lever;
int input;
//enum for squat switch status
enum SQUATSWITCH
{
CLOSED = 0,
OPENED = 1,
FAILED = 2
};
//enum for Lever status in Hydraulic system
enum LeverStatus
{
RAISING = 8,
FALLING = 4,
NOSTATUS = 0
};
enum Hydraulic_Control
{
FAILURE = 0 ,RUNNING = 1
};
enum Hydraulic_Control HydraulicControlStatus;
//output variables in struct
typedef struct
{
char* HydraulicPump;
char* LimitSwitch;
char* SquatSwitch;
char* Lights;
char* DirectionValveStatus;
char* NextState;
enum LeverStatus HydraulicControlLeverStatus;
int Delay;
}PlaneResponse;
//struct variable definition to give output
PlaneResponse Response[9] = {
{"Enabled","Open","Open","Green","Down","CheckingBeforeTakeOff",8,3},
{"Enabled","Open","Open","Red","Up","RaisingGear",0,0},
{"Enabled","Open","close","Red","Down","GearDown",4,0},
{"Enabled","Open","Open","Red","Down","CheckingBeforeTakeOff",4,3},
{"Disabled","close","open","Off","Up","GearUp",0,0},
{"Enabled","close","open","Red","Up","CheckingBeforeLanding",4,0},
{"Enabled","Open","Open","Red","Down","LoweringGear",0,0},
{"Enabled","Open","close","Green","Down","GearDown",0,0},
{"Enabled","Open","Open","Red","Down","CheckingBeforeTakeOff",4,3},
};
//function for lever status in hydraulic system
void Hydraulic_System_Status();
//function declaration for result
void RESULT(int input);
//function declarations for each state
void geardown();
void checkingbeforetakeoff();
void raisinggear();
void gearup();
void checkingbeforelanding();
void loweringgear();
//main function
int main()
{
printf("\nPlane is parked at bay, Passengers are onboarding.\nHydraulic Mechanism monitoring the pressure on Nose Gear and neutralizing pressure by exerting pressure on opposite directions");
printf("\n=======================================================\n");
printf("Lever States : \nLever Raising : 8 \nLever Up : 2 \nLever Falling : 4 \nLever Disabled : 0 \nLever Down : 1");
printf("\nCurrent status of the outputs");
input = 7; //initiating the input with 7 for stating gear down status
//initiating geardown function
geardown();
}
//function definition for gear down state
void geardown()
{
//DISPLAYING CURRENT STATUS OF THE PLANE
printf("\n\n=========================STATUS OF PLANE==============================\n\n");
//calling result function to print status of variables
RESULT(input);
printf("\n\n=======================================================\n\n");
//calling Hydraulic system status function
Hydraulic_System_Status();
//Getting the Lever input from the user
printf("\n\nPlane is parked.\n Valid inputs \nEnter 8 - Lever Raising :");
fflush(stdout);
scanf("%d", &Lever);
//Squat switch status declaration and getting the status from console
int squat_switch;
enum SQUATSWITCH SquatSwitch; //declaration of squat switch status
printf("Enter Squat switch status \n Enter 1 if opened \nEnter 0 if closed \nEnter 2 if failed");
fflush(stdout);
scanf("%d",&squat_switch);
SquatSwitch = squat_switch;
if(Lever == 8)
{
if(SquatSwitch == OPENED)
{
input = 0;
printf("\nLeverRaising.\nChecking whether Squat Switch is opened.....\nDelay 4 seconds.\nPlane is checking before take off !!!");
checkingbeforetakeoff(); //function call for another state
}
else if(SquatSwitch == CLOSED)
{
input = 7;
printf("Squat switch is closed.Plane will be parked until it is open");
geardown();
}
else
{
printf("\nFailure of Squat switch is ignored. Passengers must be accompanied with next available flights. Plane will go under maintenance");
}
}
else
{
printf("\nPlease Enter valid Lever input to change the state");
geardown(); //function call for another state
}
}
void checkingbeforetakeoff()
{
//DISPLAYING THE CURRENT STATUS OF THE PLANE
printf("\n\n=========================STATUS OF PLANE==============================\n\n");
RESULT(input);
printf("\n\n=======================================================\n\n");
//calling Hydraulic system status function
Hydraulic_System_Status();
//Getting the Lever input from the user
printf("\n\nCurrently plane is checking before take off, \nEnter 2 to move the lever up and Raise the Gear. \nEnter 4 to transit the lever down and go to Gear down : ");
fflush(stdout);
scanf("%d", &Lever);
if(Lever == 2)
{
input = 1;
printf("\nLever and Direction valve are now UP \nNow Gear is Raising....Plane is taking off!!!");
raisinggear(); //function call for another state
}
else if(Lever == 4)
{
input = 2;
printf("\nSquat switch is closed. Plane is not taking off due to technical emergency. Plane will be parked");
geardown(); //function call for another state
}
else
{
printf("\nPlease Enter valid Lever input to change the state");
checkingbeforetakeoff(); //function call for another state
}
}
void raisinggear()
{
//DISPLAYING THE CURRENT STATUS OF THE PLANE
printf("\n\n=========================STATUS OF PLANE==============================\n\n");
RESULT(input);
printf("\n\n=======================================================\n\n");
//calling Hydraulic system status function
Hydraulic_System_Status();
//Getting the Lever input from the user
printf("\nCurrently Airplane is taking off. \nEnter 4 to lower the lever for Emergency landing. \nEnter 0 to keep flying and disable the hydraulic pump : ");
fflush(stdout);
scanf("%d", &Lever);
if(Lever == 4)
{
input =3;
printf("\nLever is falling Plane has to go for emergency landing and will check before take off");
checkingbeforetakeoff(); //function call for another state
}
else if(Lever == 0)
{
input = 4;
printf("\nPlane is currently airborne. Disabled the hydraulic pump");
gearup(); //function call for another state
}
else
{
printf("\nPlane is now taking off. Enter a valid input to change the state");
raisinggear(); //function call for another state
}
}
void gearup()
{
//DISPLAYING THE CURRENT STATUS OF THE PLANE
printf("\n\n=========================STATUS OF PLANE==============================\n\n");
RESULT(input);
printf("\n\n=======================================================\n\n");
//calling Hydraulic system status function
Hydraulic_System_Status();
//Getting the Lever input from the user
printf("\nCurrently plane is airborne with hydraulic pump disabled.\nEnter 4 to enable the hydraulic pump and lower the lever for descending the plane. : ");
fflush(stdout);
scanf("%d", &Lever);
if(Lever == 4)
{
input = 5;
printf("\nAirplane is now checking before landing");
checkingbeforelanding(); //function call for another state.
}
else
{
printf("\nAir plane is currently airborne. Enter a valid input to change the state");
gearup(); //function call for another state.
}
}
void checkingbeforelanding()
{
//DISPLAYING THE CURRENT STATUS OF THE PLANE
printf("\n\n=========================STATUS OF PLANE==============================\n\n");
RESULT(input);
printf("\n\n=======================================================\n\n");
//calling Hydraulic system status function
Hydraulic_System_Status();
//Getting the Lever input from the user
printf("\nCurrently plane is checking before landing. \nEnter 1 to move the lever and Direction valve down so that Gear can be lowered : ");
fflush(stdout);
scanf("%d", &Lever);
if(Lever == 1)
{
input = 6;
printf("\nDirection valve is down. Lowering the Gear. Airplane is now landing....");
loweringgear(); //function call for another state
}
else
{
printf("Plane is now checking before landing. Enter a valid input to change the state");
checkingbeforelanding(); //function call for another state
}
}
void loweringgear()
{
//DISPLAYING THE CURRENT STATUS OF THE PLANE
printf("\n\n=========================STATUS OF PLANE==============================\n\n");
RESULT(input);
printf("\n\n=======================================================\n\n");
//calling Hydraulic system status function
Hydraulic_System_Status();
//Getting the Lever input from the user
printf("\nAirplane is now landing.\nEnter 1 to open the limit switch and move the gear down and park the Plane.\nEnter 8 to check before take off for another flight : ");
fflush(stdout);
scanf("%d", &Lever);
if(Lever == 1)
{
input = 7;
printf("Limit switch is open and Gear is down. Plane is now parked....");
geardown();
}
else if(Lever == 8)
{
input = 8;
printf("Lever Raising , plane is not checking before take off");
checkingbeforetakeoff();
}
else
{
printf("Airplane is now landing. Enter a valid input to change the state");
loweringgear();
}
}
//function definition for result
void RESULT(int input)
{
//Code for hydraulic control lever status
char* Hydraulic_Control_Lever_Status;
if((Response[input].HydraulicControlLeverStatus == 8)&&(HydraulicControlStatus==1))
{
Hydraulic_Control_Lever_Status = "Lever Raising";
}
else if((Response[input].HydraulicControlLeverStatus == 4)&&(HydraulicControlStatus==1))
{
Hydraulic_Control_Lever_Status = "Lever Falling";
}
else if((Response[input].HydraulicControlLeverStatus == 0)||(HydraulicControlStatus==0))
{
Hydraulic_Control_Lever_Status = "No Status";
}
printf("\nHydraulic Pump Status : %s",Response[input].HydraulicPump);
printf("\nLimit switch Status : %s",Response[input].LimitSwitch);
printf("\nSquat Switch Status : %s",Response[input].SquatSwitch);
printf("\nLights Status : %s",Response[input].Lights);
printf("\nDirection Valve Status : %s",Response[input].DirectionValveStatus);
printf("\nPlane State : %s",Response[input].NextState);
printf("\nTime Delay : %d",Response[input].Delay);
printf("\nLever status in Hydraulic Control : %s ",Hydraulic_Control_Lever_Status);
}
void Hydraulic_System_Status()
{
int Hydraulic_Control_Status;
printf("\nIn case of Hydraulic system failure Enter 0:\nIin case of Hydraulic system is working fine Enter 1:");
fflush(stdout);
scanf("%d",&Hydraulic_Control_Status);
HydraulicControlStatus = Hydraulic_Control_Status;
if(HydraulicControlStatus == FAILURE)
{
HydraulicControlStatus = 0;
printf("\nHydraulic system is failed...!!! Two gas pressurized springs are in action to extend the gears");
}
else
{
HydraulicControlStatus = 1;
printf("\nHydraulic system check completed. System OK!!");
}
}
OUTPUT:
=================
Attached the output file.
State table:
================
|
Current State |
Lever Raising |
Lever Falling |
Lever Up |
Lever Down |
Hydraulic Pump |
Limit Switch |
Squat Switch |
Lights |
Direction Valve status |
Next State |
Delay |
|
Gear Down |
1 |
0 |
0 |
0 |
Enabled |
Open |
Open |
Green |
Down |
Checking Before Take Off Delay 3s |
3 |
|
Checking Before Take Off Delay 3s |
0 |
0 |
1 |
0 |
Enabled |
Open |
Open |
Red |
Up |
Raising Gear |
0 |
|
Checking Before Take Off Delay 3s |
0 |
1 |
0 |
0 |
Enabled |
Open |
Closed |
Red |
Down |
Gear Down |
0 |
|
Raising Gear |
0 |
1 |
0 |
0 |
Enabled |
Open |
Open |
Red |
Down |
Checking Before Take Off Delay 3s |
3 |
|
Raising Gear |
0 |
0 |
0 |
0 |
Disabled |
Closed |
Open |
Off |
Up |
Gear Up |
0 |
|
Gear Up |
0 |
1 |
0 |
0 |
Enabled |
Closed |
Open |
Red |
Up |
Checking Before Landing |
0 |
|
Checking Before Landing |
0 |
0 |
0 |
1 |
Enabled |
Open |
Open |
Red |
Down |
Lowering Gear |
0 |
|
Lowering Gear |
0 |
0 |
0 |
1 |
Enabled |
Open |
Closed |
Green |
Down |
Gear Down |
0 |
|
Lowering Gear |
1 |
0 |
0 |
0 |
Enabled |
Open |
Open |
Red |
Down |
Checking Before Take Off Delay 3s |
3 |