Challenge

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

ABINAYA INBAMANI, BATCH-26

#include<stdio.h>
#include<stdlib.h>
void Initial_state_machine();
void Gear_down();
void Checking_before_takeoff();
void Raising_gear();
void Gear_up();
void Checking_before_landing();
void Lowering_gear();
typedef enum states{
GEAR_DOWN,
CHECK_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECK_BEFORE_LANDING,
LOWERING_GEAR
}state_type;
typedef enum Switch
{
open,
close
}Switch_status;
typedef enum pilot_lever
{
raising,
falling,
up,
down
}pilot_lever_status;
typedef enum hydraulic_mechanism
{
working,
malfunctioning
}hydraulic_mechanism_status;
static volatile Switch_status squat_switch;
static volatile Switch_status limit_switch;
static volatile pilot_lever_status pilot_lever;
static volatile pilot_lever_status hydraulic_mechanism;
state_type current_state;
typedef struct
{
char* current_state_status;
char* light_status;
char* direction_valve_status;
char* hydraulic_pump_ctrl_status;
char* gas_pressurize_spring_status[2];
}state_table;
static state_table state_machine[6]=
{
{"gear down","green","down","enables",{0,0}},
{"checking before take off","green","down""enabled",{0,0}},
{"raising gear","red","up","enabled",{"disabled","enabled"}},
{"gear up","off","NULL","disabled",{0,0}},
{"checking before landing","red","down","enabled",{0,0}},
{"lowering gear","green","down","enabled",{"disabled","enabled"}}
};
static void(*State_Table[])(void)={Gear_down,Checking_before_takeoff,Raising_gear,Gear_up,Checking_before_landing,Lowering_gear};
void Initial_state_machine()
{
current_state=GEAR_DOWN;
printf("\nState machine is initials and at first program is in gear down and its light status is :%s\n",
state_machine[current_state].light_status);
}
void Gear_down(void)
{
current_state= GEAR_DOWN;
printf("\nEnter the pilot's lever position and squat switch status:\n");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch);
if(pilot_lever==raising && squat_switch == open)
{
current_state=CHECK_BEFORE_TAKEOFF;
printf("\n The current state of the machine is:%s",state_machine[current_state].current_state_status);
printf("\n Light status of the current machine state is: %s\n",state_machine[current_state].light_status);
}
else{
Gear_down();
}
}
void Checking_before_takeoff()
{
current_state=CHECK_BEFORE_TAKEOFF;
printf("\n Enter the pilot lever position, squat switch and hydraulic mechanism:\n");
fflush(stdout);
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
printf("\n just wait 2 sec\n");
if(pilot_lever=up && squat_switch== close)
{
Gear_down();
}
else if(pilot_lever==up && squat_switch==open && hydraulic_mechanism==working)
{
current_state=RAISING_GEAR;
printf("\n Current state: %s\n",state_machine[current_state].current_state_status);
printf("\n Light status: %s\n",state_machine[current_state].light_status);
printf("\n Direcion status: %s\n\n",state_machine[current_state].direction_valve_status);
}
else if(pilot_lever== up && squat_switch== open && hydraulic_mechanism== malfunctioning)
{
current_state=RAISING_GEAR;
printf("\nCurrent state is: %s\n",state_machine[current_state].current_state_status);
printf("\nLight status: %s\n",state_machine[current_state].light_status);
printf("\n Direction status : %s\n",state_machine[current_state].direction_valve_status);
}
else
{
Gear_down();
}
}
void Raising_gear()
{
current_state=RAISING_GEAR;
printf("\n Enter the switch status and pilot lever status:\n");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
printf("\nWait for 1 sec\n");
if(pilot_lever==falling && limit_switch==open)
{
current_state==CHECK_BEFORE_LANDING;
printf("\n Current_state is: %s\n",state_machine[current_state].current_state_status);
printf("\nLight status:%s\n",state_machine[current_state].light_status);
printf("\nHydraulic condition for landing gear status is: %s\n",state_machine[current_state].hydraulic_pump_ctrl_status);
}
else if(limit_switch==close && pilot_lever==up)
{
current_state=GEAR_UP;
printf("\n Current state is: %s\n",state_machine[current_state].current_state_status);
printf("\nLight status is :%s\n",state_machine[current_state].current_state_status);
printf("\nHydraulic condition for landing gear status is: 5s\n",
state_machine[current_state].hydraulic_pump_ctrl_status);
}
else
{
Raising_gear();
}
}
void Gear_up()
{
current_state=GEAR_UP;
printf("\n Enter the pilot lever position:\n");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever== falling)
{
current_state=CHECK_BEFORE_LANDING;
printf("\nCurrent status: %s\n",state_machine[current_state].current_state_status);
printf("\nLight status: %s\n",state_machine[current_state].light_status);
printf("\nHydraulic condition for landing gear status is: %s\n",state_machine[current_state].hydraulic_pump_ctrl_status );
}
else
{
Gear_up();
}
}
void Checking_before_landing()
{
current_state=CHECK_BEFORE_LANDING;
printf("\nEnter the pilot lever positio, status of hydraulic machine:\n");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
if(pilot_lever==down && hydraulic_mechanism==working)
{
current_state=LOWERING_GEAR;
printf("\nCurrent state: %s\n",state_machine[current_state].current_state_status);
printf("\nLight status:%d\n",state_machine[current_state].light_status);
printf("\nDirection status:%s\n",state_machine[current_state].direction_valve_status);
}
else if(pilot_lever==down &&hydraulic_mechanism==malfunctioning)
{
current_state=LOWERING_GEAR;
printf("\nCurrent state: %s\n",state_machine[current_state].current_state_status);
printf("\nLight status: %s\n",state_machine[current_state].current_state_status);
printf("\n Direction status: %s\n",state_machine[current_state].current_state_status);
printf("\nGas pressurised spring status: %s\n",state_machine[current_state].gas_pressurize_spring_status);
}
if(pilot_lever==(up || raising || falling))
{
Checking_before_landing();
}
}
void Lowering_gear()
{
current_state=LOWERING_GEAR;
printf("\nEnter the pilot lever position, limit switch:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&limit_switch);
if(pilot_lever==down && limit_switch==open)
{
current_state=CHECK_BEFORE_TAKEOFF;
printf("\nCurrent state: %s\n",state_machine[current_state].current_state_status);
printf("\nLight status: %s\n",state_machine[current_state].light_status);
}
if(pilot_lever==down && limit_switch ==open)
{
current_state=GEAR_UP;
printf("\nCurrent state: %s\n",state_machine[current_state].current_state_status);
printf("\nLight status: %s\n",state_machine[current_state].light_status);
printf("\nHydraulic condition for landing gear status is: %s\n",state_machine[current_state].hydraulic_pump_ctrl_status );
}
else
{
Lowering_gear();
}
}
int main()
{
Initial_state_machine();
while(1)
{
State_Table[current_state]();
}
}
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.