Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
1. Implement the Code for controlling the retraction and extension of Airplane’s landing gear.
ans)
Overview of the Project: (5 to 6 lines)
In this project, controlling the retraction and extension of Airplane’s landing gear can be implemented using Finite State Machine (FSM). FSM is the most efficient algorithm which is mathematical model of computation.
Goals ( 2 to 3 points)
Controlling the direction of Valve.
Controlling the retraction and extension of Airplane’s landing gear.
Key Highlights of the Project: (4 to 5 points)
A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.
Deliverables of this project: (4 to 5 points)
Implementing the control for the retraction and extension of Airplane’s landing gear using the Finite state machine with the knowledge of various states of switch and gear.
Expected Outcomes: (4 to 5 points)
The student will be getting the Knowledge of Finite State Machine algorithm which is used to achieve the control over the retraction and extension of Airplane’s landing gear using the switch and gear states of Airplane.
code:
#include<stdio.h>
void Initiate_State_Machine();
void GearDown();
void CheckingBeforeTakeOFFDelay3S();
void RaisingGear();
void GearUp();
void CheckBeforeLanding();
void LoweringGear();
static void(*statetable[])(void)={GearDown, CheckingBeforeTakeOFFDelay3S, RaisingGear, GearUp, CheckBeforeLanding, LoweringGear};
typedef enum statetypes{
gear_down,
checking_before_takeoff_delay_3s,
rising_gear,
gear_up,
check_before_land,
falling_gear
}state_type;
typedef enum Switch{
off,//OFF=0 closed
on//ON=1 open
}SW_status;
typedef enum lever{
falling,//0
raising//1
}aircraft_lever;
typedef enum hydraulic_mechanism{
disable,//0
enable//1
}hydraulic_mechanism;
static volatile SW_status squat_switch;
static volatile SW_status limit_switch;
static volatile aircraft_lever L;
static volatile hydraulic_mechanism hyd_mech;
state_type current_state;
typedef struct{
char* current_state_indication;
char* light;
char* direction_status;
char* landing_gear_hydraulic_control;
char* gas_pressurized_springs[2];
}state_table;
static state_table state_machine[6]={{"GearDown","Green","Down","enable",{0,0}},
{"CheckingBeforeTakeOFFDelay3S","Green","Down","enable",{0,0}},
{"RaisingGear","Red","Up","enable",{0,0}},
{"GearUp","Off","NULL","disable",{0,0}},
{"CheckBeforeLanding","Red","Down","enable",{0,0}},
{"LoweringGear","Green","Down","enable",{"Disabled","Enabled"}}};
int main()
{
Initiate_State_Machine();
while(1)
{
statetable[current_state]();
}
}
void GearDown(void)
{
current_state=gear_down;
printf("Enter the status of pilot's lever and squat switch: ");
fflush(stdout);
scanf("%d %d",&L,&squat_switch);
if(L==raising && squat_switch==on)
{
current_state = checking_before_takeoff_delay_3s;
printf("current state:%s\n",state_machine[current_state].current_state_indication);
printf("Light is :%s\n", state_machine[current_state].light);
}
else
{
GearDown();
}
}
//CheckingBeforeTakeOFFDelay3S
void CheckingBeforeTakeOFFDelay3S(void)
{
current_state=checking_before_takeoff_delay_3s;
printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism:");
fflush(stdout);
scanf("%d %d %d",&L,&squat_switch,&hyd_mech);
if((L==raising && squat_switch==on && hyd_mech==enable)||
(L==raising && squat_switch==on && hyd_mech==disable))
{
current_state=rising_gear;
printf("Current State:%s\n",state_machine[current_state].current_state_indication);
printf("Light is:%s\n",state_machine[current_state].light);
printf("Status of Direction valve:%s\n",state_machine[current_state].direction_status);
}
else
{
GearDown();
}
}
//RaisingGear
void RaisingGear(void)
{
current_state=rising_gear;
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&L,&limit_switch);
if(L==falling && limit_switch==on)
{
current_state=check_before_land;
printf("Current State:%s\n",state_machine[current_state].current_state_indication);
printf("Light is:%s\n",state_machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
else if(L==raising && limit_switch==off)
{
current_state=gear_up;
printf("Current State:%s\n",state_machine[current_state].current_state_indication);
printf("Light is:%s\n",state_machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
else
{
RaisingGear();
}
}
//GearUp
void GearUp(void)
{
current_state=gear_up;
printf("Enter the status of pilot's lever:");
fflush(stdout);
scanf("%d",&L);
if(L==falling)
{
current_state=check_before_land;
printf("Current State:%s\n",state_machine[current_state].current_state_indication);
printf("Light is:%s\n",state_machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
else
{
GearUp();
}
}
//CheckBeforeLanding
void CheckBeforeLanding(void)
{
current_state=check_before_land;
printf("Enter the status of pilot's lever and hydraulic mechanism status:");
fflush(stdout);
scanf("%d %d",&L,&hyd_mech);
if(L==falling && hyd_mech==enable)
{
current_state=falling_gear;
printf("Current State:%s\n",state_machine[current_state].current_state_indication);
printf("Light is:%s\n",state_machine[current_state].light);
printf("Status of Direction :%s\n",state_machine[current_state].direction_status);
}
else if(L==falling && hyd_mech==disable)
{
current_state=falling_gear;
printf("Current State:%s\n",state_machine[current_state].current_state_indication);
printf("Light is:%s\n",state_machine[current_state].light);
printf("Status of Direction:%s\n",state_machine[current_state].direction_status);
printf("Status of gas pressurized Spring System:%s\n",state_machine[current_state].gas_pressurized_springs[1]);
}
else
{
CheckBeforeLanding();
}
}
//LoweringGear.
void LoweringGear(void)
{
current_state=falling_gear;
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&L,&limit_switch);
if(L==falling && limit_switch==on)
{
current_state=checking_before_takeoff_delay_3s;
printf("Current State:%s\n",state_machine[current_state].current_state_indication);
printf("Light is:%s\n",state_machine[current_state].light);
}
else if(L==raising && limit_switch==off)
{
current_state=gear_down;
printf("Current State:%s\n",state_machine[current_state].current_state_indication);
printf("Light is:%s\n",state_machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
else
{
LoweringGear();
}
}
//Initiate_State_Machine
void Initiate_State_Machine()
{
current_state = gear_down;
printf("The Finite State Machine is Initialized and current the program is in\nGearDown State & Light is:%s\n",state_machine[current_state].light);
}