Challenge

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

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

OFFLINE

#include <stdio.h> //Preprocessor
#include <stdlib.h> //Standard Library

//Functions Used in our projects
void Gear_Down();
void Checking_Before_Takeoff();
void Rising_Gear();
void Gear_Up();
void Checking_Before_Landing();
void Lowering_Gear();

typedef enum State //enum is used to giving subsequent value for variables
{
gear_down,
checking_before_take_off,
rising_gear,
gear_up,
checking_before_landing,
lowering_gear
}State_Type;

typedef enum Switch
{
Open, //Open =0 ,Close =1;
Close // Plane is in ground
}Switch_Status;

typedef enum Light
{
Off, //Status of the Light in different States
Red,
Green
}Light_Status;

typedef enum Pilot_Lever //by using enum
{
Rising, // rising = 0;
Up, // up =1;
Falling, // falling =2;
Down // down =3;
}Pilot_Lever_Status;

typedef enum Hydraulic_Pump
{
Working, // working =0;
Malfunctioning // malfunctioning =1;
}Hydraulic_Pump_Status;

// input used in order to change the state
static volatile Switch_Status squat_switch;
static volatile Switch_Status limit_switch;
static volatile Pilot_Lever_Status pilot_lever;
static volatile Pilot_Lever_Status hydraulic_pump;

State_Type current_state;

typedef struct // Structure is used to have different types
{
char* current_state_type; // Output which is we waant to visualize are given
char* light_status;
char* direction_valve_status;
char* hydraulic_pump_status;
}State_Table;

//state table required for the system data
State_Table State_Plane[6]={
{"GearDown","Green","Down","Enabled"},
{"Checking Before Take Off","Green","Down","Enabled"},
{"Raising Gear","Red","Up","Enabled"},
{"Gear Up","Off","Null","Disabled"},
{"Checking Before Landing","Red","Down","Enabled"},
{"Lowering Gear","Green","Down","Enabled"}};

void Gear_Down(void)// Called function
{
printf("\n Current state is Gear Down \n");// Showing the current state of the plane
printf("\n Enter the pilot's Lever Position, Squat Switch Status:\n");// entering the input
fflush(stdout);
scanf("%d%d",&pilot_lever, &squat_switch);//getting the pilot lever position and squat switch
if(pilot_lever == Rising && squat_switch == Open) // checking the condition is true
{
printf("\n Current State :%s\n",State_Plane[current_state].current_state_type);
printf("\n Light State :%s\n",State_Plane[current_state].light_status);
printf("\n Direction Valve Status :%s\n",State_Plane[current_state].direction_valve_status);
printf("\n Hydraulic Control Status :%s\n",State_Plane[current_state].hydraulic_pump_status);
current_state = checking_before_take_off; // condition is satifices it moves to the next state
}
else // Condition fails it will move to gear down state
{
printf("\n Check the Pilot Lever and Squat Switch ");
Gear_Down();
}
}

void Checking_Before_Takeoff()
{
printf("\nCurrent state is Checking_Before_Takeoff \n ");
printf("\n Enter the pilot's lever Position, Squat Switch Status :\n");
fflush(stdout);
scanf("%d%d",&pilot_lever, &squat_switch);
if(pilot_lever == Up || squat_switch == Open)
{
printf("\n Current State :%s\n",State_Plane[current_state].current_state_type);
printf("\n Light State :%s\n",State_Plane[current_state].light_status);
printf("\n Direction Valve Status :%s\n",State_Plane[current_state].direction_valve_status);
printf("\n Hydraulic Control Status :%s\n",State_Plane[current_state].hydraulic_pump_status);
current_state = rising_gear;
}
else
{
printf("\n Check the Pilot Lever and Squat Switch ");
Checking_Before_Takeoff();
}
}
void Rising_Gear()
{
printf("\n Current state is Rising Gear \n");
printf("\n Enter the Limit Switch Status,Pilots Lever Status:\n");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if(pilot_lever == Up && limit_switch == Close)
{
printf("\n Current State :%s\n",State_Plane[current_state].current_state_type);
printf("\n Light State :%s\n",State_Plane[current_state].light_status);
printf("\n Direction Valve Status :%s\n",State_Plane[current_state].direction_valve_status);
printf("\n Hydraulic Control Status :%s\n",State_Plane[current_state].hydraulic_pump_status);
current_state = gear_up;
}
else if(limit_switch == Open && pilot_lever == Falling)
{
current_state = checking_before_landing;
printf("\n Current State :%s\n",State_Plane[current_state].current_state_type);
printf("\n Light State :%s\n",State_Plane[current_state].light_status);
printf("\n Direction Valve Status :%s\n",State_Plane[current_state].direction_valve_status);
printf("\n Hydraulic Control Status :%s\n",State_Plane[current_state].hydraulic_pump_status);
current_state=rising_gear;
}
else
{
Rising_Gear();
}
}
void Gear_Up()
{
printf("\n Current state is Gear Up \n");
printf("\n Enter the Pilot's lever Position and Limit switch:\n");
fflush(stdout);
scanf("%d%d",&pilot_lever,&limit_switch);
if(pilot_lever == Falling && limit_switch == Close)

{
printf("\n Current State :%s\n",State_Plane[current_state].current_state_type);
printf("\n Light State :%s\n",State_Plane[current_state].light_status);
printf("\n Direction Valve Status :%s\n",State_Plane[current_state].direction_valve_status);
printf("\n Hydraulic Control Status :%s\n",State_Plane[current_state].hydraulic_pump_status);
current_state =checking_before_landing;
}
else
{
printf("\n Check the Pilot Lever");
current_state = gear_up;
}
}
void Checking_Before_Landing()
{
printf("\n Current state is Checking Before Landing \n");
printf("\n Enter the Pilot's Lever Position:\n");

fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Down)
{
printf("\n Current State :%s\n",State_Plane[current_state].current_state_type);
printf("\n Light State :%s\n",State_Plane[current_state].light_status);
printf("\n Direction Valve Status :%s\n",State_Plane[current_state].direction_valve_status);
printf("\n Hydraulic Control Status :%s\n",State_Plane[current_state].hydraulic_pump_status);
current_state = lowering_gear;
}
else if(pilot_lever== Down && hydraulic_pump == Malfunctioning)
{
current_state = lowering_gear;
printf("\n Current State :%s\n",State_Plane[current_state].current_state_type);
printf("\n Light State :%s\n",State_Plane[current_state].light_status);
printf("\n Direction Valve Status :%s\n",State_Plane[current_state].direction_valve_status);
printf("\n Hydraulic Control Status :%s\n",State_Plane[current_state].hydraulic_pump_status);
}
else
{
current_state= checking_before_landing;
}
}

void Lowering_Gear()
{
current_state = lowering_gear;
printf("\n Current state is lowering_gear \n");
printf("\n Enter the limit Switch Status,pilot's lever Position:\n");
scanf("%d%d",&pilot_lever, &limit_switch);
if( pilot_lever == Down && limit_switch == Open )
{
printf("\n Current State :%s\n",State_Plane[current_state].current_state_type);
printf("\n Light State :%s\n",State_Plane[current_state].light_status);
printf("\n Direction Valve Status :%s\n",State_Plane[current_state].direction_valve_status);
printf("\n Hydraulic Control Status :%s\n",State_Plane[current_state].hydraulic_pump_status);
current_state = gear_down ;
}
else if(limit_switch == Open && pilot_lever == Rising)
{
current_state = checking_before_landing;
printf("\n Current State :%s\n",State_Plane[current_state].current_state_type);
printf("\n Light State :%s\n",State_Plane[current_state].light_status);
printf("\n Direction Valve Status :%s\n",State_Plane[current_state].direction_valve_status);
printf("\n Hydraulic Control Status :%s\n",State_Plane[current_state].hydraulic_pump_status);
current_state=lowering_gear;
}
else
{
current_state = lowering_gear;
}
}

void Init_State_Plane() // Declaring the
{
current_state = gear_down;
printf("\n The Flight is initialized & Program is in Gear_Down_state & Light_Status:%s\n",State_Plane[current_state].light_status);
}

// Static which holds the current value
static void (*state_row[])(void) = {Gear_Down,Checking_Before_Takeoff, Rising_Gear, Gear_Up, Checking_Before_Landing, Lowering_Gear};

int main() // Main function
{
printf("Lever positions:: \n\n Rising =0 \n Up =1\n Falling =2 \n Down =3 \n Squat switch is always '1'(Open) Except gear landing \n Limit switch is '1'(close) only for gear rising and gear up condition ");
Init_State_Plane(); //current state update
while(1)
{
state_row[current_state]();//switching to the next state through
}
return 0;
}

OUTPUT :

Lever positions::

Rising =0
Up =1
Falling =2
Down =3
Squat switch is always '1'(Open) Except gear landing
Limit switch is '1'(close) only for gear rising and gear up condition
The Flight is initialized & Program is in Gear_Down_state & Light_Status:Green

Current state is Gear Down

Enter the pilot's Lever Position, Squat Switch Status:
0
0

Current State :GearDown

Light State :Green

Direction Valve Status :Down

Hydraulic Control Status :Enabled

Current state is Checking_Before_Takeoff

Enter the pilot's lever Position, Squat Switch Status :
1
0

Current State :Checking Before Take Off

Light State :Green

Direction Valve Status :Down

Hydraulic Control Status :Enabled

Current state is Rising Gear

Enter the Limit Switch Status,Pilots Lever Status:
1
1

Current State :Raising Gear

Light State :Red

Direction Valve Status :Up

Hydraulic Control Status :Enabled

Current state is Gear Up

Enter the Pilot's lever Position and Limit switch:
2
1

Current State :Gear Up

Light State :Off

Direction Valve Status :Null

Hydraulic Control Status :Disabled

Current state is Checking Before Landing

Enter the Pilot's Lever Position:
3

Current State :Checking Before Landing

Light State :Red

Direction Valve Status :Down

Hydraulic Control Status :Enabled

Current state is lowering_gear

Enter the limit Switch Status,pilot's lever Position:
3
0

Current State :Lowering Gear

Light State :Green

Direction Valve Status :Down

Hydraulic Control Status :Enabled

Current state is Gear Down

Enter the pilot's Lever Position, Squat Switch Status:

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.