Challenge

Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear

Live Batch 5

Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear.

https://drive.google.com/file/d/1adQGqMrHBH6qYZmweNQTSr-rtf6coPr5/view

Soln:

Objective: To implement the C-code for controlling the retraction and extension of Airplane's landing gear using FSM.

FSM : Finite State Machine(FSM) is the most efficient algorithm which is mathematical model of computation.A finite state machine can have multiple states, it can switch from one state to another state on the basis of internal or external input. This input could be timer expiry signal, hardware or software interrupt .. etc. In the finite state machine, the procedure to change one state to another state is called transition.

Description of the Hardware:
Actually an airplane has 3 gears for landing :
• Nose Gear
• Left Gear
• Right Gear
There is a hydraulic pump which is exerting pressure to the gears to bring it down or pull it up and that pump is electrically driven.

Limit switches : Every leg of the gear has one limit switch.Nose gear has one extra Squat Switch to determine whether the airplane is in ground or not.

Switch State State of Gears
Limit Switch CLOSED Gear is UP
Limit Switch OPENED Gear is DOWN
Switch State State of Airplane
Squat Switch CLOSED Airplane is grounded and Gears are locked
Squat Switch OPENED Airplane is taking off / landing / airborne


A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.

Status of Direction Valve States of landing gear
Direction valve = Down (Gear Down)(Parked at bay or Landed)
Direction valve = Up Raising Gear(Taking Off)
Control of hydraulic pump for the landing gear part is disabled Gear Up(Airborne)
Direction valve = down Lowering Gear(Landing)


Input for the Direction Valve

Pilot’s Lever State Direction Valve State
Lever UP Direction valve = Up
Lever Down Direction valve = Down
Pilot’s Lever State Light Status
Lever Rising Edge Red
Lever Falling Edge Red


Every gear has one light. According to the state of the gear,color of light is changing.

Landing Gear State Light Status
Gear is up OFF
Gear is down Green
Gear in transit(Raising or
Lowering)
Red

Consider this cases


• There is a possibility that the plane is about to take off and an emergency comes where pilot has to abort the take off
• When taking off,to ensure that its right time to raising the gear,check for at least 4 seconds that squat switch is open
• When the airplane is parked at the bay and nose gear is down,then the nose gear is always experiencing a pressure on it due to airplane weight,weight of luggage and weight of passengers boarding on the airplane.Hydraulic mechanism is monitoring the pressure exerted on the nose gear and to neutralize that pressure its applying a pressure on the opposite direction.
• Hydraulic Control can detect the rising edge and falling edge of pilot’s lever
• In case of Hydraulic system failure,there are two gas pressurized springs by which gears can be extended
• The case of failure of Squat Switch is ignored

State Diagram:

State table :

Raising/up/open = 0

falling/down/close = 1

Pilot's Lever State

Squat Switch Limit Switch Direction Switch Current State Next State
0 0 Gear_Down Check_before_Takeoff
0 0 0 Check_before_Takeoff Raising_Gear
0 1 Raising_Gear Gear_Up
1 0/1 Raising_Gear Check_before_landing
1 Gear_Up Check_before_landing
1 1 Check_before_landing Lowering_gear
0 1 Lowering_gear Check_before_Takeoff
1 0 Lowering_gear Gear_Down

Program:

#include  //preprocessor section


typedef enum Airplane_states  //creating enumerated data type for Airplane states using typedef
{
GEAR_DOWN,				//enum members
CHECK_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECK_BEFORE_LANDING,
LOWERING_GEAR
}State_Type;			//Alias name

typedef enum Switch 	//creating enumerated data type for switch states using typedef
{
	Open,
	Close				//enum members
}Switch_Status;		//Alias name

typedef enum  Pilot_lever_States 	//creating enumerated data type for pilot lever using typedef
{
Raising,
Falling			//enum members
}Pilot_lever;	//Alias name

typedef enum direction_value	//creating enumerated data type for hydraulic using typedef
{
working,
not_working			//enum members
}Hydraulic_Mechanism;	//alias name

typedef enum		//creating enumerated data type for direction value using typedef
{
	Up,
	Down
}Direction_Value;	//Alias name

static volatile Switch_Status squat_switch;	//input for the squat switch
static volatile Switch_Status limit_switch;	//input for limit switch
static volatile Pilot_lever pilot_lever;	//input for pilot's lever
static volatile Direction_Value direction;	//input for direction
static volatile Hydraulic_Mechanism hydraulic_mechanism;	//input for hydraulic mechanism

//State table attributes declaration
typedef struct			//Structure declaration
{
char *current_state_indication;		//structure members
char *light;
char *direction_value_status;
char *gas_pressurized_spring_system_status[2];
char *landing_gear_hydraulic_control;
}State_table;							//alias name for struct

//State_table Table formation
static State_table State_Machine[6]={
{"GearDown","Green","Down",{NULL,NULL},"Enabled"},
{"CheckBeforeTakeOFF","Green","Down",{NULL,NULL},"Enabled"},
{"RaisingGear","Red","Up",{"Disabled","Enabled"},"Enabled"},
{"GearUP","Off","Null",{NULL,NULL},"Disabled"},
{"CheckBeforeLanding","Red","Down",{NULL,NULL},"Enabled"},
{"LoweringGear","Green","Down",{"Disabled","Enabled"},"Enabled"}
};

//function called prototype declarations
void Initate_State_Machine();
void GearDown();
void CheckBeforeTakeOFF();
void RaisingGear();
void GearUp();
void CheckBeforeLanding();
void LoweringGear();

State_Type current_state;	//assigning the current_state for State_Type

//accessing functions by an array of functions
static void(*stateTable[])(void)={GearDown,CheckBeforeTakeOFF,RaisingGear,GearUp,CheckBeforeLanding,LoweringGear};


int main()	//main function
{//main loop
	Initate_State_Machine();	//system initialized
	while(1)					//infinite loop condition
	{
		stateTable[current_state]();
	}
}//close loop

void Initate_State_Machine() //caller function
{
//system initialized and its in Gear_down condition
current_state=GEAR_DOWN;
printf("Control of Airplane landing Gear is implemented\n");	//print the value in the console
fflush(stdout);		//clear the buffer
printf("Current state is in GearDown State and Light is :%s\n",State_Machine[current_state].light);	//print the value in the console
fflush(stdout);		//clear the buffer
}

//GearDown function
void GearDown(void)	//caller function
{
//system initialized and its in GearDown condition
current_state=GEAR_DOWN;
printf("Enter the status of pilot's lever and squat switch :");	//print the value in the console
fflush(stdout);		//clear the buffer
scanf("%d %d",&pilot_lever,&squat_switch);	//scan the input from the console

//checking the if condition for check_before_takeoff function
if(pilot_lever==Raising && squat_switch==Open)
{
current_state=CHECK_BEFORE_TAKEOFF;	//current state is assigned with CHECK_BEFORE_TAKEOFF
printf("Current state :%s\n",State_Machine[current_state].current_state_indication);//print the value in the console
fflush(stdout);		//clear the buffer
printf("Light is :%s\n",State_Machine[current_state].light);	//print the value in the console
fflush(stdout);		//clear the buffer
}
else
{
GearDown();	//called function to repeat the loop
}
}

//checkingBeforeTakeoff function
void CheckBeforeTakeOFF(void)	//caller function
{

current_state=CHECK_BEFORE_TAKEOFF;
printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism :");//print the value in the console
fflush(stdout);		//clear the buffer
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);	//scan the input from the console

//checking the if condition for GearDown function
if(pilot_lever==Falling || squat_switch==Close)
{
GearDown();	//called function
}
//checking the if condition for Raising gear function
else if(pilot_lever==Up && squat_switch==Open && hydraulic_mechanism==Up)
{
current_state=RAISING_GEAR;		//current state is assigned with raising gear
printf("Current state :%s\n",State_Machine[current_state].current_state_indication);//print the value in the console
fflush(stdout);		//clear the buffer
printf("Light is :%s\n",State_Machine[current_state].light);	//print the value in the console
fflush(stdout);		//clear the buffer
printf("Status of Direction value is :%s\n",State_Machine[current_state].direction_value_status);	//print the value in the console
fflush(stdout);		//clear the buffer
printf("Status of Gas pressurized  Spring System :%s\n",State_Machine[current_state].gas_pressurized_spring_system_status);	//print the value in the console
fflush(stdout);		//clear the buffer
}

else
{
	CheckBeforeTakeOFF();	//called function
}
}

//Raising gear function
void RaisingGear(void)	//caller function
{
current_state=RAISING_GEAR;
printf("Enter the status of pilot's lever and limit switch :");	//print the value in the console
fflush(stdout);	//buffer to clear
scanf("%d %d",&pilot_lever,&limit_switch);	//scan the input from the console
//checking the if condition for CHECK_BEFORE_LANDING
 if(pilot_lever == Falling )
{
current_state=CHECK_BEFORE_LANDING;	//current state is assigned with CHECK_BEFORE_LANDING
printf("Current state :%s\n",State_Machine[current_state].current_state_indication);	//print the value in the console
fflush(stdout);	//buffer to clear
printf("Light is :%s\n",State_Machine[current_state].light);	//print the value in the console
fflush(stdout);	//buffer to clear
printf("Landing Gear Hydraulic Control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);	//print the value in the console
fflush(stdout);	//buffer to clear
}
 //checking the if condition for GEAR_UP function
 else if (limit_switch == Close)
 {
 	current_state=GEAR_UP;	//current state is assigned with GEAR_UP
 	printf("Current state :%s\n",State_Machine[current_state].current_state_indication);//print the value in the console
 	fflush(stdout);	//buffer to clear
 	printf("Light is :%s\n",State_Machine[current_state].light);//print the value in the console
 	fflush(stdout);	//buffer to clear

 }

else
{
RaisingGear();	//called function
}
}

//GearUp function
void GearUp(void)	//caller function
{
current_state= GEAR_UP;
printf("Enter the status of pilots lever :");	//print the value in the console
fflush(stdout);	//buffer to clear
scanf("%d",&pilot_lever);	//scan the input from the console
//checking the if condition for CHECK_BEFORE_LANDING
if(pilot_lever == Falling)
{
current_state=CHECK_BEFORE_LANDING; //current state is assigned with CHECK_BEFORE_LANDING
printf("Current state :%s\n",State_Machine[current_state].current_state_indication);//print the value in the console
fflush(stdout);	//buffer to clear
printf("Light is :%s\n",State_Machine[current_state].light); //print the value in the console
fflush(stdout);		//buffer to clear
printf("Landing Gear Hydraulic Control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);//print the value in the console
fflush(stdout);	//buffer to clear
}

else
{
	GearUp();	//called function
}
}

//checkBeforeLanding function
void CheckBeforeLanding(void)	//caller function
{
current_state=CHECK_BEFORE_LANDING;
printf("enter the pilot's lever and hydraulic mechanism status :");	//print the value in the console
fflush(stdout);	//buffer to clear
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);	//scan the input from the console
//checking the if condition for LOWERING_GEAR
if(pilot_lever==Down && hydraulic_mechanism==Down)
{
current_state=LOWERING_GEAR;	//current state is assigned with LOWERING_GEAR
printf("Current state :%s\n",State_Machine[current_state].current_state_indication);//print the value in the console
fflush(stdout);	//buffer to clear
printf("Light is :%s\n",State_Machine[current_state].light);	//print the value in the console
fflush(stdout);	//buffer to clear
printf("Status of Direction value is :%s\n",State_Machine[current_state].direction_value_status);//print the value in the console
fflush(stdout);	//buffer to clear
}
else
{
CheckBeforeLanding();	//called function
}
}

//loweringgear function
void LoweringGear(void)	//caller function
{
current_state=LOWERING_GEAR;
printf("Enter the status of pilot's lever and Limit Switch :");	//print the value in the console
fflush(stdout);	//buffer to clear
scanf("%d %d",&pilot_lever,&limit_switch);	//scan the input from the console
//checking the if condition for CHECK_BEFORE_TAKEOFF
if(pilot_lever==Raising )
{
current_state=CHECK_BEFORE_TAKEOFF;	//current state is assigned with
printf("Current state :%s\n",State_Machine[current_state].current_state_indication);//print the value in the console
fflush(stdout);		//buffer to clear
printf("Light is :%s\n",State_Machine[current_state].light);//print the value in the console
fflush(stdout);	//buffer to clear
}
//checking the if condition for GEAR_DOWN
else if(limit_switch==Open)
{
current_state=GEAR_DOWN;	//current state is assigned with GEAR_DOWN
printf("Current state :%s\n",State_Machine[current_state].current_state_indication);//print the value in the console
fflush(stdout);	//buffer to clear
printf("Light is :%s\n",State_Machine[current_state].light);//print the value in the console
fflush(stdout);	//buffer to clear
printf("Landing Gear Hydraulic Control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);//print the value in the console
fflush(stdout);	//buffer to clear
}

else
{
LoweringGear();	//called function
}
}

Output:

Geardown to CheckBeforeTakeoff

CheckBeforeTakeoff to RaisingGear

RaisingGear to GearUp

RaisingGear to CheckBeforeLanding

GearUp to CheckBeforeLanding

CheckBeforeLanding to LoweringGear

LoweringGear to CheckBeforeTakeoff

LoweringGear to GearDown

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.