Challenge

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

#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 stat

{
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;
}
}
}
}

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.