Challenge

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

LIVE BATCH 5:

/*
* airplane.c
*
* Created on: 17-Sep-2022
* Author: suraj kumar
*/
#include//preprocessor
#include
typedef enum Airplane_states{//enum declaration and variables
GEAR_DOWN,CHECKING_BEFORE_TAKEOFF_DELAY,RISING_GEAR,GEAR_UP,CHECKING_BEFORE_LANDING,LOWERING_GEAR
} STATES;//alias name to enum Airplane_states
typedef struct attributes{//structure declaration
char *Current_state[2];//member
char *direction_valve[2];//member
char *gear_colour[2];//member
STATES updator[2];//member
char *next_state[2];//member
} Airplane;//alias name for struct attributes
Airplane State_table[6]={{{"GEAR_DOWN","GEAR_DOWN"},{"Down","Up"},{"Green","Green"},
{GEAR_DOWN,CHECKING_BEFORE_TAKEOFF_DELAY},{"GEAR_DOWN","CHECKING_BEFORE_TAKEOFF_DELAY"}},//FOR GEAR DOWN
{{"CHECKING_BEFORE_TAKEOFF_DELAY","CHECKING_BEFORE_TAKEOFF_DELAY"},{"Down","Up"},{"Red","Red"},
{GEAR_DOWN,RISING_GEAR},{"GEAR_DOWN","RISING_GEAR"}},//FOR CHECKING_BEFORE_TAKEOFF_DELAY STATE
{{"RAISING_GEAR","RISING_GEAR"},{"Down","Control for Landing is Disabled"},{"Red","Off"},
{CHECKING_BEFORE_LANDING,GEAR_UP},{"CHECKING_BEFORE_LANDING","GEAR_UP"}},//FOR RAISING_GEAR
{{"GEAR_UP","GEAR_UP"},{"Control for Landing is disabled","Control for Landing is enabled"},{"Off","Red"},
{GEAR_UP,CHECKING_BEFORE_LANDING},{"GEAR_UP","CHECKING_BEFORE_LANDING"}},//FOR GEAR_UP
{{"CHECKING_BEFORE_LANDING","CHECKING_BEFORE_LANDING"},{"Control for Landing is enabled","Down"},
{"Red","Red"},{CHECKING_BEFORE_LANDING,LOWERING_GEAR},{"CHECKING_BEFORE_LANDING","LOWERING_GEAR"}},// FOR CHECKING_BEFORE_LANDING
{{"LOWERING_GEAR","LOWERING_GEAR"},{"Down","Up"},
{"Green","Red"},{GEAR_DOWN,CHECKING_BEFORE_TAKEOFF_DELAY},{"GEAR_DOWN","CHECKING_BEFORE_TAKEOFF_DELAY"}}};// for LOWERING_GEAR
static volatile int current_state,control_input;//variable declaration
int main()//main function
{//open loop
char limit_switch[7],squat_switch[7],pilot_lever[7];
printf("\t**HELLO WELCOME ON BOARD**\n");//print output in console
printf("Initially Plane is in GEAR_DOWN state\n");//print output in console
current_state=GEAR_DOWN;//variable initializing
while(1){
switch(current_state){
case 0:
{ printf("Enter the input of Limit-Switch: select from ON or OFF\n");
fflush(stdout);
scanf("%s",limit_switch);
printf("Enter the input of Squat-Switch: select from ON or OFF\n");
fflush(stdout);
scanf("%s",squat_switch);
printf("Enter the input of pilot_lever: select from RISING OR FALLING\n");
fflush(stdout);
scanf("%s",pilot_lever);
if(((!strcmp(limit_switch,"ON")) && (!strcmp("OFF",squat_switch)) &&(!strcmp("RISING",pilot_lever))))
control_input=1;
else
control_input=0;
break;
}
case 1:
{
printf("Limit-Switch is in ON Position and if you want to change choose from STAY or OFF\n");
fflush(stdout);
scanf("%s",limit_switch);
printf("Squat-Switchis in OFF Position and if you want to change choose from STAY OR ON\n");
fflush(stdout);
scanf("%s",squat_switch);
printf("Pilot-Lever is in RISING Position and if you want change it,choose from FALLING or UP\n");
fflush(stdout);
scanf("%s",pilot_lever);
if((!strcmp("STAY",limit_switch)) && (!strcmp("STAY",squat_switch)) && (!strcmp("UP",pilot_lever)))
control_input=1;
else
control_input=0;
break;
}
case 2:
{
printf("Limit-switch is in ON position");
printf("\nSquat-switch is in OFF position");
printf("\nPilot-Lever is in UP Position and if you want change it,choose from FALLING or CONTINUE\n");
fflush(stdout);
scanf("%s",pilot_lever);
if(!strcmp("CONTINUE",pilot_lever))
control_input=1;
else
control_input=0;
break;
}
case 3:
{
printf("Limit-switch is in ON position");
printf("\nSquat-switch is in OFF position\n");
printf("Now the Control for LANDING Gear is Disabled\n");
printf("PLANE is in Air Completely");
printf("\nPilot-Lever is in UP Position and if you want change it,choose from FALLING or CONTINUE\n");
fflush(stdout);
scanf("%s",pilot_lever);
if(!strcmp(pilot_lever,"FALLING"))
control_input=1;
else
{
printf("PLANE is Still in Air Completely\n");
control_input=0;
}
break;
}
case 4:
{
printf("Limit-switch is in ON position");
printf("\nSquat-switch is in OFF position\n");
printf("Now the Control for LANDING Gear is Enabled\n");
printf("Pilot-Lever is in FALLING Position and if you want change it,choose from DOWN OR NOT\n");
fflush(stdout);
scanf("%s",pilot_lever);
if(!strcmp("DOWN",pilot_lever))
control_input=1;
else
control_input=0;
break;
}
case 5:
{
printf("Limit-Switch is in ON Position and if you want to change choose from STAY or OFF\n");
fflush(stdout);
scanf("%s",limit_switch);
printf("Squat-Switchis in OFF Position and if you want to change choose from STAY OR ON\n");
fflush(stdout);
scanf("%s",squat_switch);
printf("Pilot-Lever is in FALLING Position and if you want to change it,choose from RISING OR DOWN\n");
fflush(stdout);
scanf("%s",pilot_lever);
if(((!strcmp(limit_switch,"STAY")) && (!strcmp(squat_switch,"STAY")) &&(!strcmp(pilot_lever,"RISING"))))
control_input=1;
else{
control_input=0;
printf("\t->Plane Landed Sucessfully<-");
}
break;
}
}
printf("Current State is %s\n",State_table[current_state].Current_state[control_input]);//print output in console
printf("Status of Direction Valve:%s\n",State_table[current_state].direction_valve[control_input]);//print output in console
printf("Status of Gear Colour:%s\n",State_table[current_state].gear_colour[control_input]);//print output in console
printf("State to be entered next is %s\n",State_table[current_state].next_state[control_input]);//print output in console
current_state=State_table[current_state].updator[control_input];//updating current_state
printf("\t\t**Moved to next state**\n");
fflush(stdout);//clear buffer
}
}

OUTPUT :
**HELLO WELCOME ON BOARD**
Initially Plane is in GEAR_DOWN state
Enter the input of Limit-Switch: select from ON or OFF
ON
Enter the input of Squat-Switch: select from ON or OFF
ON
Enter the input of pilot_lever: select from RISING OR FALLING
RISING
Current State is GEAR_DOWN
Status of Direction Valve:Down
Status of Gear Colour:Green
State to be entered next is GEAR_DOWN
**Moved to next state**
Enter the input of Limit-Switch: select from ON or OFF

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.