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*/
/*Here I am using the binary state code instead of 1,2,3.
so we have only option with only 1/0, I am using this type due to simplying the code
and I am using the nested functions also for state transition in between functions*/
#include <stdio.h>
#include <stdlib.h>
int stp(int grdwn1,int chk_bf_tkff1,int rsg_gr1,int gr_up1,int chk_bf_ldg1,int lwg_gr1);//function prototype for state checking/calling
void rigr();
int static pl,sw,dv,ls,hd;
typedef enum state{ //states declaring
grdwn ,
chk_bf_tkff ,
rsg_gr ,
gr_up,
chk_bf_ldg,
lwg_gr
} flsts;
typedef enum ssqt{
open,
close
} ssqt;
typedef enum pilot_lever{
raising,
falling
} plr;
typedef enum hyd_mec{
working,
notworking,
} hdsts;
typedef enum divl{
up,
down,
} divl;
void grdwnd(){
printf("\nGear downed");
stp(0,0,0,0,0,0);
}
void chk_bf_tf(){ //function for checking before take off
printf("\nchecking before Take-off with Delay of 3 secs ");
printf("\nLights green");
stp(1,1,0,0,0,0);
printf("\nEnter the Pilot Lever status Direction valve and squat switch :- ");
scanf("%d %d %d",&pl,&dv,&sw);
if(pl == raising || dv == up){
rigr();
}
else if(sw == close || pl == falling){
grdwnd();
}
}
void lwg_ger(){ //function for Lowering gear
printf("\nLowering the gear now ");
stp(1,0,0,0,0,5);
printf("\nEnter the status of piolet lever and limit switch:- ");
scanf("%d %d",&pl,&ls);
if(pl == raising ){
chk_bf_tf();
}
else if(ls == open){
printf("\n Light is Green ");
grdwnd();
}
}
void chk_bf_lg(){ //function for checking before landing
printf("\nChecking before landing\n Lights are RED");
stp(1,0,0,0,4,0);
printf("\nEnter the status of pilot lever and directionn valve:- ");
scanf("%d %d",&pl,&dv);
if(pl == falling && dv == down){
lwg_ger();
}
}
void grup(){ //function for gear up
printf("\nFlight Gear is UP Lights are off");
stp(1,0,0,3,0,0);
printf("\nEnter the status of Piolet lever and hydraulic :- ");
scanf("%d %d",&pl,&hd);
if(pl == falling && hd == working){
chk_bf_lg();
}



}
void rigr(){ //function for Raising the gear
printf("\nRaising the Gear Lights are RED");
stp(1,0,2,0,0,0);
printf("\nEnter the status of Limit switch,Hydraulic,piolet lever:- ");
scanf("%d %d %d",&ls,&hd,&pl);
if(ls == close || hd == notworking){
grup();
}
else if(pl == falling){
chk_bf_lg();
}
}
void Intilaization(){ //Intial setting up the Flight cruise system.
printf("\nThe airpalne crusing system enabled, The Fligth is on Ground\n");
}
int main(){
Intilaization();
while(1){
printf("\nEnter the state of Pilot's Lever and Squatt switch:- ");
scanf("%d %d",&pl,&sw);
if(pl==raising && sw == open){
chk_bf_tf();
}
}
}
//Below code for the state checking.
int stp(int grdwn1,int chk_bf_tkff1,int rsg_gr1,int gr_up1,int chk_bf_ldg1,int lwg_gr1){
if(grdwn == grdwn1){
printf("\nTHE FLIGHT IS oN GROUND!\nSQUAT SWITCH CLOSED::PIOLT'S LEVER FALLING");
}
else if(chk_bf_ldg==chk_bf_ldg){
printf("\nPIOLT'S LEVER RAISING::SQAUT SWITCH OPENED::GREEN LIGHT");
}
else if(rsg_gr1==rsg_gr){
printf("\nPIOLT'S LEVER UP::DIRECTION VALVE UP::RED LIGHT");
}
else if(gr_up1 == gr_up){
printf("\nLIMIT SWITCH CLOSED::LIGHTS OFF::HYDRAULIC DISABLED");
}
else if(chk_bf_ldg1==chk_bf_ldg){
printf("\nPIOLT'S LEVER FALLING::HYDRAULIC ENABLED::RED LIGHT");
}
else if(lwg_gr1==lwg_gr){
printf("\nPIOLT'S LEVER DOWN::DIRECTION VALVE DOWN");
}
}
OUTPUT:-

PS C:\Users\gurur> cd 'c:\Users\gurur\vspraccodes\output'
PS C:\Users\gurur\vspraccodes\output> & .\'project2.exe'

The airpalne crusing system enabled, The Fligth is on Ground

Enter the state of Pilot's Lever and Squatt switch:- 0 0

checking before Take-off with Delay of 3 secs
Lights green
THE FLIGHT IS oN GROUND!
SQUAT SWITCH CLOSED::PIOLT'S LEVER FALLING
PIOLT'S LEVER RAISING::SQAUT SWITCH OPENED::GREEN LIGHT
Enter the Pilot Lever status Direction valve and squat switch :- 0 0 0

Raising the Gear Lights are RED
PIOLT'S LEVER UP::DIRECTION VALVE UP::RED LIGHT
Enter the status of Limit switch,Hydraulic,piolet lever:- 0 0 1

Checking before landing
Lights are RED
PIOLT'S LEVER FALLING::HYDRAULIC ENABLED::RED LIGHT
Enter the status of pilot lever and directionn valve:- 1 1

Lowering the gear now
PIOLT'S LEVER DOWN::DIRECTION VALVE DOWN
Enter the status of piolet lever and limit switch:- 0 1

checking before Take-off with Delay of 3 secs
Lights green
THE FLIGHT IS oN GROUND!
SQUAT SWITCH CLOSED::PIOLT'S LEVER FALLING
PIOLT'S LEVER RAISING::SQAUT SWITCH OPENED::GREEN LIGHT
Enter the Pilot Lever status Direction valve and squat switch :- 1 1 1

Gear downed
THE FLIGHT IS oN GROUND!
SQUAT SWITCH CLOSED::PIOLT'S LEVER FALLING
Enter the state of Pilot's Lever and Squatt switch:- 0 0

checking before Take-off with Delay of 3 secs
Lights green
THE FLIGHT IS oN GROUND!
SQUAT SWITCH CLOSED::PIOLT'S LEVER FALLING
PIOLT'S LEVER RAISING::SQAUT SWITCH OPENED::GREEN LIGHT
Enter the Pilot Lever status Direction valve and squat switch :- 0 0 0

Raising the Gear Lights are RED
PIOLT'S LEVER UP::DIRECTION VALVE UP::RED LIGHT
Enter the status of Limit switch,Hydraulic,piolet lever:- 1 1 0

Flight Gear is UP Lights are off
LIMIT SWITCH CLOSED::LIGHTS OFF::HYDRAULIC DISABLED
Enter the status of Piolet lever and hydraulic :- 1 0

Checking before landing
Lights are RED
PIOLT'S LEVER FALLING::HYDRAULIC ENABLED::RED LIGHT
Enter the status of pilot lever and directionn valve:- 1 1

Lowering the gear now
PIOLT'S LEVER DOWN::DIRECTION VALVE DOWN
Enter the status of piolet lever and limit switch:- 1 0

Light is Green
Gear downed
THE FLIGHT IS oN GROUND!
SQUAT SWITCH CLOSED::PIOLT'S LEVER FALLING

Enter the state of Pilot's Lever and Squatt switch:-

*SCREENSHOTS*

*NOTE* I done this project with an idea of making the Finite automation in an easy way, that anyone can easily understand the code, And I used the nested functioning that will easily go up with self-calling or assigning the system state inputs one to one each. other.

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.