Challenge

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

Live Batch 9

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

Overview

  • An airplane has three gears for landing such as nose gear, left gear and right gear
  • There is a hydraulic pump which is exerting pressure to the gears to bring it down or pull it up using a electrical driven pump
  • When the direction of the valve is down then it is landed or gear down position
  • Similarly when the direction of valve is up then it is in rising gear or taking off
  • When gear is up then light status is off
  • Gear is down then the light status is green
  • Gear is raising or lowering then the colour of light is red
  • A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear
  • So here mainly we are controlling the direction of valve and controlling the retraction and extension of airplane's landing gear
  • Every leg of the gear has one limit switch
  • Nose gear has one extra Squat switch to determine whether the airplane is in ground or not

Conditions

  • Following are the conditions for the code and State Flow Chart shows the finite states to implement and we are going to find retraction and extension of airplane,controlling the retraction and extension of Airplane’s landing gear can be implemented using Finite State Machine (FSM)
  • The table 1 below provides the states of switches and gear operation
  • Table2 provides the status of direction value and the corresponding states of landing gear
  • Table 3 shows the input for the direction valve and it provides the details whether the pilot lever is up or down or rising or falling along with the light
  • Table 4 shows the landing gear status and the light status accordingly
  • Figure 1 shows the different states involved in the program

Progam

a)Header file

#ifndef AIRPLANE_H_
#define AIRPLANE_H_
void Init_State_Machine(); //function declaration
void Gear_Down();
void Checking_Before_Takeoff();
void Raising_Gear();
void Gear_Up();
void Checking_Before_Landing();
void Lowering_Gear();

typedef enum State
{
GR_DWN,
CHK_BFR_TKFF,
RSING_GR,
GR_UP,
CHK_BFR_LND,
LWRNG_GR

}State_Type;
typedef enum Switch
{
Open,
Close

}Switch_Status;

typedef enum Pilot_Lever
{

Rising,
Falling,
UP,
DOWN

}Pilot_Lever_Status;

typedef enum Hydraulic_Mechanism
{
Working,
Malfunctioning

}Hydraulic_Mechanism_Status;

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 // declaration of structure using typedef

{
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] = //calling state table
{
{"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"}}

};


#endif /* AIRPLANE_H_ */

b)main.c

//main.c
#include
#include "airplane.h"

static void(*state_table[])(void) = {Gear_Down, Checking_Before_Takeoff,Raising_Gear,
Gear_Up, Checking_Before_Landing, Lowering_Gear};
//using state table the condition controlling the retraction and extension of airoplane's landing gear

int main()
{
Init_State_Machine(); //declare initial state machine
while(1) //while loop
{
state_table[current_state](); // current state is declare in the state table
}
}

c) Initial State

// Init_State_Machine

#include"airplane.h"

void Init_State_Machine() //initial state machine condition
{
current_state = GR_DWN; //current state is gear down
printf("\nState Machine is initialized & Program is in Gear_Down State & Light_Status: %s\n"
,State_Machine[current_state].light_status);
//display state machine is initialized and gear down state with status of light
}

d)Gear Down

//Gear_Down
#include"airplane.h"
#include

void Gear_Down(void) //gear down condition
{
current_state = GR_DWN;
printf("\n Enter 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();
}
}

e)Check before Takeoff

//Checking_Before_Takeoff
#include "airplane.h"
#include

void Checking_Before_Takeoff() //before take off condition
{
current_state = CHK_BFR_TKFF;
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)
//lever is up , switch is open and hydraulic mechanism is 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)
//pilot lever is up,switch is open and hydraulic mechanism is 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]);
}
}

f) Raising Gear

//Raising_Gear
#include"airplane.h"
#include

void Raising_Gear() // raising gear operation
{
current_state = RSING_GR;
printf("\nEnter the Limit Switch Status,Pilots Lever Status:");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
printf("\nWait for 1 sec\n"); //display wait for 1 sec
if(pilot_lever == Falling && limit_switch == Open) //if pilot lever is falling then limit switch is 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) //limit switch close then pilot lever is open

{
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();

}

}

g)Gear Up

//Gear_Up
#include"airplane.h"
#include

void Gear_Up() //gear up condition

{
current_state = GR_UP;
printf("\nEnter the Pilot's Lever Position:");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Falling) //if pilot lever is 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();

}
}

h)Check before Landing

//Checking_Before_Landing
#include "airplane.h"
#include
void Checking_Before_Landing() //checking before Landing condition
{
current_state = CHK_BFR_LND;
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)
//if pilot lever is down and hydraulic mechanism is 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)
//pilot lever is down then hydraulic mechanism is 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[hydraulic_mechanism]);

}
else if(pilot_lever == (UP || Rising || Falling))//if pilot lever is up,raising or falling

{
Checking_Before_Landing();
}
}

i)Lowering Gear

//Lowering_Gear
#include "airplane.h"
#include
void Lowering_Gear() //lowering gear condition
{
current_state = LWRNG_GR;
printf("\nEnter the Limit Switch Status,Pilots Lever Status:");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if(limit_switch == Close && pilot_lever == Rising ) //if limit switch is close and pilot lever is raising
{
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 && pilot_lever == DOWN) //if limit switch is open and pilot lever is down

{
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);

}
else
{
Lowering_Gear();
}

}

In this case

  • We can observe that the direction valve helps us to raise or lower the landing gear.
  • The direction valve is controlled by the software.
  • With the help of this software we control the hydraulic mechanism.
  • The hydraulic pump controls the raising or lowering of the landing gear.
  • The hydraulic mechanism helps us to land and take off of the airplane.

Figure shows the program and output obtained

  • Here we have 9 files which has one header file with function declarations(.h file) and eight .c files
  • Here figure 2-10 shows the program files and figure 11 shows the outcome obtained from the program

a)Header file

b) Main

c)Initializing state machine of all condition

d)Gear down

e)Checking before take off

f)Raising gear

g)Gear up

h)Check before landing

i)Lowering gear

j)Output

Logic and Comments

  • Our aim is to write an code using the concept of finite state machine by using an typedef and also an enum
  • Here in main.c file we are writing the syntax for function definition All this functions are defined inside the header file and are are declared in type def enum function
  • Initialization of state machineis also done
  • Type def is used because it can be changed for an existing variable and in case of enum for each and every variable the number will get automatically allocated
  • A direction valve is controlled in a way that allow the hydraulic pressure to either raise or lower the landing gear
  • If we enter the pilot lever status as 1 then the light status will turn to green as per the program , the other results are attached as screenshot

Result

  • Implemented the code for controlling the retraction and extraction of an airplane landing gear
  • In this project we get good understanding about finite state machine
  • FSM helps to achieve the control over the retraction and extension of airplane's landing gear
  • The switch states and gear states of airplane plays a major role in control of retraction and extension
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.