Challenge

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

Program:

#include //Preprocessor

typedef enum //Declaring data type to show status of state machine.
{
Steady_state,
Rising_up,
lowering_down,
} Gear_status; //status of landing gear

typedef enum
{
steady,
up,
down,
} Valve_direction; //valve direction

typedef struct
{
Gear_status arr1[3];
char* state_signal[3];
Valve_direction arr3[3];
char* valve[3];
int time;

} State;

State state_machine[2] = {
{{Steady_state,Rising_up,lowering_down},{"Steady_state","Raising_Up","Lowering_down"},{steady,up,down},{"steady_state","Closing","Opening"},10}
};

// Global variables
int current_status;
int pilot_lever_signal;
int squat_switch_signal;

// This function is checking feedback i.e end user inputs.
void plane_status(int a, int b)
{
if(a == 0 && b == 0)
{
printf("plane is on landn");
printf("Checking all feedback before take offn");

}
if(a == 0 && b == 1)
{
printf("Checking all feedback before take offn");
printf("Pilot lever feedback is 0.Check Pilot lever feedbackn");
}
if(a == 1 && b == 0)
{
printf("Checking all feedback before take offn");
printf("limiting switch is closed.Please Enablen");
}
if(a == 1 && b == 1)
{
printf("plane is taking offn");
}
if(a == 2 && b == 0)
{
printf("Checking all feedback before Landingn");
printf("limiting switch is Disable.Please Enablen");
}
if(a == 0 && b == 2)
{
printf("Checking all feedback before Landingn");
printf("Pilot lever feedback is 0.Check Pilot lever feedbackn");
}
if(a == 2 && b == 2)
{
printf("plane is landingn");
}

}
int main() //Main function
{
current_status = Steady_state;
while(1)
{
printf("Enter Pilot Lever Position and Squat Switch Statusn"); // These two inputs user has to put.
fflush(stdout);
scanf("%d %d",&pilot_lever_signal,&squat_switch_signal);
plane_status(pilot_lever_signal,squat_switch_signal);

// Printing Actions of landing Gear accourding to inputs
if(pilot_lever_signal == 0 && squat_switch_signal == 0)
{
printf("Valve State : %sn",state_machine[current_status].valve[pilot_lever_signal]);
printf("Time Taken by Landing Gear : %d secn",state_machine[current_status].time);
printf("Landing Gear: %sn",state_machine[current_status].state_signal[pilot_lever_signal]);
}
if(pilot_lever_signal == 1 && squat_switch_signal == 1)
{
printf("Valve State : %sn",state_machine[current_status].valve[pilot_lever_signal]);
printf("Time Taken by Landing Gear : %d secn",state_machine[current_status].time);
printf("Landing Gear: %sn",state_machine[current_status].state_signal[pilot_lever_signal]);
}
if(pilot_lever_signal == 2 && squat_switch_signal == 2)
{

printf("Valve State : %sn",state_machine[current_status].valve[pilot_lever_signal]);
printf("Time Taken by Landing Gear : %d secn",state_machine[current_status].time);
printf("Landing Gear: %sn",state_machine[current_status].state_signal[pilot_lever_signal]);
}
}
}

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.