Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
-------------------------------------------------------LIVE BATCH-----------------------------------------------------
AIM:-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 Airplane's landing gear can be implemented using Finite state Machine(FSM). FSM is the most efficient algorithm which is mathematical model of computation.
- Problem Statement:-
- Implement the Code for controlling the retraction and extension of Airplane's landing gear
- Description of the Hardware:-
- Actually an airplane has gears for landing:
- Nose Gear
- Left Gear
- Right Gear
- There is a hydraulic pump which is exerting pressure to the gears to bring it down or pull it up and that pump is electrically driven.
- Limit switches:-
- 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 no
|
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 |
- Consider this cases:-
- There is a possibility that the plane is about to take off and emergency comes where pilot has to abort the take off.
- When taking off,to ensure that its right time to raising the gear.Check for at least 4 seconds that squat switch is open.
- Contant:
- When the airplane is parked at the bay and nose gear is down,then the nose gear is always experiencing a pressure on it due to airplane weight,weight of luggage and weight of passengers boarding on the airplane.
- Hydraulic mechanism is monitoring the pressure exerted on the nose gear and to neutralize that pressure its applying a pressure on the opposite direction.
- Hydraulic Control can detect the rising edge and falling edge of pilot's lever.
- In case of Hydraulic system failure,there are two gas pressurized springs by which gears can be extended
- The case of failure of Squat Switch is ignored.

- 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.
- In this project we have created NINE files.
- There are,EIGHT '.c' file and ONE "h' file.
- main.c file
- states.h file
- init state.c file
- gear down.c file
- checking befor takeoff.c file
- raising gear.c file
- gear up.c file
- checking befor landing.c file
- lowering gear.c file
- CODE:-
- main.c:-
#include"states.h" //states header file
static void(*state_table[])(void)={s_gear_down,
s_checking_before_take_off,
s_rising_gear,
s_gear_up,
s_checking_before_landing,
s_lowering_gear};
// array of function pointer declaration and initialization.
//it can change accordingly airplane landing gear are called
int main() //main function
{
init_state_machine(); //function call for initial state
while(1) //infinite loop
{
state_table[current_state](); //state table function call based on current state
}
}
- states.h:-
#ifndef STATES_H_
#define STATES_H_
#include<stdio.h>
#define P printf
#define S scanf
typedef enum //creating user define data type
{
gear_down, //different type of states
checking_before_take_off,
rising_gear,
gear_up,
checking_before_landing,
lowering_gear
}state_type;
state_type current_state; //state_type is declared as current_state
typedef enum //user defined data type for switch input
{
open,
close
}switch_condition;
static volatile switch_condition limit_switch; //declaring two switches
static volatile switch_condition squat_switch;
typedef enum //for lever position
{
rising,
falling,
up,
down,
}pilot_lever;
pilot_lever lever_position;
typedef enum //for hydrolic pump input
{
working,
malfunctioning
}hydrolic;
hydrolic pump_status;
typedef struct //state table attributes declaration
{
char* current_status_indication;
char* lights_status;
char* direction_valve_status;
char* hydrolic_pump_control_status;
char* gas_spring_status[2];
}State_table;
//state table formation
static State_table state_machine[6]={
{"gear down","green","down","enabled",{0,0}},
{"checking before take off","green","down","enabled",{0,0}},
{"rising 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"}}
};
void init_state_machine(); //declaration of function prototype for all states
void s_gear_down();
void s_checking_before_take_off();
void s_rising_gear();
void s_gear_up();
void s_checking_before_landing();
void s_lowering_gear();
#endif /* STATES_H_ */
- init_state.c:-
#include"states.h" //including states header file
void init_state_machine()
{
current_state=gear_down;
P("current status_indication:- %s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s\n",state_machine[current_state].direction_valve_status);
}
- gear_down.c
#include"states.h"
void s_gear_down()
{
current_state = gear_down;
P("\nenter the position of lever:-");
fflush(stdout);
S("%d",&lever_position); //asking user to give lever position and squat switch
P("Enter squat switch input:-");
fflush(stdout);
S("%d",&squat_switch);
if(lever_position == rising && squat_switch == open) //condition statement for next state
{
current_state=checking_before_take_off;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s\n",state_machine[current_state].direction_valve_status);
}
else
{
s_gear_down(); //function call
}
}
- checking_before_take_off.c:-
#include"states.h"
void s_checking_before_take_off()
{
current_state=checking_before_take_off;
P("\nenter the position of lever:-");
fflush(stdout);
S("%d",&lever_position);
P("Enter squat switch input:-");
fflush(stdout);
S("%d",&squat_switch);
P("enter the hydrolic pump status:-");
fflush(stdout);
S("%d",&pump_status);
if(lever_position == up && squat_switch == open && pump_status == working) //condition for rising gear state
{
current_state=rising_gear;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s",state_machine[current_state].direction_valve_status);
P("\ngas spring status:-%s\n",state_machine[current_state].gas_spring_status[pump_status]);
}
else if(lever_position == up && squat_switch == open && pump_status == malfunctioning) //condition for rising gear state
{
current_state=rising_gear;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s",state_machine[current_state].direction_valve_status);
P("\ngas spring pump status:-%s\n",state_machine[current_state].gas_spring_status[pump_status]);
}
else if(lever_position == falling && squat_switch == open) //condition for gear down state
{
current_state=gear_down;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s\n",state_machine[current_state].direction_valve_status);
}
}
- rising_gear.c:-
#include"states.h"
void s_rising_gear()
{
current_state=rising_gear;
P("\nenter the position of lever:-");
fflush(stdout);
S("%d",&lever_position);
P("enter limit switch input:-");
fflush(stdout);
S("%d",&limit_switch);
if(lever_position==up && limit_switch == close) //condition for gear_up state
{
current_state=gear_up;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s\n",state_machine[current_state].direction_valve_status);
}
else if(lever_position==falling && limit_switch==open) //condition for checking before
{
current_state=checking_before_landing;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s\n",state_machine[current_state].direction_valve_status);
}
else
{
s_rising_gear(); //function call
}
}
- gear_up.c:-
#include"states.h"
void s_gear_up()
{
current_state=gear_up;
P("\nenter the position of lever:-");
fflush(stdout);
S("%d",&lever_position);
if(lever_position == falling) //condition for checking before landing state
{
current_state=checking_before_landing;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s",state_machine[current_state].direction_valve_status);
P("\npump status:-%s\n",state_machine[current_state].hydrolic_pump_control_status);
}
else
{
s_gear_up(); //function call
}
}
- checking_before_landing.c:-
#include"states.h"
void s_checking_before_landing()
{
current_state=checking_before_landing;
P("\nenter the position of lever:-");
fflush(stdout);
S("%d",&lever_position);
P("enter the hydrolic pump status:-");
fflush(stdout);
S("%d",&pump_status);
if(lever_position == down && pump_status == working) //condition for lowering gear
{
current_state=lowering_gear;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s",state_machine[current_state].direction_valve_status);
P("\ngas spring status:-%s\n",state_machine[current_state].gas_spring_status[pump_status]);
}
else if(lever_position == down && pump_status == malfunctioning)
{
current_state=lowering_gear;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s",state_machine[current_state].direction_valve_status);
P("\ngas spring pump status:-%s\n",state_machine[current_state].gas_spring_status[pump_status]);
}
else
{
s_checking_before_landing(); //function call
}
}
- lowering_gear.c:-
#include"states.h"
void s_lowering_gear()
{
current_state=lowering_gear;
P("\nenter the position of lever:-");
fflush(stdout);
S("%d",&lever_position);
P("enter limit switch input:-");
fflush(stdout);
S("%d",&limit_switch);
if(lever_position==down && limit_switch == open) //condition for gear down
{
current_state=gear_down;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s\n",state_machine[current_state].direction_valve_status);
}
else if(lever_position==rising && limit_switch==close) //condition for checking before take off
{
current_state=checking_before_take_off;
P("\ncurrent state indication:-%s",state_machine[current_state].current_status_indication);
P("\nlight status:-%s",state_machine[current_state].lights_status);
P("\ndirection valve status:-%s\n",state_machine[current_state].direction_valve_status);
}
else
{
s_lowering_gear(); //function call
}
}
- RESULT:-


- CONCLUSION:-
- Thus a program code is created to control retraction and extension of airplanes landing gear implementation using finite state machine(FSM).