Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Project 2 - 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.
In retraction and extension of Airplanes Landing gear, six different states are identified based on control elements like Pilot Lever,Squat switch,Limit switch & Direction Value.
Below figure shows the States and control element status.By change in control elements ,change in states accordingly by below figure.

Goals:
*Controlling the direction of Valve.
*Controlling the retraction and extension of Airplane’s landing gear.
*Displaying the current state indications along with the inputs required to change for next state.
Key Highlights of the Project:
*Controlling the Aircrafts retraction and extension by using software and switches like Squat and Pilot.
*A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.
*FSM algorithm used for the programming the project.
*Function pointer Array used for function protyping.
*enum data type used for Switches ,Pilot Lever and Direction Value.
Deliverables of the Project:
*Implementing the control for the retraction and extension of Airplane’s landing gear using the Finite state machine with the knowledge of various states of switch and gear.
*State of current state along the status of Light ,Status Direction Value and status of Hydraulic control will be printed as Output.
*Based on input provided application wll provide it Current State information.
Expected Outcome:
*The student will be getting the Knowledge of Finite State Machine algorithm which is used to achieve the control over the retraction and extension of Airplane’s landing gear using the switch and gear states of Airplane.
Knowledge on following Concept:
*FSM Concept
*Enum Data Type
*Function Pointer Array
Code:
#include<stdio.h>//Preprocessor Section
typedef enum State //TYPEDEF ENUM FUNCTION TO DEFINE STATE
{
GEAR_DOWN,
CHECKING_BEFORE_TAKE_OFF,
RAISING_GEAR,
GEAR_UP,
CHECKING_BEFORE_LANDING,
LOWERING_GEAR,
}State_Type;
typedef enum Switch//TYPEDEF ENUM FUNCTION TO DEFINE SWITCH
{
OPEN,
CLOSED,
}Switch_Status;
typedef enum Pilot_Lever //TYPEDEF ENUM FUNCTION TO DEFINE PILOT LEVER STATUS
{
RAISING,
FALLING,
UP,
DOWN,
}Pilot_Lever;
typedef enum hydraulic_mechanism //TYPEDEF ENUM FUNCTION TO DEFINE HYDRAULIC MECHANISM STATUS
{
WORKING,
NOT_WORKING,
}Hydraulic_Mechanism;
//INPUT VARIABLES FOR CHANGING THE STATES
static volatile Switch_Status Squat_Switch;
static volatile Switch_Status Limit_Switch;
static volatile Pilot_Lever Pilot_lever;
static volatile Hydraulic_Mechanism hydraulic_mechanism;
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;
char* direction_valve_status;
char* landing_gear_hydraulic_control;
}State_Table;
//STATE TABLE ARRAY DECLARATION
static State_Table State_Machine[6]=
{
{"GearDown","Green","Down","Enabled"},
{"Checking before take off", "Green","Down", "Enabled"},
{"Raising Gear", "Red", "Up", "Enabled"},
{"Gear up", "off", "Null", "Disabled"},
{"Checking before landing", "Red","Down", "Enabled" },
{"Lowering gear", "Green", "Down", "Enabled"}
};
//FUNCTION DEFINITIONS
void Init_State_Machine()//FUNCTION INITIAL STATE MACHINE CALL
{
current_state=GEAR_DOWN;
printf("Program is in Gear Down & Light is in:%s\n",State_Machine[current_state].light);
}
void GearDown(void)//FUNCTION GEAR DOWN CALL
{
current_state=GEAR_DOWN;
printf("Enter the status of Pilot Lever and Squat switch:");
fflush(stdout);
scanf("%d %d",&Pilot_lever,&Squat_Switch);
if(Pilot_lever==RAISING && Squat_Switch==OPEN)
{
current_state=CHECKING_BEFORE_TAKE_OFF;
printf("\n current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status);
printf("Landing Gear Hydraulic control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
GearDown();
}
}
void CheckingBeforeTakeOFF(void)//FUNCTION CHECKING BEFORE LANDING CALL
{
current_state=CHECKING_BEFORE_TAKE_OFF;
printf("Enter the status of Pilot Lever and Squat switch and Hydraulic Mechanism:");
fflush(stdout);
scanf("%d %d %d", &Pilot_lever, &Squat_Switch, &hydraulic_mechanism);
if(Pilot_lever==FALLING || Squat_Switch==CLOSED)
{
current_state=GEAR_DOWN;
printf("\n current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status);
printf("Landing Gear Hydraulic control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else if (Pilot_lever==UP && Squat_Switch==OPEN && hydraulic_mechanism==WORKING)
{
current_state=RAISING_GEAR;
printf("\n current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status);
printf("Landing Gear Hydraulic control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
CheckingBeforeTakeOFF();
}
}
void RaisingGear(void)//FUNCTION RAISING GEAR CALL
{
current_state=RAISING_GEAR;
printf("Enter the status of Pilot Lever and Limit switch: ");
fflush(stdout);
scanf("%d %d", &Pilot_lever, &Limit_Switch);
if(Pilot_lever==FALLING && Limit_Switch==OPEN)
{
current_state=CHECKING_BEFORE_LANDING;
printf("\n current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status);
printf("Landing Gear Hydraulic control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else if (Pilot_lever==UP && Limit_Switch==CLOSED)
{
current_state=GEAR_UP;
printf("\n current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status);
printf("Landing Gear Hydraulic control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
RaisingGear();
}
}
void GearUp(void)//FUNCTION GEAR UP CALL
{
current_state=GEAR_UP;
printf("Enter the status of Pilot Lever:");
fflush(stdout);
scanf("%d", &Pilot_lever);
if(Pilot_lever==FALLING)
{
current_state=CHECKING_BEFORE_LANDING;
printf("\n current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status);
printf("Landing Gear Hydraulic control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
GearUp();
}
}
void CheckingBeforeLanding(void)//FUNCTION CHECKING BEFORE LANDING CALL
{
current_state=CHECKING_BEFORE_LANDING;
printf("Enter the status of Pilot Lever and Hydraulic mechanism status:");
fflush(stdout);
scanf("%d %d", &Pilot_lever, &hydraulic_mechanism);
if(Pilot_lever==DOWN && hydraulic_mechanism==NOT_WORKING)
{
current_state=LOWERING_GEAR;
printf("\n current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status);
printf("Landing Gear Hydraulic control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
CheckingBeforeLanding();
}
}
void LoweringGear(void)//FUNCTION LOWERING GEAR CALL
{
current_state=LOWERING_GEAR;
printf("Enter the status of Pilot Lever and Limit Switch:");
fflush(stdout);
scanf("%d %d", &Pilot_lever, &Limit_Switch);
if(Pilot_lever==DOWN && Limit_Switch==OPEN)
{
current_state=GEAR_DOWN;
printf("\n current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status);
printf("Landing Gear Hydraulic control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else if(Pilot_lever==RAISING && Limit_Switch==CLOSED )
{
current_state=CHECKING_BEFORE_TAKE_OFF;
printf("\n current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status);
printf("Landing Gear Hydraulic control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
LoweringGear();
}
}
//DECLARING VARIABLES TO STATE TABLE
static void (*state_table[])(void)={GearDown,CheckingBeforeTakeOFF,RaisingGear,GearUp,
CheckingBeforeLanding,LoweringGear};
//MAIN FUNCTION
int main()
{
Init_State_Machine(); //INITIALIZE STATE MACHINE
while(1)
{
state_table[current_state](); //CALLING STATE TABLE
}
}
SCREENSHOT:

OUTPUT:
Program is in Gear Down & Light is in:Green
Enter the status of Pilot Lever and Squat switch:0 0
current state:Checking before take off
light:Green
Status of Direction valve :Down
Landing Gear Hydraulic control :Enabled
Enter the status of Pilot Lever and Squat switch and Hydraulic Mechanism:2 0 0
current state:Raising Gear
light:Red
Status of Direction valve :Up
Landing Gear Hydraulic control :Enabled
Enter the status of Pilot Lever and Limit switch 2 1
current state:Gear up
light:off
Status of Direction valve :Null
Landing Gear Hydraulic control :Disabled
Enter the status of Pilot Lever1
current state:Checking before landing
light:Red
Status of Direction valve :Down
Landing Gear Hydraulic control :Enabled
Enter the status of Pilot Lever and Hydraulic mechanism status 3 1
current state:Lowering gear
light:Green
Status of Direction valve :Down
Landing Gear Hydraulic control :Enabled
Enter the status of Pilot Lever and Limit Switch3 0
current state:GearDown
light:Green
Status of Direction valve :Down
Landing Gear Hydraulic control :Enabled
Enter the status of Pilot Lever and Squat switch: