Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
PROJECT-2:
#include
#include
void m (); //function
typedef enum
{
gear_down,
checking_before_take_off,
raising_gear,
gear_up,
checking_before_landing,
lowering_gear
} gear; //Enumerated data type
typedef enum
{
off,
green,
red
} light; //Enumerated data type
typedef enum
{
valve_up,
valve_down
} valve; //Enumerated data type
typedef struct
{
gear output;
gear next_state[6];
int time;
light l[3];
char *a[10];
} State; //Enumerated data type
State state_[6] = {
{gear_down, {gear_down, checking_before_take_off}, 3, {off, green, red},
{"gear down", "checking before take off", "airplan is on ground", "green",
"red"}},
{checking_before_take_off, {gear_down, raising_gear}, 3, {off, green, red},
{"gear down", "checking before take off", "raising_gear", "red"}},
{raising_gear, {gear_up, checking_before_landing}, 3, {off, green, red},
{"checking before take off", "gear up", "off"}},
{gear_up, {checking_before_landing}, 3, {off, green, red},
{"checking before landing", "gear up", "red"}},
{checking_before_landing, {lowering_gear}, 3, {off, green, red},
{"checking before landing", "lowering_gear", "gear up", "red"}},
{lowering_gear, {gear_up, checking_before_take_off}, 3, {off, green, red},
{"gear up", "checking before take off", "lowering_gear", "red"}},
};
//FSM (finite state machine
int squat_switch, current_state, pilot_lever, pilot_lever_up, limit_switch,
pilot_lever_falling, pilot_lever_down;
//global variable
int main ()
{
while (1)
{
printf ("squat switch=");
fflush(stdout);
scanf ("%d", &squat_switch);
if (0 == squat_switch) //plane is on ground squat switch off
{
printf ("\nlight=(%d)%s\n", state_[0].l[1], state_[0].a[3]);
printf ("\n%s", state_[0].a[0]);
printf ("\n%s\n", state_[0].a[2]);
current_state = state_[0].next_state[0];
continue;
} //condition to be in ground till squat switch is not closed
else if (1 == squat_switch) //plane is taking off or landing or airborn
{
printf
("\npilot lever for checking before take off or stay at ground=");
fflush(stdout);
scanf ("%d", &pilot_lever);
if (1 == pilot_lever && 1 == squat_switch) //condition to change state from down to rising
{
{
printf ("%s\n", state_[0].a[1]);
printf ("\nlight=(%d)%s\n", state_[0].l[2], state_[0].a[4]);
printf ("delay=%d\n", state_[0].time);
current_state = checking_before_take_off;
} //state has been changed
printf
("pilot lever condtion for rising gear or gear down status =");
fflush(stdout);
scanf ("%d", &pilot_lever);
if (2 == pilot_lever && 1 == squat_switch) //condition to change state 2 for lever up
{
printf ("\n%s", state_[1].a[2]);
printf ("\nlight=(%d)%s\n", state_[1].l[2], state_[1].a[3]);
current_state = raising_gear;
printf("\nlimit_switch to go at gear up or gear down before landing=");
fflush(stdout);
scanf ("%d", &limit_switch);
if (1 == limit_switch) //condition to change state from rising to gear up
{
{
printf("\n%s", state_[2].a[1]);
printf("\nlight=(%d)%s\n", state_[2].l[0],
state_[2].a[2]);
printf ("control for landing gear disabled");
current_state = gear_up;
//3 for falling
}
printf("\npilot lever before landing condition=");
fflush(stdout);
scanf ("%d", &pilot_lever);
if (pilot_lever == 3) //condition to change state from gear up to check before landing
{
printf("\n%s", state_[3].a[0]);
printf("\nlight=(%d)%s\n", state_[3].l[2],
state_[3].a[2]);
current_state = checking_before_landing;
// 4 for down
}
}
else if (1 == limit_switch || 0 == limit_switch) //condition to change state from rising to check before landing
{
printf("\n%s", state_[3].a[0]);
printf("\nlight=(%d)%s\n", state_[3].l[1],
state_[3].a[3]);
current_state = checking_before_landing;
// 4 for down
}
printf("\npilot_lever before lowering gear condition="); //4 for landing
fflush(stdout);
scanf("%d", &pilot_lever);
if (4 == pilot_lever) //condition to change state from check before landing to lowering gear
{
printf("\n%s\n", state_[4].a[1]);
printf("\nlight=(%d)%s\n", state_[4].l[1],
state_[4].a[3]);
current_state = lowering_gear;
//0 for open
}
printf("limit switch ");
fflush(stdout);
scanf("%d", &limit_switch);
printf("pilot_lever");
fflush(stdout);
scanf("%d", &pilot_lever);
if (0 == limit_switch || 0==pilot_lever) //condition to change state from lowering gear to gear down state
{
printf("\nlight=(%d)%s\n", state_[0].l[1],
state_[0].a[3]);
printf("\n%s", state_[0].a[0]);
printf("\n%s\n", state_[0].a[2]);
current_state = state_[0].next_state[0];
continue;
}
if (1 == pilot_lever || 1 == limit_switch)
{
m (); //called function
continue;
}
}
}
}
}
}
void
m () //called function
{
while(1)
{
squat_switch = 1;
printf ("pilot lever condtion for rising gear or gear down status =");
fflush(stdout);
scanf ("%d", &pilot_lever);
if (2 == pilot_lever && 1 == squat_switch) //condition to change state 2 for lever up
{
printf ("\nlight=(%d)%s\n", state_[1].l[2], state_[1].a[3]);
printf ("\n%s", state_[1].a[2]);
current_state = raising_gear;
printf ("\nlimit_switch to go at gear up or gear down before landing=");
fflush(stdout);
scanf ("%d", &limit_switch);
if (1 == limit_switch) //condition to change state from rising to gear up
{
{
printf ("\n%s", state_[2].a[1]);
printf ("\nlight=(%d)%s\n", state_[2].l[1], state_[2].a[3]);
printf ("control for landing gear disabled");
current_state = gear_up;
printf ("control for for landing gear are disabled");;
//3 for falling
}
printf ("\npilot lever checking before landing condition=");
fflush(stdout);
scanf ("%d", &pilot_lever);
if (pilot_lever == 3) //condition to change state from gear upm to check before landing
{
printf ("\n%s", state_[3].a[0]);
printf ("\nlight=(%d)%s\n", state_[3].l[1], state_[3].a[3]);
current_state = checking_before_landing;
// 4 for down
}
}
else if (1 == limit_switch || 0 == limit_switch) //condition to change state from rising to check before landing
{
printf ("\n%s", state_[3].a[0]);
printf ("\n light=(%d)%s\n", state_[3].l[1], state_[3].a[3]);
current_state = checking_before_landing;
// 4 for down
}
printf ("\npilot_lever before lowering gear condition="); //4 for landing
fflush(stdout);
scanf ("%d", &pilot_lever);
if (4 == pilot_lever) //condition to change state from check before landing to lowering gear
{
printf ("\n%s", state_[4].a[1]);
printf ("\n light=(%d)%s\n", state_[4].l[1], state_[4].a[3]);
current_state = lowering_gear;
//0 for open
}
printf ("limit switch ");
fflush(stdout);
scanf ("%d", &limit_switch);
printf("pilot lever");
fflush(stdout);
scanf("%d",&pilot_lever);
if (0 == limit_switch || 0== pilot_lever) //condition to change state from lowering gear to gear down state
{
printf ("\nlight=(%d)%s\n", state_[0].l[1], state_[0].a[3]);
printf ("\n%s", state_[0].a[0]);
printf ("\n%s\n", state_[0].a[2]);
current_state = state_[0].next_state[0];
break;
}
}
}
}

DESCRIPTION:
In this project,controlling the retraction and extension of airplane's landiing gear can be implemented using FSM.We took void m it is nothing but a function .Also took the typedef enum like gear_down,checking_before_take_off,raising_gear,gear_up,checkimg_before_landing,lowering_gear and lights like off,green,red. Also we took the valve_up,valve_down and typedeg struct is the gear output,gear next_state,time,light and char. Here we took the state_state[6] in all enmurated data types are presented in the state.Next we have declare FSM like a squat_switch,current_state,pilot_lever,pilot_lever_up,limit_switch . Now the declaration of the golbal varible and print the above all FSM conditions are different valves . The squat_switch is used to the plane is on ground suqat switch off and print the light and state values and going to the next step.Now the state has been changed .The next condition is pilot lever condition for rising gear or gear down status and also the condition changes state 2 for level up. Print the limit _switch to go at gear up or gear down before landing and limit_switch condition is changes state from to gear up.Now print the control for landing gear disabled because above print the conditions.Next condition is pilot lever before landing condition. It's changes state from gear up to check before landing.Now using the else if statement because of the values are printed the next step. In all conditions are used to the changes the one state to another state.Finally print the geardown state with different colour .The airplane is on grounded.Slove the project.