Challenge

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

#include

typedef enum State
{
GEAR_DOWN,
TAKEOFF_CHECK,
RAISING_GEAR,
UPSHIFT,
LANDING_CHECK,
DOWNSHIFT
}State_Conditions;

typedef enum Switch
{
Open,
Close
}Switch_Conditions;

typedef enum Pilot_Lever
{
Rising,
Falling,
UP,
DOWN
}Pilot_Lever_Condition;

typedef enum Hydraulics
{
Working,
Malfunctioning
}Hydraulics_Condition;

static volatile Switch_Conditions squat_switch;
static volatile Switch_Conditions limit_switch;
static volatile Pilot_Lever_Condition pilot_lever;
static volatile Hydraulics_Condition hydraulics;
State_Conditions current_state;
typedef struct
{
char* current_state_indicator;
char* light_indicator;
char* direction_valve_indicator;
char* hydraulic_pump_control_indicator;
char* gas_pressure_spring_indicator[2];
}State_Indicators;

State_Indicators Finite_State_Machine[6]={
{"GearDown","Green","Down","Enabled",0,0},
{"Checking Before Take Off","Green","Down","Enabled",0,0},
{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"Gear Up","Off","Null","Disabled",0,0},
{"Checking Before Landing","Red","Down","Enabled",0,0},
{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};

void initialiseStateMachine();
void gearUp();
void raiseGear();
void checkBeforeLanding();
void checkBeforeTakeoff();
void loweringGear();
void gearDown();

static void (*state_table[])(void) = {gearDown, checkBeforeTakeoff, raiseGear, gearUp, checkBeforeLanding, loweringGear};

int main(){
initialiseStateMachine();
while(1)
{
state_table[current_state]();
}
return 0;
}

void gearDown()
{
current_state = GEAR_DOWN;
printf("\nCurrent State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Enter the pilot's Lever Position, Squat Switch Status ");
fflush(stdout);
scanf("%d %d",&pilot_lever, &squat_switch);
if(pilot_lever == Rising && squat_switch == Open)
{
current_state=TAKEOFF_CHECK;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\nLight State: %s",Finite_State_Machine[current_state].light_indicator);
}
else
{
gearDown();
}
}

void loweringGear()
{
current_state = DOWNSHIFT;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Enter the limit Switch Status,pilot's lever Position");
fflush(stdout);
scanf("%d%d",&pilot_lever, &limit_switch);
if(limit_switch == Close && pilot_lever == Rising )
{
current_state=TAKEOFF_CHECK;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Light Status: %s",Finite_State_Machine[current_state].light_indicator);
}
if(limit_switch == Open && pilot_lever ==DOWN)
{
current_state = GEAR_DOWN;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Light Status: %s",Finite_State_Machine[current_state].light_indicator);
printf("\n Hydraulic Control for Landing Gear Status:%s \n",Finite_State_Machine[current_state].hydraulic_pump_control_indicator);
}
else
{
loweringGear();
}
}

void checkBeforeTakeoff()
{
current_state = TAKEOFF_CHECK;
printf("\n Current State:%s \n",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Enter the pilot's lever Position, Squat Switch Status and Hydraulic Mechanism Status:");
fflush(stdout);
scanf("%d %d %d",&pilot_lever, &squat_switch, &hydraulics);
if(pilot_lever == Falling ||squat_switch == Close)
{
gearDown();
}
else if(pilot_lever==UP && squat_switch==Open && hydraulics==Working)
{
current_state=RAISING_GEAR;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Light Status: %s",Finite_State_Machine[current_state].light_indicator);
printf("\n Direction valve Status:%s",Finite_State_Machine[current_state].direction_valve_indicator);
}
else if (pilot_lever== UP && squat_switch == Open && hydraulics ==Malfunctioning)
{printf("\n Light Status:%s \n", Finite_State_Machine[current_state].light_indicator);
printf("\n Direction Valve Status:%s",Finite_State_Machine[current_state].direction_valve_indicator);
printf("\n Gas Pressurized Spring System Status:%s",Finite_State_Machine[current_state].gas_pressure_spring_indicator[hydraulics]);
}
}

void checkBeforeLanding()
{
current_state = LANDING_CHECK;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Enter the Pilot's Lever Position and HydraulicMechanism Status:");

fflush(stdout);
scanf("%d %d",&pilot_lever, &hydraulics);
if(pilot_lever == DOWN && hydraulics == Working)
{
current_state = DOWNSHIFT;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Light State: %s",Finite_State_Machine[current_state].light_indicator);
printf("\n Direction Valve Status:%s",Finite_State_Machine[current_state].direction_valve_indicator);
}
else if(pilot_lever== DOWN && hydraulics == Malfunctioning)
{
current_state = DOWNSHIFT;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Light Status: %s",Finite_State_Machine[current_state].light_indicator);
printf("\n Direction Valve Status:%s",Finite_State_Machine[current_state].direction_valve_indicator);
printf("\n Gas Pressurized Spring System Status:%s",Finite_State_Machine[current_state].gas_pressure_spring_indicator[hydraulics]);
}
if(pilot_lever == (UP||Rising||Falling))
{
checkBeforeLanding();
}
}

void raiseGear()
{
current_state = RAISING_GEAR;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Enter the Limit Switch Status,Pilots Lever Status:");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);

if(pilot_lever == Falling && limit_switch == Open)
{
current_state=LANDING_CHECK;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Light State: %s",Finite_State_Machine[current_state].light_indicator);
printf("\n Hydraulic Control for Landing Gear State:%s",Finite_State_Machine[current_state].hydraulic_pump_control_indicator);
}
else if(limit_switch == Close && pilot_lever == UP)
{
current_state=UPSHIFT;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Light State: %s",Finite_State_Machine[current_state].light_indicator);
printf("\n Hydraulic Control for landing Gear Status:%s",Finite_State_Machine[current_state].hydraulic_pump_control_indicator);
}
else
{
raiseGear();
}
}

void gearUp()
{
current_state = UPSHIFT;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Enter the Pilot's lever Position ");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Falling)
{
current_state=LANDING_CHECK;
printf("\n Current State:%s",Finite_State_Machine[current_state].current_state_indicator);
printf("\n Light Status: %s",Finite_State_Machine[current_state].light_indicator);
printf("\n Hydraulic Control for Landing Gear Status:%s",Finite_State_Machine[current_state].hydraulic_pump_control_indicator);
}
else
{
gearUp();
}
}

void initialiseStateMachine()
{
current_state = GEAR_DOWN;
printf("\n State Machine is initialized & Program is in Gear_Down_state & Light_Status:%s",Finite_State_Machine[current_state].light_indicator);
}

 

output

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.