Challenge

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

Implementing the control for the retraction and extension of Airplane’s landing gear using the Finite state machine with the knowledge of various states of switch and gear.

#include<stdio.h>//standard input output library
typedef enum{//states
gear_down,
checking_before_takeoff,
raising_gear,
gear_up,
checking_before_landing,
lowering_gear
}state_types;
typedef enum{//switch status (for both squat switch and limit switch)
off,
on
}switc;
typedef enum{//pilot lever status
lever_down,
lever_up
}lever_state;
typedef enum{//input types
noinput,
limit_on,
squat_on,
limit_squat,
lever_raising,
lever_limit,
lever_squat
}sensor_input;

typedef struct{
state_types stype[7];
char*state[7];
char*light;
char*direction_controlvalve;
char*landing_gear_hydraulic;
}state;
state state_machine[6]={
{{gear_down,gear_down,gear_down,gear_down,checking_before_takeoff,checking_before_takeoff,gear_down},{"gear_down","gear_down","gear_down","gear_down","checking_before_takeoff","checking_before_takeoff","gear_down"},"green","down","enabled"},
{{gear_down,gear_down,gear_down,gear_down,raising_gear,raising_gear,gear_down},{"gear_down","gear_down","gear_down","gear_down","raising_gear","raising_gear","gear_down"},"green","down","enabled"},
{{checking_before_landing,checking_before_landing,raising_gear,raising_gear,raising_gear,gear_up,raising_gear},{"checking_before_landing","checking_before_landing","raising_gear","raising_gear","raising_gear","gear_up","raising_gear"},"red","up","enabled"},
{{checking_before_landing,checking_before_landing,checking_before_landing,checking_before_landing,raising_gear,gear_up,raising_gear},{"checking_before_landing","checking_before_landing","checking_before_landing","checking_before_landing","raising_gear","gear_up","raising_gear"},"off","null","disabled"},
{{lowering_gear,lowering_gear,lowering_gear,lowering_gear,checking_before_landing,checking_before_landing,checking_before_landing},{"lowering_gear","lowering_gear","lowering_gear","lowering_gear","checking_before_landing","checking_before_landing","checking_before_landing"},"red","down","enabled"},
{{gear_down,lowering_gear,gear_down,lowering_gear,lowering_gear,lowering_gear,lowering_gear},{"gear_down","lowering_gear","gear_down","lowering_gear","lowering_gear","lowering_gear","lowering_gear"},"red","down","enabled"}
};
int current_state;
lever_state lever;
switc limit_switch;
switc squat_switch;
sensor_input input;
int main()
{
current_state=gear_down;

while(1)
{
printf("\nEnter the status of pilot lever,squat switch,limit switch ");
fflush(NULL);
scanf("%d %d %d",&lever,&squat_switch,&limit_switch);
if(lever==0 && squat_switch==0 && limit_switch==0)
{
input=noinput;
printf("\n Current state is %s",state_machine[current_state].state[input]);
current_state=state_machine[current_state].stype[input];
}
else if(lever==0 && squat_switch==0 && limit_switch==1)
{
input=limit_on;
printf("\n Current state is %s",state_machine[current_state].state[input]);
current_state=state_machine[current_state].stype[input];
}
else if(lever==0 && squat_switch==1 && limit_switch==0)
{
input=squat_on;
printf("\n Current state is %s",state_machine[current_state].state[input]);
current_state=state_machine[current_state].stype[input];
}
else if(lever==0 && squat_switch==1 && limit_switch==1)
{
input=limit_squat;
printf("\n Current state is %s",state_machine[current_state].state[input]);
current_state=state_machine[current_state].stype[input];
}
else if(lever==1 && squat_switch==0 && limit_switch==0)
{
input=lever_raising;
printf("\n Current state is %s",state_machine[current_state].state[input]);
current_state=state_machine[current_state].stype[input];
}
else if(lever==1 && squat_switch==0 && limit_switch==1)
{
input=lever_limit;
printf("\n Current state is %s",state_machine[current_state].state[input]);
current_state=state_machine[current_state].stype[input];
}
printf("\n Light is %s",state_machine[current_state].light);
printf("\n Direction control valve status %s",state_machine[current_state].direction_controlvalve);
printf("\n Landing gear hydraulic system is %s",state_machine[current_state].landing_gear_hydraulic);
printf("\n");
}
return 0;
}

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.