Challenge

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

Overview of the Project:

In this project, controlling the retraction and extension of the Airplane’s landing gear can be implemented using a Finite State Machine (FSM). FSM is the most efficient algorithm which is a mathematical model of computation.

Goals

  • Controlling the direction of the Valve.
  • Controlling the retraction and extension of the Airplane’s landing gear.

Key Highlights of the Project:

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:

Implementing the control for the retraction and extension of the Airplane’s landing gear using the Finite state machine with the knowledge of various states of switch and gear.

Expected Outcomes:

The student will be getting the Knowledge of the Finite State Machine algorithm which is used to achieve control over the retraction and extension of the Airplane’s landing gear using the switch and gear states of the Airplane.

PROGRAM CODE

#include<stdio.h>//Header file

#include<States.h>//Created header file

 

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

//Variables

 

int main()

{

Init_State_Machine();//Function calling

while(1)//Loop

{

state_table[current_state]();

}

return 0;

}

 

/*

 * States.h


 */

 

#ifndef STATES_H_

#define STATES_H_

 

#include<stdio.h>

 

void Init_State_Machine();

 

void Gear_Down();

 

void Checking_Before_Takeoff ();

 

void Raising_Gear();

 

void Gear_Up();

 

void Checking_Before_Landing();

 

void Lowering_Gear();

 

typedef enum State

 

{

//States

GR_DWN,

 

CHK_BFR_TKFF,

 

RSING_GR,

 

GR_UP,

 

CHK_BFR_LND,

 

LWRNG_GR

 

}State_Type;

 

typedef enum Switch {

 

Open,

 

Close//Plane is in ground

 

}Switch_Status;

typedef enum Pilot_Lever

{

Rising,

 

Falling,

 

UP,

 

DOWN

 

}Pilot_Lever_Status;

 

typedef enum Hydraulic_Mechanism

 

{

 

Working,

 

Malfunctioning

}Hydraulic_Mechanism_Status;

 

/* -input for changing the State----- */

 

static volatile Switch_Status squat_switch;

static volatile Switch_Status limit_switch;

static volatile Pilot_Lever_Status pilot_lever;

static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;

 

State_Type current_state;

 

typedef struct

 

{

 

char* current_state_indication;

 

char* light_status;

 

char* direction_valve_status;

 

char* hydraulic_pump_control_status;

 

//char* gas_pressurized_spring_status[2];

 

}State_Table;

 

static State_Table State_Machine [6] = {

 

{"Gear Down", "Green", "Down", "Enabled" },//{0,0}

 

{"Checking Before Take Off", "Green", "Down", "Enabled"},

 

{"Raising Gear", "Red", "Up", "Enabled"},

 

{"Gear Up", "Off", "0","Disabled"},

 

{"Checking Before Landing", "Red", "Down", "Enabled"},

 

{"Lowering Gear", "Green", "Down", "Enabled"}

 

};

 

 

#endif /* STATES_H_ */

 

/*

 * Gear_Down.c


 */

 

 

#include<States.h>

void Gear_Down(void)

 

{

current_state = GR_DWN;

printf("\nCurrent State: %s\n", State_Machine [current_state]. current_state_indication);

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

fflush(stdout);

 

scanf("%d %d", &pilot_lever, &squat_switch);

 

if(pilot_lever == Rising && squat_switch == Open)

 

{

 

current_state = CHK_BFR_TKFF;

 

printf("\nCurrent State: %s\n", State_Machine [current_state]. current_state_indication);

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

 

}

 

else

 

{

 

Gear_Down();

}

 

}

 

/*

 * Lowering_Gear.c


 */

#include "States.h"

 

void Lowering_Gear(){

//State

current_state = LWRNG_GR;

 

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);

printf("\nEnter the Limit Switch Status, Pilots Leaver Status:");

 

fflush(stdout);

 

scanf("%d %d",&limit_switch,&pilot_lever);//taking i/p from the user

 

if(pilot_lever == Rising)

{

current_state= CHK_BFR_TKFF;

 

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);

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

 

}

 

if(limit_switch == Open)

{

current_state= GR_DWN;

 

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);

 

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

 

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

}

 

if(limit_switch == Close)

{

Lowering_Gear();

}}

 

/*

 * Init_State_Machine.c


 */

#include "States.h"

 

void Init_State_Machine()//func

{

//System Initialized and its in State A

current_state = GR_DWN;

 

printf("\nState Machine is initialized & Program is in Gear_Down State & Light Status",State_Machine [current_state].light_status);

 

 

}

 

/*

 * Checking_Before_Takeoff.c

 */

#include "States.h"

 

void Checking_Before_Takeoff()//func

{

current_state = CHK_BFR_TKFF;

printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);

printf("\nEnter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:");

fflush(stdout);

scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);

printf("\nWait for 2 secs\n");

if(pilot_lever == Falling || squat_switch == Close)

{

Gear_Down();

}

 

else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)

{

current_state = RSING_GR;

printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);

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

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

}

 

else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Malfunctioning)

{

current_state = RSING_GR;

printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);

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

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

//printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);

}

}

 

/*

 * Gear_Up.c

 */

#include "States.h"

 

void Gear_Up()//func

{

current_state = GR_UP;

 

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);

printf("\nEnter the Pilot's Lever Position:");

 

fflush(stdout);

 

scanf("%d",&pilot_lever);

 

if(pilot_lever == Falling)

{

current_state = CHK_BFR_LND;

 

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);

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

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

 

}

 

else

{

Gear_Up();

}

}

 

/*

 * Raising_Gear.c


 */

#include "States.h"

 

void Raising_Gear()//func

{

current_state = RSING_GR;

printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);

printf("\nEnter the Limit Switch Status,Pilots Leaver Status:");

fflush(stdout);

scanf("%d %d",&limit_switch,&pilot_lever);

printf("\nWait for 1 sec\n");

if(pilot_lever == Falling && limit_switch == Open)

{

current_state = CHK_BFR_LND;

printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);

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

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

 

}

else if(limit_switch == Close && pilot_lever == UP)

{

current_state = GR_UP;

printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);

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

printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

}

 

else

{

Raising_Gear();

}

}

 

/*

 * Checking_Before_Landing.c


 */

#include "States.h"

 

void Checking_Before_Landing()//func

 

{

 

current_state = CHK_BFR_LND;

 

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);

printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:");

fflush(stdout);

 

scanf("%d %d",&pilot_lever,&hydraulic_mechanism);

 

if(pilot_lever == DOWN && hydraulic_mechanism == Working)

{

current_state = LWRNG_GR;

printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);

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

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

 

}

 

else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)

{

current_state=LWRNG_GR;

printf("\nCurrent State: %s\n", State_Machine [current_state].current_state_indication);

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

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

//printf("Gas Pressurized Spring System Status:%s\n", State_Machine[current_state].gas_pressurized_spring_status);

}

 

if(pilot_lever == (UP || Rising || Falling))

{

Checking_Before_Landing();

}}

OUTPUT

State Machine is initialized & Program is in Gear_Down State & Light Status 
Current State: Gear Down 

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

Current State: Checking Before Take Off 
Light Status: Green 

Current State: Checking Before Take Off 

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 Valve Status: Up 

Current State : Raising Gear 

Enter the Limit Switch Status, Pilots Leaver Status: 1 2 

Wait for 1 sec 

Current State : Gear Up 
Light Status: Off 
Hydraulic Control for Landing Gear Status: Disabled 

Current State: Gear Up 

Enter the Pilot's Lever Position: 1 

Current State: Checking Before Landing 
Light Status: Red 
Hydraulic Control for Landing Gear Status: Enabled

Current State: Checking Before Landing 

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

Current State: Lowering Gear 
Light Status: Green 
Direction Valve Status: Down 

Current State: Lowering Gear 

Enter the Limit Switch Status, Pilots Leaver Status: 0 1 

Current State: Gear Down 
Light Status: Green 
Hydraulic Control for Landing Gear Status: Enabled 

Current State: Gear Down 

Enter the Pilot's Lever Position and 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.