Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Project:Implementation of the code for controlling the retraction and extension of airplane’s landing gear
Aim:
- To implement the code for control retraction and extension of airplanes landing gear implementation using Finite State Machine (FSM).
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.
State digram:

| State Type | Switch Status | Pilot Lever Status | Hydraulic Mechanics Status |
| GEAR_DOWN | Open | Rising | Working |
| CHECK_BEFORE_TAKEOFF | Close | Falling | Notworking |
| RAISING_GEAR | Up | ||
| GEAR_UP | Down | ||
| CHECK_BEFORE_LANDING | |||
| LOWERING_GEAR |
Code:
/*
* project.c
*
* Created on: 16-Mar-2023
* Author: rajpr
*/
/*
* pra.c
*
* Created on: 06-Mar-2023
* Author: rajpr
*/
#include
#include
/*Function used in this project*/
void Init_State_Machine(); //function declartion
void Gear_Down();
void Checking_Before_Takeoff();
void Raising_Gear();
void Gear_Up();
void Checking_Before_Landing();
void Lowering_Gear();
typedef enum State //enum used to give subsequent value for each state
{
GEAR_DOWN,//GEAR_DOWN= 0
CHECK_BEFORE_TAKEOFF,//CHECK_BEFORE_TAKEOFF= 1
RAISING_GEAR,//RAISING_GEAR= 2
GEAR_UP,//GEAR_UP= 3
CHECK_BEFORE_LAND,//CHECK_BEFORE_LAND= 4
LOWERING_GEAR//LOWERING_GEAR= 5
}State_Type;
typedef enum Switch//enum switch is used for sebsequent value of switch
{
Open, //Open=0
Close //Close=1
}Switch_Status;
typedef enum Pilot_Lever
{
Rising, //Rising=0
Falling, //Falling=1
UP, //UP=2
DOWN //DOWN=3
}Pilot_Lever_Status;
typedef enum Hydraulic_Mechanism
{
Working, //Working=o
Malfunctioning//Malfunctioning=1
}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 //structre is used to have different types of datatype
{
char* current_state_indication; //output which we want to visualize aregiven under structure as structure member
char* light_status;
char* direction_valve_status;
char* hydraulic_pump_control_status;
char* gas_pressurized_spring_status[2];
}State_Table;
/*State table of the requried system*/
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"}}
};
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]();
}
}
void Init_State_Machine()
{
current_state = GEAR_DOWN;
printf("\nState Machine is initialized & Program is in Gear_Down State & Light Status: %s\n"
,State_Machine[current_state].light_status);
}
void Gear_Down(void)
{
current_state = GEAR_DOWN;
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 = CHECK_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();
}
}
void Checking_Before_Takeoff()
{
current_state = CHECK_BEFORE_TAKEOFF;
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("\n Wait 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 = 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 System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
}
void Raising_Gear()
{
current_state = RAISING_GEAR;
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 = CHECK_BEFORE_LAND;
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 = 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();
}
}
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 = CHECK_BEFORE_LAND;
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();
}
}
void Checking_Before_Landing()
{
current_state = CHECK_BEFORE_LAND;
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 = 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 System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
else if(pilot_lever == (UP || Rising || Falling))
{
Checking_Before_Landing();
}
}
void Lowering_Gear()
{
current_state = LOWERING_GEAR;
printf("\nEnter the Limit Switch Status,Pilots Leaver Status:");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if(limit_switch == Close && pilot_lever == Rising )
{
current_state = CHECK_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);
}
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 Controlfor Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
}
else
{
Lowering_Gear();
}
}
Result:This a program code is created to control retraction and extension of airplanes landing gear implementation using Finite State Machine (FSM).