Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Aim:
Implement the Code for controlling the retraction and extension of Airplane’s landing gear.
Objective:
1.The main goal is to write a code using the concept of finite state machine by using an type and also an enum
2.Controlling the direction of Valve.
3.Controlling the retraction and extension of Airplane’s landing gear
Description:
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 this project we have developed this project by using the C programming and Finite state machine. The finite state machine the process to express the algorithm in the form of states. the transition are connected between the state to show the flow of states and its input output connection. The c program we have to develop here to retraction and extension of the Airplane landing gear. There are so many states here we have take into consideration.
- initializing state machine of all condition
- Gear down
- Checking before tak-off
- Rising Gear
- Gear up condition
- Check before landing
- Lowering Gear
Deliverable and highlights of project:

The logical and working flow of the Airplane landing gear system is shown in above figure. We declare the typedef enum function. The direction valve controlled by the Software to control the Hydraulic pressure rise and lower of landing gear.
Steps and logic to develop the C program:
Step1: first declare header file and function prototype Gear_Down, Checking_Before_Take_Off, Raising_Gear, Gear_Up, Checking_Before_Landing and Lowering_Gear.
Step2: declare typedef and enum data type name as State_Type, Switch, Pilot_Lever and Hydraulic_mechanism.
Step3: The enumerated variable "State_type" has predefined states like "GEAR_DOWN", "CHECKING_BEFORE_TAKE_OFF","RAISING_GEAR","GEAR_UP","CHECKING_BEFORE_LANDING", "LOWERING_GEAR" and the enumerated variable "Hydraulic_mechanism" has predefined states like "WORKING" and "NOT_WORKING".
Step4: declare enumerated variable "Switch" has predefined states like "OFF", "ON" and the enumerated variable "Pilot_lever" has predefined states like "RAISING", "FALLING", "UP" and "DOWN".
Step5: Create two variables of enumerated datatype "Switch" with type qualifier as "volatile" and storage class as "static" and the variables are named as "Squat_Switch" and "Limit_Switch".
Step6: Similar to Step 5 we are creating two variables of enumerated datatype "Pilot_lever" with type qualifier as "volatile" and storage class as "static" and the variables are named as "PL".
Step7: Creating two variables of enumerated datatype "Hydraulic_mechanism" with type qualifier as "volatile" and storage class as "static" and the variables are named as "HM".
Step8: A structure is created with alias name of "State" and inside structure we are creating 4 string variables like "Currentstate", "Light", "Direction_valve" and "Hydraulic_control".
Step9: Creating array of function pointers in order to store the 6 different functions and it is created with the storage class of "static", return type and arguments as "void".
Step10: Creating an array of structure with storge class as "static" and it is named as "State_Machine" with the array size of 6 and each index of array will be storing current state, light status, Direction valve and Hydraulic control status as outputs.
Step11: In main function we are assigning the "GEAR_DOWN" state as the current state and Using infinite while loop we are calling the array of function pointers(State_Table[Current_state]()).
Step12: In function definition of Gear_Down() we are assigning the "GEAR_DOWN" state as the current state and using scanf() function we are getting the values of Pilot lever and Squat_Switch.
Step13: If condition declare check the Pilot lever is equal to "RAISING" and Squat_Switch is equal to "ON" and if the condition is true then we are assigning the "CHECKING_BEFORE_TAKE_OFF" as the current state.
Step14: Using printf() function we are printing the values of Currentstate, Light, Direction_valve and Hydraulic_control values. When the IF condition fails we are calling the same function "Gear_Down()".
Step15: In function definition of Checking_Before_Take_Off() we are assigning the "CHECKING_BEFORE_TAKE_OFF" state as the current state and using scanf() function we are getting the values of Pilot lever, Squat_Switch and Hydraulic_mechanism.
Step16: Using If condition we are checking the Pilot lever is equal to "FALLING" and Squat_Switch is equal to "OFF" and if the condition is true then we are assigning the "GEAR_DOWN" as the current state and printing the required outputs as mentioned in Step 14.
Step17: In Else If part we are checking the Pilot lever is equal to "UP" and Hydraulic_mechanism is equal to "WORKING" and if the condition is true then we are assigning the "RAISING_GEAR" as the current state and printing the required outputs as mentioned in Step 15 and in else part we are calling the same function "Checking_Before_Take_Off()".
Step18: In function definition of Raising_Gear() we are assigning the "RAISING_GEAR" state as the current state and using scanf() function we are getting the values of Pilot lever,Limit_Switch.
Step19: Using If condition we are checking the Pilot lever is equal to "FALLING" and if the condition is true then we are assigning the "CHECKING_BEFORE_LANDING" as the current state and printing the required outputs as mentioned in Step 15.
Step20: In Else If part we are checking the Limit_Switch is equal to "OFF" and if the condition is true then we are assigning the "GEAR_UP" as the current state and printing the required outputs as mentioned in Step 15 and in else part we are calling the same function "Raising_Gear()".
Step21: function definition of Gear_Up() we are assigning the "GEAR_UP" state as the current state and using scanf() function we are getting the values of Pilot lever.
Step22: Using If condition we are checking the Pilot lever is equal to "FALLING" and if the condition is true then we are assigning the "CHECKING_BEFORE_LANDING" as the current state and printing the required outputs as mentioned in Step 15 and in else part we are calling the same function "Gear_Up()".
Step23:In function definition of Checking_Before_Landing() we are assigning the "CHECKING_BEFORE_LANDING" state as the current state and using scanf() function we are getting the values of the pilot lever and Hydraulic_mechanism.
Step24: Using If condition we are checking the Pilot lever is equal to "DOWN" OR Hydraulic_mechanism is equal to NOT_WORKING if the condition is true then we are assigning the "LOWERING_GEAR" as the current state and printing the required outputs as mentioned in Step 15 and in else part we are calling the same function "Checking_Before_Landing()".
Step25: In function definition of Lowering_Gear() we are assigning the "LOWERING_GEAR" state as the current state and using scanf() function we are getting the values of the Pilot lever and Limit Switch.
Step26: Using If condition we are checking the Limit_Switch is equal to "ON" and if the condition is true then we are assigning the "GEAR_DOWN" as the current state and printing the required outputs as mentioned in Step 15.
Step26: In Else If part we are checking the Pilot lever is equal to "RAISING" and if the condition is true then we are assigning the "CHECKING_BEFORE_TAKE_OFF" as the current state and printing the required outputs as mentioned in Step 15 and in else part we are calling the same function "Lowering_Gear()".
C Program for the Project:
#include
#include
// C Program for control the Retraction and Extention of Airplane's ladding gear
void Gear_Down(void); //functions for program
void Checking_Before_Take_Off(void);
void Raising_Gear(void);
void Gear_Up(void);
void Checking_Before_Landing(void);
void Lowering_Gear(void);
typedef enum //user define finction prototypes
{
GEAR_DOWN,
CHECKING_BEFORE_TAKE_OFF,
RAISING_GEAR,
GEAR_UP,
CHECKING_BEFORE_LANDING,
LOWERING_GEAR
}State_type;
typedef enum //enumerated variable for ON/OFF Switch
{
OFF,
ON
}Switch;
typedef enum //enumerated variable of pilot lever fro rising and falling
{
RAISING,
FALLING,
UP,
DOWN
}Pilot_lever;
typedef enum // user define data type
{
WORKING,
NOT_WORKING
}Hydraulic_mechanism;
static volatile Switch Squat_Switch; // create enumerated variable with static
static volatile Switch Limit_Switch;
static volatile Pilot_lever PL; // pilot lever
static volatile Hydraulic_mechanism HM;
State_type Current_state;
typedef struct //structure create with alias name for various states
{
char* Currentstate;
char* Light;
char* Direction_valve;
char* Hydraulic_control;
}State;
// array of structure to store the various states
static void(*State_Table[])(void)={Gear_Down,Checking_Before_Take_Off,Raising_Gear,Gear_Up,Checking_Before_Landing,Lowering_Gear};
static State State_Machine[6]={
{"Gear Down","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"}
};
int main() //main function for gear down as current state
{
Current_state = GEAR_DOWN;
while(1) //infinite while loop
{
State_Table[Current_state]();
}
return 0;
}
Gear_Down()
{
Current_state = GEAR_DOWN;
printf("\nEnter the Pilot lever and Squat_Switch Values:");
fflush(stdout);
scanf("%d %d",&PL,&Squat_Switch);
if((PL==RAISING)&&(Squat_Switch==ON)) //ef else condition for checking gear state, pilt lever and squat switch
{
Current_state = CHECKING_BEFORE_TAKE_OFF;
printf("\nCurrent state: %s",State_Machine[Current_state].Currentstate); //if condition true then print all datanof various state
printf("\nLight Status: %s",State_Machine[Current_state].Light);
printf("\nDirection_valve Status: %s",State_Machine[Current_state].Direction_valve);
printf("\nHydraulic_control Status: %s",State_Machine[Current_state].Hydraulic_control);
}
else
{
Gear_Down(); //gear position is down if condition falls
}
}
Checking_Before_Take_Off() //function for take off
{
Current_state = CHECKING_BEFORE_TAKE_OFF; //current state as checking befor take off
printf("\nEnter the Pilot lever, Squat_Switch and Hydraulic_mechanism Values:"); //take the values from user
fflush(stdout);
scanf("%d %d %d",&PL,&Squat_Switch,&HM);
if((PL==FALLING)&&(Squat_Switch==OFF)) //check condition for gear down
{
Current_state = GEAR_DOWN;
printf("\nCurrent state: %s",State_Machine[Current_state].Currentstate);
printf("\nLight Status: %s",State_Machine[Current_state].Light);
printf("\nDirection_valve Status: %s",State_Machine[Current_state].Direction_valve);
printf("\nHydraulic_control Status: %s",State_Machine[Current_state].Hydraulic_control);
}
else if((PL==UP)&&(HM==WORKING)) //check else condition for gear rise
{
Current_state = RAISING_GEAR;
printf("\nCurrent state: %s",State_Machine[Current_state].Currentstate); //print the data for various states
printf("\nLight Status: %s",State_Machine[Current_state].Light);
printf("\nDirection_valve Status: %s",State_Machine[Current_state].Direction_valve);
printf("\nHydraulic_control Status: %s",State_Machine[Current_state].Hydraulic_control);
}
else
{
Checking_Before_Take_Off(); //if condition falls then this function will execute
}
}
Raising_Gear() //risiong geaar function
{
Current_state = RAISING_GEAR; //current state as rising gear
printf("\nEnter the Pilot lever,Limit_Switch Values:"); //input for pilot lever and switch
fflush(stdout);
scanf("%d %d",&PL,&Limit_Switch);
if(PL==FALLING) //condition for checking pilot lever
{
Current_state = CHECKING_BEFORE_LANDING; //current state as befor landing
printf("\nCurrent state: %s",State_Machine[Current_state].Currentstate);
printf("\nLight Status: %s",State_Machine[Current_state].Light);
printf("\nDirection_valve Status: %s",State_Machine[Current_state].Direction_valve);
printf("\nHydraulic_control Status: %s",State_Machine[Current_state].Hydraulic_control);
}
else if(Limit_Switch==OFF)
{
Current_state = GEAR_UP; //else current state as gear up
printf("\nCurrent state: %s",State_Machine[Current_state].Currentstate); //display all data for current state
printf("\nLight Status: %s",State_Machine[Current_state].Light);
printf("\nDirection_valve Status: %s",State_Machine[Current_state].Direction_valve);
printf("\nHydraulic_control Status: %s",State_Machine[Current_state].Hydraulic_control);
}
else
{
Raising_Gear(); //ele condtion for excute the rising gear function
}
}
Gear_Up() //gear up function
{
Current_state = GEAR_UP; //gear up as current state
printf("\nEnter the Pilot lever Values:"); //take input for pilot lever
fflush(stdout);
scanf("%d",&PL);
if(PL==FALLING) //check condition for pilot lever
{
Current_state = CHECKING_BEFORE_LANDING; //current state before landing
printf("\nCurrent state: %s",State_Machine[Current_state].Currentstate); //display the data if condition true
printf("\nLight Status: %s",State_Machine[Current_state].Light);
printf("\nDirection_valve Status: %s",State_Machine[Current_state].Direction_valve);
printf("\nHydraulic_control Status: %s",State_Machine[Current_state].Hydraulic_control);
}
else
{
Gear_Up(); //execute funcion gear up after condition falls
}
}
Checking_Before_Landing() //function
{
Current_state = CHECKING_BEFORE_LANDING; //current state as before landing check
printf("\nEnter the Pilot lever and Hydraulic_mechanism Values:"); //take inputs for pilot lever and hydrolic mechanism
fflush(stdout);
scanf("%d%d",&PL,&HM);
if((PL==DOWN)||(HM==NOT_WORKING)) //condition for pilot state and hydrolic mechanism
{
Current_state = LOWERING_GEAR;
printf("\nCurrent state: %s",State_Machine[Current_state].Currentstate); //display data if condition true
printf("\nLight Status: %s",State_Machine[Current_state].Light);
printf("\nDirection_valve Status: %s",State_Machine[Current_state].Direction_valve);
printf("\nHydraulic_control Status: %s",State_Machine[Current_state].Hydraulic_control);
}
else
{
Checking_Before_Landing(); //condition falls then execute the function
}
}
Lowering_Gear() //lowering gear function
{
Current_state = LOWERING_GEAR; //lowering gear as current state
printf("\nEnter the Pilot lever and Limit Switch Values:"); //take inputs for pilot lever and limit switch
fflush(stdout);
scanf("%d%d",&PL,&Limit_Switch);
if((Limit_Switch==ON)) //condition for switch position
{
Current_state = GEAR_DOWN; //current state as gear down
printf("\nCurrent state: %s",State_Machine[Current_state].Currentstate); //display the data
printf("\nLight Status: %s",State_Machine[Current_state].Light);
printf("\nDirection_valve Status: %s",State_Machine[Current_state].Direction_valve);
printf("\nHydraulic_control Status: %s",State_Machine[Current_state].Hydraulic_control);
}
else if(PL==RAISING) //condition check for pilot lever position
{
Current_state = CHECKING_BEFORE_TAKE_OFF; // current state before take off
printf("\nCurrent state: %s",State_Machine[Current_state].Currentstate);
printf("\nLight Status: %s",State_Machine[Current_state].Light);
printf("\nDirection_valve Status: %s",State_Machine[Current_state].Direction_valve);
printf("\nHydraulic_control Status: %s",State_Machine[Current_state].Hydraulic_control);
}
else
{
Lowering_Gear(); //condition falls then execute lowering gear function
}
}
Output:
Enter the Pilot lever and Squat_Switch Values:0 1
Current state: Checking Before Take Off
Light Status: Green
Direction_valve Status: Down
Hydraulic_control Status: Enabled
Enter the Pilot lever, Squat_Switch and Hydraulic_mechanism Values:1 0 0
Current state: Gear Down
Light Status: Green
Direction_valve Status: Down
Hydraulic_control Status: Enabled
Screen short of program and output:

Result:
In this we have developed the Code for controlling the retraction and extension of Airplane’s landing gear.