Implement the Code for controlling the retraction and extension of Airplane’s landing gear
AIM:
To implement the code for controlling the retraction and extension of Airplane’s landing gear can be implemented using Finite State Machine (FSM).
PROGRAM:
#include
void Initiate_State_Machine();
void GearDown();
void CheckingBeforeTakeOFF();
void RaisingGear();
void GearUp();
void CheckingBeforeLanding();
void LoweringGear();
static void(*statetable[])(void)={GearDown, CheckingBeforeTakeOFF, RaisingGear, GearUp, CheckingBeforeLanding, LoweringGear};
typedef enum State
{
GEAR_DOWN,CHECKING_BEFORE_TAKEOFF,RAISING_GEAR,GEAR_UP,CHECKING_BEFORE_LANDING,LOWERNG_GEAR
}
State_Type;
typedef enum Switch
{
on,
off
}
Switch_Status;
typedef enum Pilot_Lever
{
Raising,
falling,
}
Pilot_Lever;
typedef enum Hydraulic_Mechanism
{
Working,
notworking
}
Hydraulic_Mechanism;
static volatile Switch_Status squat_switch;
static volatile Switch_Status limit_switch;
static volatile Pilot_Lever pl;
static volatile Hydraulic_Mechanism hm;
State_Type current_state;
typedef struct
{
char* current_state_indication;
char* light;
char* direction_valve_status;
char* landing_gear_hydraulic_control;
char* Gas_Pressurized_Spring_system[2];
}
State_Table;
static State_Table State_Machine[6] = {{"GearDown","Green","Down","Enabled",{NULL,NULL}},
{"CheckingBeforeTakeOFF","Green","Down","Enabled",{NULL,NULL}},
{"RaisingGear","Red","Up","Enabled",{NULL,NULL}},
{"GearUp","Off","NULL","Disabled",{NULL,NULL}},
{"CheckingBeforeLanding","Red" ,"Down","Enabled",{NULL,NULL}},
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
//Initial State Machine//
int main()
{
Initiate_State_Machine();
while(1)
{
statetable[current_state]();
}
}
// gear down //
void GearDown(void)
{
current_state=GEAR_DOWN;
printf("Enter thestatus of pilot's Lever and Squat Switch");
fflush(stdout);
scanf("%d %d",&pl,&squat_switch);
if(pl == Raising && squat_switch==on)
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("currrent state: %sn",State_Machine[current_state].current_state_indication);
printf("Light is:%sn", State_Machine[current_state].light);
}
else
{
GearDown();
}
}
//Checking Before Takeoff//
void CheckingBeforeTakeOFF(void)
{
current_state = CHECKING_BEFORE_TAKEOFF;
printf("Enter the Pilot's Lever Position,Squat Switch Status and hydraulic mechanism status:");
fflush(stdout);
scanf("%d %d %d", &pl, &squat_switch, &hm);
if(pl == falling&&squat_switch == off)
{
GearDown();
}
else if(pl == Raising && squat_switch == on && hm == Working)
{
current_state = RAISING_GEAR;
printf("Current State :%sn",State_Machine[current_state].current_state_indication);
printf("Light is: %sn", State_Machine[current_state].light);
printf("Direction Valve Status:%sn", State_Machine[current_state].direction_valve_status);
}
else if(pl == Raising && squat_switch == on && hm == notworking)
{
current_state = RAISING_GEAR;
printf("nCurrent State :%sn",State_Machine[current_state].current_state_indication);
printf("Light Status: %sn", State_Machine[current_state].light);
printf("Direction Valve Status:%sn", State_Machine[current_state].direction_valve_status);
printf("Status of gas pressurised Spring System:%sn",State_Machine[current_state].Gas_Pressurized_Spring_system[2]);
}
}
//Raising_Gear//
void RaisingGear(void)
{
current_state = RAISING_GEAR;
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&pl, &limit_switch);
if(pl == falling && limit_switch == on)
{
current_state = CHECKING_BEFORE_LANDING;
printf("nCurrent State: %sn",State_Machine[current_state].current_state_indication);
printf("Light is :%sn",State_Machine[current_state].light);
printf("Landing gear hydraulic control:%sn",State_Machine[current_state].landing_gear_hydraulic_control);
}
else if(pl == Raising && limit_switch == off )
{
current_state = GEAR_UP;
printf("Current State: %sn",State_Machine[current_state].current_state_indication);
printf("Light Status: %sn", State_Machine[current_state].light);
printf("Hydraulic Control for Landing Gear Status:%sn", State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
RaisingGear();
}
}
//Gear Up//
void GearUp(void)
{
current_state = GEAR_UP;
printf("Enter the status of Pilot's Lever:");
fflush(stdout);
scanf("%d",&pl);
if(pl == falling)
{
current_state = CHECKING_BEFORE_LANDING;
printf("Current State: %sn",State_Machine[current_state].current_state_indication);
printf("Light Status:%sn", State_Machine[current_state].light);
printf("Hydraulic Control for Landing Gear Status:%sn",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
GearUp();
}
}
//Check Before Landing //
void CheckingBeforeLanding(void)
{
current_state = CHECKING_BEFORE_LANDING;
printf("nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:");
fflush(stdout);
scanf("%d %d",&pl,&hm);
if(pl == falling && hm == Working)
{
current_state = LOWERNG_GEAR;
printf("nCurrent State:%sn", State_Machine[current_state].current_state_indication);
printf("Light is :%sn", State_Machine[current_state].light);
printf("Direction Valve Status:%sn", State_Machine[current_state].direction_valve_status);
}
else if(pl == falling && hm == notworking)
{
current_state = LOWERNG_GEAR;
printf("Current State:%sn",State_Machine[current_state].current_state_indication);
printf("Light Status:%sn", State_Machine[current_state].light);
printf("Direction Valve Status:%sn", State_Machine[current_state].direction_valve_status);
printf("Status of gas pressurised spring system:%sn",State_Machine[current_state].Gas_Pressurized_Spring_system[2]);
}
else if(pl == (Raising))
{
CheckingBeforeLanding();
}
}
//Lowering_Gear//
void LoweringGear(void)
{
current_state = LOWERING_GEAR;
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d ",&pl,&limit_switch);
if(pl == falling && limit_switch == on)
{
current_state = CHECKING_BEFORE_TAKEOFF;
printf("Current State:%sn",State_Machine[current_state].current_state_indication);
printf("Light is:%sn",State_Machine[current_state].light);
}
else if(pl == Raising && limit_switch == off)
{
current_state = GEAR_DOWN;
printf("Current State:%sn",State_Machine[current_state].current_state_indication);
printf("Light Status:%sn",State_Machine[current_state].light);
printf("Landing gearhydraulic control:%sn",State_Machine[current_state].landing_gear_hydraulic_control);
}
if (limit_switch==off)
{
LoweringGear();
}
}
//initiate state machine//
void Initiate_State_Machine()
{
current_state = GEAR_DOWN;
printf("The Finite State Machine is Intialized and current program is in" "GearDown state & Light is :%sn", State_Machine[current_state].light);
}
OUTPUT:
The Finite State Machine is Intialized and current program is inGearDown state & Light is :Green
Enter thestatus of pilot's Lever and Squat Switch 0 0
0 0
currrent state: CheckingBeforeTakeOFF
Light is:Green
Enter the Pilot's Lever Position,Squat Switch Status and hydraulic mechanism status:0 0
0 0
Current State :RaisingGear
Light is: Red
Direction Valve Status:Up
Enter the status of pilot's lever and limit switch:0 1
Enter the status of pilot's lever and limit switch:0 1
Current State: CheckingBeforeLanding
Light is :Red
Landing gear hydraulic control:Enabled
Enter the Pilot's Lever Position and Status of Hydraulic Mechanism:1 0
Current State:LoweringGear
Light Status:Green
Direction Valve Status:Down
Status of gas pressurised spring system:�*��
Enter the status of pilot's lever and limit switch: