Project 2: Impliment the code for controlling and retracting the code for airplane landing gear
Answer:
code:
PG program · 48 weeks Build projects like this: PG Program in Mechanical Design (CAD)
Industry projects, mentor reviews and placement support. Ask a counsellor if it fits your background.
#include
void Initiate_State_Machine();
void GearDown();
void CheckingBeforeTakeOFF();
void RaisingGear();
void GearUp();
void CheckBeforeLanding();
void LoweringGear();
static void(*statetable[])(void)={GearDown, CheckingBeforeTakeOFF,
RaisingGear, GearUp, CheckBeforeLanding, LoweringGear};
typedef enum State
{
GEAR_DOWN,
CHECK_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECK_BEFORE_LANDING,
LOWERING_GEAR,
}State_Type;
typedef enum Switch
{
on,
off//plane is on ground
}Switch_status;
typedef enum pilot_lever
{
Raising,
falling
}Pilot_lever;
typedef enum hydraulic_mechanism
{
working,
not_working
}Hydraulic_mechanism;
static volatile Switch_status squat_switch;
static volatile Switch_status limit_switch;
static volatile Pilot_lever pilot_lever;
static volatile Hydraulic_mechanism hydraulic_mechanism;
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_status[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}},
{"CheckBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
{"LoweringGear","Green","Down","Enabled",{"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\n");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch);
if(pilot_lever==Raising && squat_switch==on)
{
current_state=CHECK_BEFORE_TAKEOFF;
printf("current state:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is :%s\n", State_Machine[current_state].light);
}
else
{
GearDown();
}
}
//CheckingBeforeTakeOFF
void CheckingBeforeTakeOFF(void)
{
current_state=CHECK_BEFORE_TAKEOFF;
printf("Enter the status of pilot's lever and squat switch "
"and hydraulic mechanism:\n");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
if(pilot_lever==falling&&squat_switch==off)
{
GearDown();
}
else if(pilot_lever==Raising && squat_switch==on && hydraulic_mechanism==working)
{
current_state=RAISING_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_valve_status);
}
else if(pilot_lever==Raising && squat_switch==on && hydraulic_mechanism==not_working)
{
current_state=RAISING_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_valve_status);
printf("Status of gas pressurized Spring System:%s\n",
State_Machine[current_state].Gas_Pressurized_Spring_system_status);
}
}
//RaisingGear
void RaisingGear(void)
{
current_state=RAISING_GEAR;
printf("Enter the status of pilot's lever and limit switch:\n");
fflush(stdout);
scanf("%d %d",&pilot_lever,&limit_switch);
if(pilot_lever==falling && limit_switch==on)
{
current_state=CHECK_BEFORE_LANDING;
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(pilot_lever==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",&pilot_lever);
if(pilot_lever==falling)
{
current_state=CHECK_BEFORE_LANDING;
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_LANDING;
printf("Enter the status of pilot's lever and "
"hydraulic mechanism status:\n");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
if(pilot_lever==falling && hydraulic_mechanism==working)
{
current_state=LOWERING_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_valve_status);
}
else if(pilot_lever==falling && hydraulic_mechanism==not_working)
{
current_state=LOWERING_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_valve_status);
printf("Status of gas pressurized Spring System:%s\n",
State_Machine[current_state].Gas_Pressurized_Spring_system_status);
}
else if(pilot_lever==(Raising))
{
CheckBeforeLanding();
}
}
//LoweringGear.
void LoweringGear(void)
{
current_state=LOWERING_GEAR;
printf("Enter the status of pilot's lever and limit switch:\n");
fflush(stdout);
scanf("%d %d",&pilot_lever,&limit_switch);
if(pilot_lever==falling && limit_switch==on)
{
current_state=CHECK_BEFORE_TAKEOFF;
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
}
else if(pilot_lever==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);
}
if(limit_switch==off)
{
LoweringGear();
}
}
//Initiate_State_Machine
void Initiate_State_Machine()
{
current_state==GEAR_DOWN;
printf("The Finite State Machine Airplane states is Initialized and current the program "
"is in""GearDown State & Light is:%s\n",State_Machine[current_state].light);
}
Output:
The Finite State Machine Airplane states is Initialized and current the program is inGearDown State & Light is:Green Enter the status of pilot's lever and squat switch 0 0 current state:CheckingBeforeTakeOFF Light is :Green Enter the status of pilot's lever and squat switch and hydraulic mechanism: 0 0 Current State:RaisingGear Light is:Red Status of Direction valve:Up Enter the status of pilot's lever and limit switch: 1 0 Current State:CheckBeforeLanding Light is:Red Landing Gear Hydraulic Control:Enabled Enter the status of pilot's lever and hydraulic mechanism status: 1 0 Current State:LoweringGear Light is:Green Status of Direction valve:Down Enter the status of pilot's lever and limit switch: 0 1 Current State:GearDown Light is:Green Landing Gear Hydraulic Control:Enabled Enter the status of pilot's lever and limit switch: 1 0 Current State:CheckingBeforeTakeOFF Light is:Green