Challenge

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

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.

Click here for the attachment

#include <stdio.h>

#define AUTO 0 // Manual mode = 0, Auto mode = 1

#define LOOP 1

/* Function Prototypes */

void Init_State_Machine();

void Gear_Down(); // 1 1

void Checking_Before_Takeoff(); // 3 1 1

void Raising_Gear(); // 0 3

void Gear_Up(); // 0

void Checking_Before_Landing(); // 2 1

void Lowering_Gear(); // 1 2

/* Declaring and Defining enumerated data types */

enum State

{

GEAR_DOWN,

CHECKING_BEFORE_TAKEOFF,

RAISING_GEAR,

GEAR_UP,

CHECKING_BEFORE_LANDING,

LOWERING_GEAR

};

enum Switch

{

CLOSE = 0,

OPEN = 1

};

enum Pilot_Lever

{

FALLING = 0,

RAISING = 1,

DOWN = 2,

UP = 3

};

enum Hydraulic_Actuator

{

MALFUNCTION,

WORKING

};

/* Input for changing the state */

int Limit_Switch;

int Squat_Switch;

int Lever;

int Actuator;

int Current_State;

/* Declaring structure members for state table */

typedef struct

{

char* Current_Status;

char* Light_Status;

char* Direction_Valve_Status;

char* Actuator_Status;

}State_Table;

/* State Table Definition */

static volatile State_Table 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" }

};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* This function initialises the state machine's current state with GEAR_DOWN */

void Init_State_Machine()

{

Current_State = GEAR_DOWN ;

printf("\n State Machine is Initialized and Program is in Gear_Down State.\n") ;

}

/* This function is called when the current state is GEAR_DOWN */

void Gear_Down()

{

Current_State = GEAR_DOWN;

printf("\n0.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

#if AUTO == 0

printf("\n GD Enter the Pilot's Lever Position and Squat Switch Status :");

fflush(stdout);

scanf("%d %d",&Lever,&Squat_Switch);

#elif AUTO == 1

Lever = 1;

Squat_Switch = 1;

#endif

if(Lever == RAISING && Squat_Switch == OPEN) /* 1 1 */

{

Current_State = CHECKING_BEFORE_TAKEOFF;

printf("\n1.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

}

else

{

Gear_Down();

}

}

/* This function is called when the current state is CHECKING_BEFORE_TAKEOFF */

void Checking_Before_Takeoff()

{

Current_State = CHECKING_BEFORE_TAKEOFF;

#if AUTO == 0

printf("\n CBT Enter the Pilot's Lever Position, Squat Switch Status and Hydraculic mechanism Status: ");

fflush(stdout);

scanf("%d %d %d",&Lever, &Squat_Switch, &Actuator);

#elif AUTO == 1

Lever = 3;

Squat_Switch = 1;

Actuator = 1;

#endif

if(Lever == FALLING && Squat_Switch == CLOSE) /* 0 0 X*/

{

Gear_Down();

}

else if(Lever == UP && Squat_Switch == OPEN && Actuator == WORKING) /* 3 1 1 */

{

Current_State = RAISING_GEAR;

printf("\n2.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

printf("\n Direction Valve Status : %s\n",State_Machine[Current_State].Direction_Valve_Status);

}

else if(Lever == UP && Squat_Switch == OPEN && Actuator == MALFUNCTION) /* 3 1 0*/

{

Current_State = RAISING_GEAR;

printf("\n2.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

printf("\n Direction Valve Status : %s\n",State_Machine[Current_State].Direction_Valve_Status);

}

}

/* This function is called when the current state is RAISING_GEAR */

void Raising_Gear()

{

Current_State = RAISING_GEAR;

#if AUTO == 0

printf("\n RG Enter the Limit Switch and Pilot's Lever Status: ");

fflush(stdout);

scanf("%d %d",&Limit_Switch, &Lever);

#elif AUTO == 1

Limit_Switch = 0;

Lever = 3;

#endif

if((Limit_Switch == CLOSE) && (Lever == UP)) /* 0 3 */

{

Current_State = GEAR_UP;

printf("\n3.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

printf("\n Hydraculic control for landing gear Status : %s\n",State_Machine[Current_State].Actuator_Status);

}

else if((Limit_Switch == OPEN) && (Lever == FALLING)) /* 1 0*/

{

Current_State = CHECKING_BEFORE_LANDING;

printf("\n3.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

printf("\n Hydraculic control for landing gear Status : %s\n",State_Machine[Current_State].Actuator_Status);

}

else

{

Raising_Gear();

}

}

/* This function is called when the current state is GEAR_UP */

void Gear_Up()

{

Current_State = GEAR_UP;

#if AUTO == 0

printf("\n GU Enter the Pilot's Lever Position :");

fflush(stdout);

scanf("%d",&Lever);

#elif AUTO == 1

Lever = 0;

#endif

if(Lever == FALLING) /* 0 */

{

Current_State = CHECKING_BEFORE_LANDING;

printf("\n4.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

printf("\n Hydraculic control for landing gear Status : %s\n",State_Machine[Current_State].Actuator_Status);

}

else

{

Gear_Up();

}

}

/* This function is called when the current state is CHECKING_BEFORE_LANDING */

void Checking_Before_Landing()

{

Current_State = CHECKING_BEFORE_LANDING;

#if AUTO == 0

printf("\n CBL Enter the Pilot's Lever Position and Hydraculic mechanism Status: ");

fflush(stdout);

scanf("%d %d",&Lever,&Actuator);

#elif AUTO == 1

Lever = 2;

Actuator = 1;

#endif

if(Lever == ( UP || RAISING ||FALLING )) /* (3 or 1 or 0) X */

{

Checking_Before_Landing();

}

else if(Lever == DOWN && Actuator == WORKING) /* 2 1 */

{

Current_State = LOWERING_GEAR;

printf("\n5.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

printf("\n Direction Valve Status : %s\n",State_Machine[Current_State].Direction_Valve_Status);

}

else if(Lever == DOWN && Actuator == MALFUNCTION) /* 2 0 */

{

Current_State = LOWERING_GEAR;

printf("\n5.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

printf("\n Direction Valve Status : %s\n",State_Machine[Current_State].Direction_Valve_Status);

}

}

/* This function is called when the current state is LOWERING_GEAR */

void Lowering_Gear()

{

Current_State = LOWERING_GEAR;

#if AUTO == 0

printf("\n LG Enter the Limit Switch and Pilot's Lever Status: ");

fflush(stdout);

scanf("%d %d",&Limit_Switch,&Lever);

#elif AUTO == 1

Limit_Switch = 1;

Lever = 2;

#endif

if((Limit_Switch == CLOSE) && (Lever == RAISING)) /* 0 1 */

{

Current_State = CHECKING_BEFORE_TAKEOFF;

printf("\n6.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

}

else if((Limit_Switch == OPEN) && (Lever == DOWN)) /* 1 2 */

{

Current_State = GEAR_DOWN;

printf("\n6.Current State : %s\n",State_Machine[Current_State].Current_Status);

printf("\n Light Status : %s\n",State_Machine[Current_State].Light_Status);

printf("\n Hydraculic control for landing gear Status : %s\n\n\n",State_Machine[Current_State].Actuator_Status);

}

else

{

Lowering_Gear();

}

}

/* state_table[] is a pointer to these functions */

static void (*state_table[])(void) = {Gear_Down, Checking_Before_Takeoff, Raising_Gear, Gear_Up, Checking_Before_Landing, Lowering_Gear};

int main(void) {

Init_State_Machine(); /* Initializing the State_Machine */

#if AUTO == 0

while(1)

{

state_table[Current_State](); /* For each value of Current_State respective function

* in the array index is invoked */

}

#elif AUTO == 1

for(int i = 0; i< (LOOP*6); i++)

{

state_table[Current_State]();

}

#endif

return 0;

}

OUTPUT

State Machine is Initialized and Program is in Gear_Down State.

0.Current State : Gear Down

Light Status : Green

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

0.Current State : Gear Down

Light Status : Green

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

0.Current State : Gear Down

Light Status : Green

GD Enter the Pilot's Lever Position and Squat Switch Status :1 2

1.Current State : Checking before Takeoff

Light Status : Green

CBT Enter the Pilot's Lever Position, Squat Switch Status and Hydraculic mechanism Status: 1

3 1

CBT Enter the Pilot's Lever Position, Squat Switch Status and Hydraculic mechanism Status: 0 3

CBT Enter the Pilot's Lever Position, Squat Switch Status and Hydraculic mechanism Status: 0 2

3 1

CBT Enter the Pilot's Lever Position, Squat Switch Status and Hydraculic mechanism Status: Killed

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.