Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Project :- Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Answer :-
Objective:
- Controlling the direction of valve.
- Controlling the retraction and extension of airplane’s landing gear.
Principle:
- The airplane has three gears for landing such as nose gear, left gear and right gear.
- There is a hydraulic pump which is exerting pressure tothe gears to bring it down or pull it up using 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.
Process:-

- Gear down
- Checking before take off
- Raising gear
- Gear up
- Checking before landing
- Lowering gear
| State Type | Switch Status | Pilot Lever Status | Hydraulic Mechanics Status |
| GR_DWN | Open | Rising | Working |
| CHK_BFR_TKFF | Close | Falling | Malfunctioning |
| RSING_GR | Up | ||
| GR_UP | Down | ||
| CHK_BFR_LND | |||
| LWRNG_GR |
Code :-
Main.c :-
#include //PREPROCESSOR//
#include "State.h" //HEADER FILE INCLUDING//
static void (*state_table[])(void) = {gear_down, checking_before_takeoff, raising_gear,
gear_up, checking_before_landing, lowering_gear}; //DECLARING VARIABLES TO STATE TABLE//
int main() //MAIN FUNCTION//
{
init_state_machine(); //INITIALIZE STATE MACHINE//
while(1) //WHILE LOOP//
{
state_table[current_state](); //CALLING STATE TABLE//
}
}

State.h :-
#ifndef STATE_H_ //INCLUDING HEADER FILE//
#define STATE_H_
void init_state_machine(); //FUNCTION DECLARING INITIAL STATE MACHINE//
void gear_down(); //FUNCTION DECLARING GEAR DOWN//
void checking_before_takeoff(); //FUNCTION DECLARING CHECKING BEFORE TAKE OFF//
void raising_gear(); //FUNCTION DECLARING RISING GEAR//
void gear_up(); //FUNCTION DECLARING GEAR UP//
void checking_before_landing(); //FUNCTION DECLARING CHECKING BEFORE LANDING//
void lowering_gear(); //FUNCTION DECLARING LOWERING GEAR//
typedef enum state //TYPEDEF ENUM FUNCTION TO DEFINE STATE TYPE//
{
gr_dwn,
chk_bfr_tkof,
rsing_gr,
gr_up,
chk_bfr_lnd,
lwrng_gr
}state_type;
typedef enum Switch //TYPEDEF ENUM FUNCTION TO DEFINE SWITCH//
{
open,
close
}Switch_status;
typedef enum pilot_lever //TYPEDEF ENUM FUNCTION TO DEFINE PILOT LEVER STATUS//
{
rising,
falling,
up,
down
}pilot_lever_status;
typedef enum hydraulic_mechanism //TYPEDEF ENUM FUNCTION TO DEFINE HYDRAULIC MECHANISM STATUS//
{
working,
malfunctioning
}hydraulic_mechanism_status;
static volatile Switch_status squat_switch; //INPUT VARIABLE FOR CHANGING THE STATES//
static volatile Switch_status limit_switch; //INPUT VARIABLE FOR CHANGING THE STATES//
static volatile pilot_lever_status pilot_lever; //INPUT VARIABLE FOR CHANGING THE STATES//
static volatile hydraulic_mechanism_status hydraulic_mechanism; //INPUT VARIABLE FOR CHANGING THE STATES//
state_type current_state; //DEFINING CURRENT STATE AS STATE TYPE//
typedef struct //DEFINING STATE TABLE VARIABLES AS TYPEDEF STRUCTURE WITH CHARACTER DATATYPE//
{
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] = {
{"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"}}
}; //STATE TABLE ARRAY DECLARATION//
#endif /* STATES_H_ */ //END OF HEADER FILE//

Init State Machine.c :-
#include "State.h" //INCLUDING HEADER FILE//
void init_state_machine() //FUNCTION INITIAL STATE MACHINE CALLED//
{
current_state = gr_dwn; //ASSIGNING CURRENT STATE TO LOWERING GEAR//
printf("\n state machine is initialized & program is in gear down state & light status:%s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
}

Gear Down.c :-
#include "State.h" //INCLUDING HEADER FILE//
#include //PREPROCESSOR//
void gear_down(void) //FUNCTION GEAR DOWN CALLED//
{
current_state=gr_dwn; //ASSIGNING CURRENT STATE TO GEAR DOWN//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nenter the pilot lever position & squat switch status:"); //PRINT THE MESSAGE//
fflush(stdout); //CLEAR CACHE MEMORY//
scanf("%d %d",&pilot_lever,&squat_switch); //READS AND STORES THE DATA//
if(pilot_lever==rising && squat_switch==open) //IF CONDITION TO CHECK THE CONDITIONS//
{
current_state = chk_bfr_tkof; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO CHECK BEFORE TAKEOFF//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
}
else //IF CONDITIONS ARE NOT SATISFIED GO TO GEAR DOWN FUNCTION//
{
gear_down(); //REPEAT//
}
}

Checking Before Takeoff.c :-
#include "State.h" //INCLUDING HEADER FILE//
#include //PREPROCESSOR//
void checking_before_takeoff() //FUNCTION CHECKING BEFORE LANDING CALLED//
{
current_state=chk_bfr_tkof; //ASSIGNING CURRENT STATE TO CHECK BEFORE TAKEOFF//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nenter the pilot lever position,squat switch status & status of hydraulic mechanism:"); //PRINT THE MESSAGE//
fflush(stdout); //CLEAR CACHE MEMORY//
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism); //READS AND STORES THE DATA//
printf("\nwait for 2 secs\n"); //PRINT THE MESSAGE//
if(pilot_lever==falling || squat_switch==close) //IF CONDITION TO CHECK THE CONDITIONS//
{
gear_down(); //IF CONDITION IS TRUE GO TO GEAR DOWN FUNCTION//
}
else if(pilot_lever==up && squat_switch==open && hydraulic_mechanism==working) //NESTED IF CONDITION TO CHECK OTHER CONDITION//
{
current_state = rsing_gr; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO RISING GEAR//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
printf("direction valve status:%s\n",state_machine[current_state].direction_valve_status); //DISPLAY DIRECTION VALVE STATUS//
}
else if(pilot_lever==up && squat_switch==open && hydraulic_mechanism==malfunctioning) //NESTED IF CONDITION TO CHECK OTHER CONDITION//
{
printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
printf("direction valve status:%s\n",state_machine[current_state].direction_valve_status); //DISPLAY DIRECTION VALVE STATUS//
printf("gas pressurized spring status:%s\n",state_machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]); //DISPLAY GAS PRESSURIZED SPRING STATUS//
}
}

Rising Gear.c :-
#include "State.h" //INCLUDING HEADER FILE//
#include //PREPROCESSOR//
void raising_gear() //FUNCTION RAISING GEAR CALLED//
{
current_state=rsing_gr; //ASSIGNING CURRENT STATE TO RISING GEAR//
printf("\n current state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\n enter the limit switch status,pilot lever position:"); //PRINT THE MESSAGE//
fflush(stdout); //CLEAR CACHE MEMORY//
scanf("%d %d",&pilot_lever,&limit_switch); //READS AND STORES THE DATA//
printf("\n wait for 1 sec\n"); //PRINT THE MESSAGE//
if(pilot_lever==falling && limit_switch==open) //IF CONDITION TO CHECK THE CONDITIONS//
{
current_state = chk_bfr_lnd; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO CHECK BEFORE LANDING//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
printf("hydraulic control for landing gear status:%s\n",state_machine[current_state].hydraulic_pump_control_status); //DISPLAY HYDRAULIC PUMP CONTROL STATUS//
}
else if(pilot_lever==up && limit_switch==close) //NESTED IF CONDITION TO CHECK OTHER CONDITION//
{
current_state=gr_up; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO GEAR UP//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
printf("hydraulic control for landing gear status:%s\n",state_machine[current_state].hydraulic_pump_control_status); //DISPLAY HYDRAULIC PUMP CONTROL STATUS//
}
else //IF CONDITIONS ARE NOT SATISFIED GO TO RAISING GEAR FUNCTION//
{
raising_gear(); //REPEAT//
}
}

Gear Up :-
#include "State.h" //INCLUDING HEADER FILE//
#include //PREPROCESSOR//
void gear_up() //FUNCTION GEAR UP CALLED//
{
current_state=gr_up; //ASSIGNING CURRENT STATE TO GEAR UP//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nenter the pilot lever position:"); //PRINT THE MESSAGE//
fflush(stdout); //CLEAR CACHE MEMORY//
scanf("%d",&pilot_lever); //READS AND STORES THE DATA//
if(pilot_lever==falling) //IF CONDITION TO CHECK THE CONDITIONS//
{
current_state = chk_bfr_lnd; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO CHECK BEFORE LANDING//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
printf("hydraulic control for landing gear status:%s\n",state_machine[current_state].hydraulic_pump_control_status); //DISPLAY HYDRAULIC PUMP CONTROL STATUS//
}
else //IF CONDITIONS ARE NOT SATISFIED GO TO GEAR UP FUNCTION//
{
gear_up(); //REPEAT//
}
}

Checking Before Landing.c :-
#include "State.h" //INCLUDING HEADER FILE//
#include //PREPROCESSOR//
void checking_before_landing() //FUNCTION CHECKING BEFORE LANDING CALLED//
{
current_state=chk_bfr_lnd; //ASSIGNING CURRENT STATE TO CHECK BEFORE LANDING//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nenter the pilot lever position & status of hydraulic mechanism:"); //PRINT THE MESSAGE//
fflush(stdout); //CLEAR CACHE MEMORY//
scanf("%d %d",&pilot_lever,&hydraulic_mechanism); //READS AND STORES THE DATA//
if(pilot_lever==down && hydraulic_mechanism==working) //IF CONDITION TO CHECK THE CONDITIONS//
{
current_state = lwrng_gr; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO LOWERING GEAR//
printf("\n current state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\n light status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
printf("direction valve status:%s\n",state_machine[current_state].direction_valve_status); //DISPLAY DIRECTION VALVE STATUS//
}
else if(pilot_lever==down && hydraulic_mechanism==malfunctioning) //NESTED IF CONDITION TO CHECK OTHER CONDITION//
{
current_state = lwrng_gr; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO LOWERING GEAR//
printf("\n current state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\n light status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
printf("direction valve status:%s\n",state_machine[current_state].direction_valve_status); //DISPLAY DIRECTION VALVE STATUS//
printf("gas pressurized spring status:%s\n",state_machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]); //DISPLAY GAS PRESSURIZED SPRING STATUS//
}
else if (pilot_lever == (up || rising || falling)) //NESTED IF CONDITION TO CHECK OTHER CONDITION//
{
checking_before_landing(); //REPEAT//
}
}

Lowering Gear.c :-
#include "State.h" //INCLUDING HEADER FILE//
#include //PREPROCESSOR//
void lowering_gear() //FUNCTION LOWERING GEAR CALLED//
{
current_state=lwrng_gr; //ASSIGNING CURRENT STATE TO LOWERING GEAR//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nenter the limit switch status,pilot lever position:"); //PRINT THE MESSAGE//
fflush(stdout); //CLEAR CACHE MEMORY//
scanf("%d %d",&limit_switch,&pilot_lever); //READS AND STORES THE DATA//
if (limit_switch == close && pilot_lever==rising) //IF CONDITION TO CHECK THE CONDITIONS//
{
current_state = chk_bfr_tkof; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO CHECK BEFORE TAKEOFF//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nlight state: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
}
else if(limit_switch==open && pilot_lever==down) //NESTED IF CONDITION TO CHECK OTHER CONDITION//
{
current_state = gr_dwn; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO GEAR DOWN//
printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//
printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//
printf("hydraulic control for landing gear status:%s\n",state_machine[current_state].hydraulic_pump_control_status); //DISPLAY HYDRAULIC PUMP CONTROL STATUS//
}
else //IF CONDITIONS ARE NOT SATISFIED GO TO LOWERING GEAR FUNCTION//
{
lowering_gear(); //REPEAT//
}
}

Output :-
Main1.c:
- State table conditions are declared in main1.c.
States.h:
- Static table functions are defined in this header file of states.
- It consists of the various states of retraction and extension of airplanes landing gear modes.
States:
GR_DWN
CHK_BFR_TKFF
RSING_GR
GR_UP
CHK_BFR_LND
LWRNG_GR
Switch state:
Open
Close
Pilot lever state:
Rising
Falling
UP
DOWN
Hydraulic mechanism:
Working
Malfunctioning
Init_State_machine.c :-
- After inititializing the code ,current state is in Gear Down with green light.
state machine is initialized & program is in gear down state & light status:green

INITIAL CONDITION GEAR DOWN TO CHECK BEFORE TAKEOFF :-
state machine is initialized & program is in gear down state & light status:green
current state: geardown
enter the pilot lever position & squat switch status: 0 0
current state: checking before take off
light status: green

CHECK BEFORE TAKE OFF TO RAISING GEAR :-
current state: checking before take off
enter the pilot lever position,squat switch status & status of hydraulic mechanism:2 0 0
wait for 2 secs
current state: raising gear
light status: red
direction valve status:up

RAISING GEAR TO GEAR UP :-
current state: raising gear
enter the limit switch status,pilot lever position:2 1
wait for 1 sec
current state: gear up
light status: off
hydraulic control for landing gear status:disabled

GEAR UP TO CHECK BEFORE LANDING :-
current state: gear up
enter the pilot lever position:1
current state: checking before landing
light status: red
hydraulic control for landing gear status:enabled
current state: checking before landing

CHECK BEFORE LANDING TO LOWERING GEAR :-
current state: checking before landing
enter the pilot lever position & status of hydraulic mechanism:3 1
current state: lowering gear
light status: green
direction valve status:down
gas pressurized spring status:enabled
current state: lowering gear

LOWERING GEAR TO GEAR DOWN :-
current state: lowering gear
enter the limit switch status,pilot lever position:0 3
current state: geardown
light status: green
hydraulic control for landing gear status:enabled
current state: geardown

LOWERING GEAR TO TAKE OFF :-
current state: lowering gear
enter the limit switch status,pilot lever position:1 0
current state: checking before take off
light state: green
current state: checking before take off

RISING GEAR TO CHECK BEFORE LANDING :-
current state: raising gear
enter the limit switch status,pilot lever position:1 0
wait for 1 sec
current state: checking before landing
light status: red
hydraulic control for landing gear status:enabled
current state: checking before landing

OVERVIEW OF THE PROJECT:-
- The project is to know the knowledge of retraction and extensions of landing gear using a code.
- This can be achieved by using finite state machine which is used in the states header file.
- FSM (Finite state machine) is a mathematical model of computation.
- It is the most efficient algorithm which can be used.
- The creation of source file helps us easy to understand the program.
GOALS:-
- The main goals are to control the direction of valve and retraction and extension of landing gear.
- The control of direction valve is controlled by pilot lever which we can see in the program (reference given in attachment provided).
- The retraction and extension of landing gear is controlled by switch states in the program.
- Hence, all the goals are achieved.
KEY HIGHLIGHTS OF PROJECT:-
- 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.
DELIVERABLES OF THIS PROJECT:-
- The retraction and extension of landing gears is controlled by various switch and gear.
- The status of these switches and gears are shown below in various tables.
Table1:-
|
Switch State |
State of Gears |
|
Limit Switch CLOSED |
Gear is UP |
|
Limit Switch OPENED |
Gear is DOWN |
|
Switch State |
State of Airplane |
|
Squat Switch CLOSED |
Airplane is grounded and Gears are locked |
|
Squat Switch OPENED |
Airplane is taking off / landing / airborne |
A direction valve is controlled by the software to allow hydraulic pressure to either raise or lower the landing gear.
Table 2:-
|
Status of Direction Valve |
States of landing gear |
|
Direction valve = Down |
(Gear Down)(Parked at bay or Landed) |
|
Direction valve = Up |
Raising Gear(Taking Off) |
|
Control of hydraulic pump for the landing gear part is disabled |
Gear Up(Airborne) |
|
Direction valve = down |
Lowering Gear(Landing) |
INPUT FOR THE DIRECTION VALVE:-
Table 3:-
|
Pilot’s Lever State |
Direction Valve State |
|
Lever UP |
Direction valve = Up |
|
Lever Down |
Direction valve = Down |
Table 4:-
|
Pilot’s Lever State |
Light Status |
|
Lever Rising Edge |
Red |
|
Lever Falling Edge |
Table 5:-
Every gear has one light. According to the state of the gear,color of light is changing.
|
Landing Gear State |
Light Status |
|
Gear is up |
OFF |
|
Gear is down |
Green |
|
Gear in transit(Raising or Lowering) |
Red |
EXPECTED OUTCOMES:-
- In this project we get a good knowledge about the finite state machine algorithm.
- This algorithm helps us 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.
- The project has a easy logics which is shown in flowchart diagram which makes it easy and interesting.
- All the .c files, .h file and screenshots of outputs are uploaded for the reference.