Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
* question_fsm.c
*
* Created on: 15-Apr-2023
* Author: Subhajit
*/
#include <stdio.h>
typedef enum
{
Before_Take_Off_State = 0,// Different states of the Aeroplane as per the state diagram.
Before_Landing_State,
Gear_Down_State,
Lowering_Gear_State,
Raising_Gear_State,
Gear_Up_State
}state_type;
typedef struct
{
state_type states[2]; // structure variables
char* plane_state[2];
}state;
state state_machine[6]={
{{Raising_Gear_State,Gear_Down_State},{"Raising Gear","Gear Down"}},
{{Lowering_Gear_State},{"Lowering Gear"}},
{{Before_Take_Off_State},{"Before Take Off"}},
{{Gear_Down_State,Before_Take_Off_State},{"Gear Down","Before Take Off"}},
{{Gear_Up_State,Before_Landing_State},{"Gear Up","Before Landing"}},
{{Before_Landing_State},{"Before Landing"}}
};
int currentstate;
int pilotlever, directionvalue, lights, limitswitch, squatswitch, control; // We declare Global variables
int main()
{
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"); // Taking user input about pilot lever.
fflush(stdout);
scanf("%d",&pilotlever);
printf("Please enter the Direction value:\n0 for Direction Down\n1 for Direction Up\n"); // Taking user input about Direction
fflush(stdout);
scanf("%d",&directionvalue);
printf("Please enter the lights:\n0 for Red\n1 for Green\n2 for Lights Off\n"); //Taking user input about Lights
fflush(stdout);
scanf("%d",&lights);
printf("Please enter Squat Switch value:\n0 for Squat Switch close\n1 for Squat Switch open\n"); //Taking user input about Squat Switches
fflush(stdout);
scanf("%d",&squatswitch);
printf("Please enter Limit Switch value:\n0 for Limit Switch close\n1 for Limit Switch open\n"); //Taking user input about Limit Switches
fflush(stdout);
scanf("%d",&limitswitch);
printf("Please enter the Control value:\n0 for Disabled\n1 for Enabled\n"); //Taking user input about Control Values
fflush(stdout);
scanf("%d",&control);
if((pilotlever==2 && squatswitch==1)||lights==1) // Condition for state transition from Gear Down to Before Take off
{
printf("\nThe Plane is in Before Take Off State\n");
fflush(stdout);
}
else if((pilotlever==1 || directionvalue==1) && lights==0) // Condition for state transition from Before Take Off to Raising Gear
{
printf("\nThe Plane is in Raising Gear State\n");
fflush(stdout);
}
else if((limitswitch==0 || lights==2) && control==0) // Condition for state transition from Raising Gear to Gear Up state.
{
printf("\nThe Plane is in Gear Up State\n");
fflush(stdout);
}
else if(pilotlever==3 || lights==0) // Condition for state transition from Raising Gear to Checking Before Landing
{
printf("\nPlane is in Checking for Landing State\n");
fflush(stdout);
}
else if((pilotlever==3 || control==1) && lights==0) // Condition for state transition from Gear up to Checking Before Landing
{
printf("\nPlane is in Checking for Landing State\n");
fflush(stdout);
}
else if(pilotlever==0 || directionvalue==0) // Condition for state transition from Checking Before Landing to Lowering Gear State
{
printf("\nPlane is in Lowering Gear State\n");
fflush(stdout);
}
else if(pilotlever==2 || lights==0) // Condition for state transition from Lowering Gear to Checking Before Take off
{
printf("\nPlane is in Checking before Take Off State\n");
fflush(stdout);
}
else if(squatswitch==0 || pilotlever==3 || lights==0) // Condition for state transition from Checking Before Take off to Gear Down
{
printf("\nPlane is in Gear Down State\n");
fflush(stdout);
}
else if(limitswitch==1 || lights==1) // Condition for state transition from Lowering Gear to Gear Down
{
printf("\nPlane is in Gear Down State\n");
fflush(stdout);
}
return 0;
}
OUTPUT:
