Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Aim of the project:
The main objective of this project is to write Embedded c Codings for controlling the retraction and extension of Airplane’s landing gear and this can be implemented using Finite State Machine (FSM) concept.
Tools Used:
PC with STM32 or Online GDB debugging tool
Description of the System & Algorithm:
- Actually an airplane has 3 gears[Nose,Left,Right] for landing.There is a hydraulic pumpwhich is extracting pressure to the gears to bring it down or pull it up and that pump is electrically driven.
- Every leg of the Gear has one limit switch and nose gear has one extra squat switch to determin whether the airplane is in ground or not.
- A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.
- Every Gear has one light. When Gear is up - light status is off; When gear is down - light is Green;Gear Raising/lowering - red color light.
- Dont retract the gear if the plane is on the ground.
- The case of failure of squat switch is ignored and failure of hydraulic system - gas pressurized springs can be used for gear extension.
- So considering all these case, FSM is the most efficient algorithm since it gives a mathematical way of computation for the problem.
The algorithm developed consists of 7 states and its assumed to take any one of these 7 states @ any instant of time based on user inputs:
state 1: Initialization of state machine
state2:Gear down state
state3 : Checking before take off
state4: raising gear
state5: Gear up
state6:checking befoore landing
state 7: lowering gear

Program:
/*
* project2.c
*
* Created on: 15-Sep-2022
* Author: Kavitha
*/
# include
# include
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
{
GR_DWN,
CHK_BFR_TKFF,
RSING_GR,
GR_UP,
CHK_BFR_LND,
LWRNG_GR
}State_Type;
typedef enum Switch
{
open,
close //plane is in ground
}Switch_Status;
typedef enum Pilot_Lever
{
Rising,
Falling,
Up,
Down
}Pilot_Lever_Status;
typedef enum Hydraulic_Mechanism
{
Working,
Malfunctioning
}Hydraulic_Mechanism_Status;
//Inputs 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;
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;
static State_Table State_Machine[6]={
{"Gear Down","Green","Down","Enabled",{NULL,NULL}},
{"Checking Before Take Off","Green","Down","Enabled",{NULL,NULL}},
{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"Gear Up","Off","Null","Disabled",{NULL,NULL}},
{"Checking Before Landing","Red","Down","Enabled",{NULL,NULL}},
{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
void Gear_Down(void)
{
printf("In Gear Down State \n");
current_state = GR_DWN;
printf("\n Enter the pilots 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("\n current state: %s \n", State_Machine[current_state].current_state_indication);
printf("\n Light Status:%s \n",State_Machine[current_state].light_status);
}
else
{
Gear_Down();
}
}
void Checking_Before_Takeoff()
{
current_state = CHK_BFR_TKFF;
printf("\n Enter the pilots Lever Position and Squat Switch Status and Hydraulic Mechanism Status: ");
fflush(stdout);
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
printf("\n Wait for 2 seconds \n");
if(pilot_lever == Falling || squat_switch == close)
{
Gear_Down();
}
else if (pilot_lever == Up && squat_switch == open && hydraulic_mechanism == Working)
{
current_state = RSING_GR;
printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
printf("\n 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 == Up && squat_switch == open && hydraulic_mechanism == Malfunctioning)
{
current_state = RSING_GR;
printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
printf("\n 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 = RSING_GR;
printf("\n Enter the limit switch status and pilot_lever Status: ");
fflush(stdout);
scanf("%d %d", &limit_switch, &pilot_lever);
printf("\n Wait for 1 seconds \n");
if(pilot_lever == Falling && limit_switch == open)
{
current_state = CHK_BFR_LND;
printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
printf("\n 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 = GR_UP;
printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
printf("\n 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 = GR_UP;
printf("\n Enter the pilots Lever Position: ");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Falling)
{
current_state = CHK_BFR_LND;
printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
printf("\n 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 = CHK_BFR_LND;
printf("\n Enter the pilots Lever Position and Hydraulic Mechanism Status: ");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
if(pilot_lever == Down && hydraulic_mechanism == Working)
{
current_state = LWRNG_GR;
printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
printf("\n 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 = LWRNG_GR;
printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
printf("\n 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]);
}
if(pilot_lever == (Up || Rising || Falling))
{
Checking_Before_Landing();
}
}
void Lowering_Gear()
{
current_state = LWRNG_GR;
printf("\n Enter the pilots Lever Position and Limit Switch Status: ");
fflush(stdout);
scanf("%d %d", &pilot_lever, &limit_switch);
if(pilot_lever == Rising)
{
current_state = CHK_BFR_TKFF;
printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
printf("\n Light Status:%s \n",State_Machine[current_state].light_status);
}
if (pilot_lever == Down && limit_switch == open)
{
current_state = GR_DWN;
printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
printf("\n 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);
}
if(limit_switch == close)
{
Lowering_Gear();
}
}
void Init_State_Machine()
{
current_state = GR_DWN;
printf("State Machine is Initialized and Program is in Gear Down state & Light Status is: Green\n");
}
int main()
{
Init_State_Machine();
while(1)
{
switch(current_state)
{
case 0: Gear_Down();
break;
case 1:Checking_Before_Takeoff();
break;
case 2:Raising_Gear();
break;
case 3: Gear_up ();
break;
case 4:Checking_Before_Landing();
break;
case 5: Lowering_Gear();
break;
default:break;
}
}
}
Output/Results:


Conclusion:
Thus using the Finite State Machine concept, Embedded C program has been successfully written and verified using STM32 IDE for controlling the retraction and extension of Airplane’s landing gear.