Challenge

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

// Mahanmadijaj Shekh

// Live course: Embedded system Batch10


#include <stdio.h>
#include <stdlib.h>

typedef enum

{

Before_TakeOff_S= 0,
Before_Landing_S,
Gear_Down_S,
Lowering_Gear_S,
Raising_Gear_S,
Gear_Up_S

} state_type;

typedef struct

{

state_type states[4];
char* plane_state[4];

} state;

state state_machine[4]=

{

{{Raising_Gear_S,Gear_Down_S},{"Raising Gear","Gear Down"}},
{{Lowering_Gear_S},{"Lowering Gear"}},
{{Before_TakeOff_S},{"Before Take Off"}},
{{Gear_Down_S,Before_TakeOff_S},{"Gear Down","Before Take Off"}},
{{Gear_Up_S,Before_Landing_S},{"Gear Up","Before Landing"}},
{{Before_Landing_S},{"Before Landing"}}

};

int current_state;

int pilot_lever, direction_value, light, limit_switch, squat_switch, control;

int main()

{


fflush(stdout);


printf("Please enter the Pilot's lever value:\n0 for Lever Down\n1 for Lever Up\n2 for Lever Rising\n3 for Lever Falling\n");


scanf("%d",&pilot_lever);


printf("Please enter the Direction value:\n0 for Direction Down\n1 for Direction Up\n");


scanf("%d",&direction_value);


printf("Please enter the lights:\n0 for Red\n1 for Green\n2 for Lights Off\n");


scanf("%d",&light);


printf("Please enter Squat Switch value:\n0 for Squat Switch close\n1 for Squat Switch open\n");


scanf("%d",&squat_switch);


printf("Please enter Limit Switch value:\n0 for Limit Switch close\n1 for Limit Switch open\n");


scanf("%d",&limit_switch);


printf("Please enter the Control value:\n0 for Disabled\n1 for Enabled\n");


scanf("%d",&control);

if((pilot_lever==2 && squat_switch==1)||light==1)


printf("\nThe Plane is in Before Take Off State");


else


if((pilot_lever==1 || direction_value==1) && light==0)


printf("\nThe Plane is in Raising Gear State");


else


if((limit_switch==0 || light==2) && control==0)


printf("\nThe Plane is in Gear Up State");


else


if(pilot_lever==3 || light==0)


printf("\nPlane is in Checking for Landing State\n");


else


if((pilot_lever==3 || control==1) && light==0)


printf("\nPlane is in Checking for Landing State\n");


else


if(pilot_lever==0 || direction_value==0)


printf("\nPlane is in Lowering Gear State\n");


else


if(pilot_lever==2 || light==0)


printf("\nPlane is in Checking before Take Off State\n");


else


if(squat_switch==0 || pilot_lever==3 || light==0)


printf("\nPlane is in Gear Down State\n");


else


if(limit_switch==1 || light==1)


printf("\nPlane is in Gear Down State\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.