Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
EMB LIVE BATCH : ABHINAYA
AIM:-
Implement the code for controlling the retraction and extensioin of Airplane's Landing gear
Introduction:-
An airplne has three gears for landing:
- Nose Gear
- Left Gear
- Right Gear
The hydraulic pump are used for 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.
Squat switch: only nose gear have squat switch to determine whether the airplan is in ground or not.
|
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 software to allow the hydraulic pressure to either raise or lower the landing gear
|
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 :
|
Pilot's Lever State |
Direction Valve State |
|
Lever UP |
Direction valve = Up |
|
Lever Down |
Direction valve = Down |
|
Pilot's Lever State |
Light Status |
|
Lever Rising Edge |
Red |
|
Lever Falling Edge |
Red |
Every gear has one light. According to the state of the gear, color of the light is changing.
|
Landing Gear State |
Light Status |
|
Gear is up |
OFF |
|
Gear is down |
Green |
|
Gear in transit |
Red |
By incorperating all these constraints we can come to result as shown below.

PROGRAMS:-
Project2.c(main.c)
#include
#include "States.h" //User defined library
static void(*state_table[])(void)={Gear_Down, Checking_Before_Takeoff, Raising_Gear, Gear_Up, Checking_Before_Landing, Lowering_Gear};
int main()
{
Init_State_Machine();
while(1)
{
state_table[current_state](); //calling each state functions
}
}
States.h
#ifndef STATES_H_
#define STATES_H_
/*.......Functions.......*/
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
{
GEAR_DOWN,
CHECKING_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECKING_BEFORE_LANDING,
LOWERING_GEAR,
}State_Type;
typedef enum Switch //switch states
{
Open,
Close //plane is in ground
}Switch_Status;
typedef enum Pilot_Lever //pilot lever states
{
Rising,
Falling,
UP,
DOWN
}Pilot_Lever_Status;
typedef enum Hydraulic_Mechanism //hydraulic control states
{
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;
//state table elements
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;
//creating state table
static State_Table State_Machine[6]={
{"Gear Down", "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 /* STATES_H_ */
Init_State_Machine.c
#include "States.h" //User defined library
void Init_State_Machine()
{
current_state = GEAR_DOWN;
printf("\nState Machine is initialized and program is in Gear_Down state & Light Status : %s\n",State_Machine[current_state].light_status);
}
Gear_Down.c
#include "States.h" //User defined library
#include
void Gear_Down()
{
current_state = GEAR_DOWN;
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 = CHECKING_BEFORE_TAKEOFF;
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();
}
}
Checking_Before_Takeoff.c
#include "States.h" //User defined library
#include
void Checking_Before_Takeoff()
{
current_state = CHECKING_BEFORE_TAKEOFF;
printf("\nEnter the pilot's lever position and squat switch status and Hydraulic Mechanism Status: ");
fflush(stdout);
scanf("%d %d %d", &pilot_lever, &squat_switch, &hydraulic_mechanism );
printf("\nWait for 2 sec\n");
if(pilot_lever == Falling || squat_switch == Close)
{
Gear_Down();
}
else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)
{
current_state = RAISING_GEAR;
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 = RAISING_GEAR;
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 status : %s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
}
Raising_Gear.c
#include "States.h" //User defined library
#include
void Raising_Gear()
{
current_state = RAISING_GEAR;
printf("\nEnter the Limit switch status, Pilot's lever 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 = CHECKING_BEFORE_LANDING;
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(pilot_lever == UP && limit_switch == Close)
{
current_state = GEAR_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();
}
}
Gear_Up.c
#include "States.h" //User defined library
#include
void Gear_Up()
{
current_state = GEAR_UP;
printf("\nEnter the Pilot's lever Position: ");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Falling)
{
current_state = CHECKING_BEFORE_LANDING;
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();
}
}
Checking_Before_Landing.c
#include "States.h" //User defined library
#include
void Checking_Before_Landing()
{
current_state = CHECKING_BEFORE_LANDING;
printf("\nEnter the Pilot's lever status and status OF Hydraulic Mechanism: ");
fflush(stdout);
scanf("%d %d", &pilot_lever, &hydraulic_mechanism);
if(pilot_lever == DOWN && hydraulic_mechanism == Working)
{
current_state = LOWERING_GEAR;
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 = LOWERING_GEAR;
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 status : %s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
if(pilot_lever == (UP || Rising || Falling))
{
Checking_Before_Landing();
}
}
Lowering_Gear.c
#include "States.h" //User defined library
#include
void Lowering_Gear()
{
current_state = LOWERING_GEAR;
printf("\nEnter the limit switch status and pilot's lever status: ");
fflush(stdout);
scanf("%d %d", &limit_switch, &pilot_lever);
if(limit_switch == Close && pilot_lever == Rising)
{
current_state = CHECKING_BEFORE_TAKEOFF;
printf("\nCurrent state : %s\n",State_Machine[current_state].current_state_indication);
printf("Light status : %s\n",State_Machine[current_state].light_status);
}
else if(limit_switch == Open && pilot_lever == DOWN)
{
current_state = GEAR_DOWN;
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();
}
}
OUTPUT

