Challenge

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

AIM:- Implement the Code for controlling the retraction and extension of Airplane’s landing gear

GEAR_DOWN(0):

State Machine is initialized & Program is in Gear_Down State & Light_Status : Green

Enter the Pilot's Lever Position and Squat Switch Status:0 0

Current State:Checking Before Take Off


Light Status:Green

CHECKING_BEFORE_TAKING OFF(1):

Enter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:2 0 0

Wait for 2 secs

Current State: Raising Gear


Light Status:Red


Direction Value Status:Up

RISING_GEAR(2):

Enter the Limit Switch Status, Pilot's Lever Position :1 2

Wait for 1 sec

Current State: Gear Up


Light Status:Off


Hydraulic Control for Landing Gear Status:Disabled

GEAR_UP(3):

Enter the Pilot's Lever Position:1

Current State:Checking Before Landing


Light Status:Red


Hydraulic Control for Landing Gear Status:Enabled

CHECKING_BEFORE_LANDING(4):

Enter the Pilot's Lever Position and Status of Hydraulic Mechanism:3 1

Current State : Lowering Gear


Light Status:Green


Direction Valve Status:Down


Gas Pressurized Spring System Status:Enabled

LOWRING_GEAR(5):

Enter the Limit_Switch Status,Pilot_Lever Status ::1 0

Current State: Checking Before Take Off


Light Status:Green

CONDITIONS:-

PROGRAM:-

#include<stdlib.h>

typedef enum States

{

Gear_down,

Checking_before_Take_off,

Raising_Gear,

Gear_Up,

Checking_before_Landing,

Lowering_Gear

}State_Type;

typedef enum switches

{

Open,

Close

}Switch;

typedef enum pilot

{

Rising,

Falling,

Up,

Down,

}Pilot_Lever;

typedef enum Hydraulic

{

Working,

Not_Working

}Hydraulic_Mechanism;

static volatile Switch limit;

static volatile Switch squat;

static volatile Pilot_Lever a;

static volatile Hydraulic_Mechanism b;

State_Type current_state;

typedef struct

{

char* next_state;

char* light;

char* direction_valve;

char* hydraulic_control;

}position;

void gear_down();

void checking_before_take_off();

void raising_gear();

void gear_up();

void checking_before_landing();

void lowering_gear();

static

void(*position[])(void)={gear_down,

checking_before_take_off,

raising_gear,

gear_up,

checking_before_landing,

lowering_gear

};

static position state_machine[6]={{"GEAR DOWN","GREEN","DOWN","ENABLED"},

{"CHECKING BEFORE TAKEOFF","GREEN","DOWN","ENABLED"},

{"RAISING GEAR","RED","UP","ENABLED"},

{"GEAR UP","OFF","NULL","DISABLED"},

{"CHECKING BEFORE LANDING","RED","DOWN","ENABLED"},

{"LOWERING GEAR","GREEN","DOWN","ENABLED"}

};

int main()

{

current_state=Gear_down;

while(1)

{

position[current_state]();

}

}

void gear_down()

{

current_state=Gear_down;

scanf("%d %d",&a,&squat);

if((a==Rising)&&(squat==Open))

{

current_state=Checking_before_Take_off;

printf("Next state is %s\n",state_machine[current_state].next_state);

printf("Light is %s\n",state_machine[current_state].light);

printf("Direction valve is %s\n",state_machine[current_state].direction_valve);

printf("Hydraulic control is

%s\n",state_machine[current_state].hydraulic_control);

}

else

{

gear_down();

}}

void checking_before_take_off()

{

current_state=Checking_before_Take_off;

scanf("%d %d %d",&a,&squat,&b);

if((a==Falling)||(squat==Close))

{

current_state=Gear_down;

printf("Next state is %s\n",state_machine[current_state].next_state);

printf("Light is %s\n",state_machine[current_state].light);

printf("Direction valve is %s\n",state_machine[current_state].direction_valve);

printf("Hydraulic control is

%s\n",state_machine[current_state].hydraulic_control);

}

else if((a==Up)&&(b==Working))

{

current_state=Raising_Gear;

printf("Next state is %s\n",state_machine[current_state].next_state);

printf("Light is %s\n",state_machine[current_state].light);

printf("Direction valve is %s\n",state_machine[current_state].direction_valve);

printf("Hydraulic control is

%s\n",state_machine[current_state].hydraulic_control);

}

else

{

checking_before_take_off();

}

}

void raising_gear()

{

current_state=Raising_Gear;

scanf("%d %d",&a,&limit);

if(a==Falling)

{

current_state=Checking_before_Landing;

printf("Next state is %s\n",state_machine[current_state].next_state);

printf("Light is %s\n",state_machine[current_state].light);

printf("Direction valve is %s\n",state_machine[current_state].direction_valve);

printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control);

}

else if(limit==Close)

{

current_state=Gear_Up;

printf("Next state is %s\n",state_machine[current_state].next_state);

printf("Light is %s\n",state_machine[current_state].light);

printf("Direction valve is %s\n",state_machine[current_state].direction_valve);

printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control);

}

}

void gear_up()

{

current_state=Gear_Up;

scanf("%d",&a);

if(a==Falling)

{

current_state=Checking_before_Landing;

}

else

{

gear_up();

}

}

void checking_before_landing()

{

current_state=Checking_before_Landing;

scanf("%d %d",&a,&b);

if(a==Down||b==Not_Working)

{

current_state=Lowering_Gear;

}

else

{

checking_before_landing();

}

}

void lowering_gear()

{

current_state=Lowering_Gear;

scanf("%d %d",&limit,&a);

if(limit==Open)

{

current_state= Gear_down;

}

else if(a==Rising)

{

current_state=Checking_before_Take_off;

}

else

{

lowering_gear();

}

}

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.