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
Overview of the Project:
In this project, controlling the retraction and extension of the Airplane’s landing gear can be implemented using a Finite State Machine. The project describes the code for the landing of an airplane. we are going to write the code for different states before takeoff and time of landing. There are different switch states for every state. Using the finite state machine we are going to write the code.
Goal:
- Controlling the direction of Valve.
- Controlling the retraction and extension of Airplane’s landing gear.
Key highlights of the project:
A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.
Deliverables of this 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.
Expected Outcomes:
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.
Program:

#include "States.h"
#include <stdio.h>
static void(*state_table[])(void)={Gear_Down, Checking_Before_Takeoff, Raising_Gear,
Gear_Up, Checking_Before_Landing, Lowering_Gear};//static function//
int main()//main function//
{
Init_State_Machine();
while(1)//initizing the state//
{
state_table[current_state]();//calling function//
}
}

#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
{
GR_DWN,
CHK_BFR_TKFF,
RSING_GR,
GR_UP,
CHK_BFR_LND,
LWRING_GR
}state_type;
typedef enum Switch
{
open,
close//plane is graound//
}Switch_status;
typedef enum Pilot_lever
{
rising,
falling,
UP,
Down
}Pilot_Lever_status;
typedef enum Hydraulic_Mechanism
{
Working,
Malfunctioning
}Hydrulic_Mechanism_status;
//input function//
static volatile Switch_status squat_switch;
static volatile Switch_status limit_switch;
static volatile Pilot_Lever_status pilot_lever;
static volatile Hydrulic_Mechanism_status hydrulic_mechanism;
state_type current_state;
typedef struct
{
char* current_state_indication;
char* light_status;
char* direction_valve_status;
char* hydrulic_pump_control_status;
char* gas_pressurized_spring_status[2];
}State_table;
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"}}
};
#endif /* STATES_H_ */

#include"States.h"
#include<stdio.h>
void Lowering_Gear()
{
current_state=LWRING_GR;
printf("\nEnter the limit switch status,pilot lever status:");//printing statment//
fflush(stdout);//clean chach memory//
scanf("%d %d",&limit_switch,&pilot_lever);//user address//
if(limit_switch == close && pilot_lever == rising)//decreal the checking the condition//
{
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(limit_switch == open && pilot_lever ==Down)//decreal the checking the condition//
{
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("\n hydrulic pump control for landing gear status :%s\n",State_Machine[current_state].hydrulic_pump_control_status);
}
else
{
Lowering_Gear();
}
}

#include"States.h"
#include<stdio.h>
void Gear_Up()
{
current_state=GR_UP;
printf("\nEnter the limit switch status, Pilot Lever status:");//printing the statement//
fflush(stdout);//clear chach memory//
scanf("%d",&pilot_lever);//strong the data//
if(pilot_lever == falling)//decreal the checking the condition//
{
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("\n Hydrulic control for landing gear status:%s\n",State_Machine[current_state].hydrulic_pump_control_status);
}
else{
Gear_Up();
}
}

#include"States.h"
#include<stdio.h>
void Gear_Down()
{
current_state=GR_DWN;//calling function//
printf("\nEnter the pilot's lever Position and squat switch status:");//printing the statment//
fflush(stdout);//clear chach memory//
scanf("%d %d",&pilot_lever,&squat_switch);//user address//
if(pilot_lever==rising && squat_switch==open)//decreal the checking the condition//
{
current_state=CHK_BFR_TKFF;//calling function//
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
printf("\nLite State :%s\n",State_Machine[current_state].light_status);
}
else
{
Gear_Down();
}
}

#include"States.h"
void Init_State_Machine()
{
current_state=GR_DWN;
printf("\n state machine is initilized & Program is in Gear_Down State & Light Status :%s\n"
,State_Machine[current_state].light_status);
}

#include"States.h"
#include<stdio.h>
void Raising_Gear()
{
current_state=RSING_GR;//calling function//
printf("\nEnter the Limit Switch Status,Pilot lever Status:");//printing function//
fflush(stdout);//clear chach memory//
scanf("%d %d",&limit_switch,&pilot_lever);//user address//
printf("\n Wait for 1 sec\n");
if(pilot_lever == falling && limit_switch == open)//decreal the checking the condition//
{
current_state=CHK_BFR_LND;//calling function//
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
printf("Light State :%s\n",State_Machine[current_state].light_status);
printf("Hydraulic control for Landing Gear Status:%s\n",State_Machine[current_state].hydrulic_pump_control_status);
}
else if(limit_switch == close && pilot_lever == UP)//decreal the checking the condition//
{
current_state = GR_UP;//calling function//
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
printf("Light State :%s\n",State_Machine[current_state].light_status);
printf("Hydraulic control for Landing Gear Status:%s\n",State_Machine[current_state].hydrulic_pump_control_status);
}
else{
Raising_Gear();
}
}

#include "States.h"
#include<stdio.h>
void Checking_Before_Landing()
{
current_state=CHK_BFR_LND;//calling fuction//
printf("\nEnter the pilot lever Position and hydrulic Mechanism:");//printing statment//
fflush(stdout);//clear chach memory//
scanf("%d %d",&pilot_lever,&hydrulic_mechanism);//user address//
if(pilot_lever==Down && hydrulic_mechanism==Working)//decreal the checking the condition//
{
current_state=LWRING_GR;//calling function//
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 value status:%s\n",State_Machine[current_state].direction_valve_status);
}
if(pilot_lever==Down && hydrulic_mechanism==Malfunctioning)//decreal the checking the condition//
{
current_state=LWRING_GR;//calling function//
printf("\ncurrent State:%s\n",State_Machine[current_state].current_state_indication);
printf("light status:%s\n",State_Machine[current_state].light_status);
printf("hydrulic control for landind gear status:%s\n",State_Machine[current_state].hydrulic_pump_control_status);
printf("Gas pressurized spring status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydrulic_mechanism]);
}
else if(pilot_lever==(UP || rising || falling))//decreal the checking the condition//
{
Checking_Before_Landing();
}
}

#include "States.h"
#include<stdio.h>
void Checking_Before_Takeoff()
{
current_state=CHK_BFR_TKFF;//calling function//
printf("\nEnter the pilot lever Position,squate Switch and Hydraulic Mechanism Status:");//printing function//
fflush(stdout);//clear chach memory//
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydrulic_mechanism);//user address//
printf("\nWait for 2 sec\n");
if(pilot_lever == falling || squat_switch == close)//decreal the checking the condition//
{
Gear_Down();
}
else if(pilot_lever == UP && squat_switch == open && hydrulic_mechanism==Working)//decreal the checking the condition//
{
current_state=RSING_GR;//calling function//
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 value status:%s\n",State_Machine[current_state].direction_valve_status);
}
else if(pilot_lever == UP && squat_switch == open && hydrulic_mechanism==Malfunctioning)//decreal the checking the condition//
{
current_state = RSING_GR;//calling function//
printf("\nCurrent state:%s\n",State_Machine[current_state].current_state_indication);
printf("light status:%s\n",State_Machine[current_state].light_status);
printf("Hydrulic pump control for landind gear status:%s\n",State_Machine[current_state].hydrulic_pump_control_status);
printf("Gas pressurized spring status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydrulic_mechanism]);
}
}
Output Screenshort :

