Challenge

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.

Actually an airplane has 3 gears for landing: Nose gear, Left gear, Right gear.

There is an electrically powered hydraulic pump that applies pressure to the gears to bring it down or pull it up.

There is a limit switch on each leg of the gear. One extra squat switch is installed in the nose gear to assess whether the plane is on the ground or not.

Goals:

  • 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.

Aim: Implement the Code for controlling the retraction and extension of Airplane’s landing gear.

Objective: Controlling the Airplanes landing gear using the Finite State Machine.

Finite state Machine: A finite state machine (sometimes called a finite state automaton) is a computation model that can be implemented with hardware or software and can be used to simulate sequential logic and some computer programs. Finite state automata generate regular languages. Finite state machines can be used to model problems in many fields including mathematics, artificial intelligence, games, and linguistics.

A system where particular inputs cause particular changes in state can be represented using finite state machines. This example describes the various states of a turnstile. Inserting a coin into a turnstile will unlock it, and after the turnstile has been pushed, it locks again. Inserting a coin into an unlocked turnstile, or pushing against a locked turnstile will not change its state.

Implementation of Code logic using following State Flow Chart of Aeroplane landing Gear Control:

To implement above logic in the FSM we need the states with their respective functions.

Here we are using the switch states,Direction of valves with respect to gear.

Limit Switch: 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.

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

Input for the Direction Valve:

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

Code For above mentioned FSM model:

#include <stdio.h>
void Initiate_State_Machine();
void GearDown();
void CheckingBeforeTakeOFF();
void RaisingGear();
void GearUp();
void CheckBeforeLanding();
void LoweringGear();
static void(*statetable[])(void)={GearDown, CheckingBeforeTakeOFF, RaisingGear, GearUp, CheckBeforeLanding, LoweringGear};
typedef enum State
{
	GEAR_DOWN,
	CHECKING_BEFORE_TAKEOFF,
	RAISING_GEAR,
	GEAR_UP,
	CHECK_BEFORE_LANDING,
	LOWERING_GEAR,
}State_Type;
typedef enum Switch
{
	on,
	off//plane is on ground
}Switch_status;
typedef enum pilot_lever
{
	Raising,
	falling
}pilot_lever;
typedef enum hydraulic_mechanism
{
	working,
	not_working
}hydraulic_mechanism;

static volatile Switch_status squat_switch;
static volatile Switch_status limit_switch;
static volatile pilot_lever pl;
static volatile hydraulic_mechanism hm;

State_Type current_state;

typedef struct
{
	char* current_state_indication;
	char* light;
	char* direction_valve_status;
char* landing_gear_hydraulic_control;
	char* Gas_Pressurized_Spring_system_status[2];

}State_Table;

static State_Table State_Machine[6]={{"GearDown","Green","Down","Enabled",{NULL,NULL}},
		{"CheckingBeforeTakeOFF","Green","Down","Enabled",{NULL,NULL}},
		{"RaisingGear","Red","Up","Enabled",{NULL,NULL}},
		{"GearUp","Off","NULL","Disabled",{NULL,NULL}},
		{"CheckBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
		{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}
};

int main()
{
	Initiate_State_Machine();
	while(1)
	{
		statetable[current_state]();
	}
}

//Initiate_State_Machine
void Initiate_State_Machine()
{
	current_state==GEAR_DOWN;
	printf("The Finite State Machine is Intialized and current the program is in""GearDown State & Light is:%s\n",State_Machine[current_state].light);
}

//GEARDOWN state.
void GearDown(void)
{
	current_state=GEAR_DOWN;
	printf("Enter the status of pilot's lever and squat switch:");
	fflush(stdout);
	scanf("%d %d",&pl,&squat_switch);
	if(pl==Raising && squat_switch==on)
	{
		current_state=CHECKING_BEFORE_TAKEOFF;
		printf("current state:%s\n",State_Machine[current_state].current_state_indication);
		printf("Light is :%s\n", State_Machine[current_state].light);
	}
	else
	{
		GearDown();
	}
}

//Checking Before TakeOFF state.
void CheckingBeforeTakeOFF(void)
{
	current_state=CHECKING_BEFORE_TAKEOFF;
	printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism:");
	fflush(stdout);
	scanf("%d %d",&pl,&squat_switch,&hm);
	if(pl==falling&&squat_switch==off)
	{
		GearDown();
	}
	else if(pl==Raising && squat_switch==on && hm==working)
	{
		current_state=RAISING_GEAR;
		printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
		printf("Light is:%s\n",State_Machine[current_state].light);
		printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
	}
	else if(pl==Raising && squat_switch==on && hm==not_working)
	{
		current_state=RAISING_GEAR;
		printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
		printf("Light is:%s\n",State_Machine[current_state].light);
		printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
		printf("Status of gas pressurized Spring System:%s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);
	}
}

//Raising Gear state.
void RaisingGear(void)
{
	current_state=RAISING_GEAR;
	printf("Enter the status of pilot's lever and limit switch:");
	fflush(stdout);
	scanf("%d %d",&pl,&limit_switch);
	if(pl==falling && limit_switch==on)
	{
		current_state=CHECK_BEFORE_LANDING;
		printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
		printf("Light is:%s\n",State_Machine[current_state].light);
		printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
	}
	else if(pl==Raising && limit_switch==off)
	{
		current_state=GEAR_UP;
		printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
		printf("Light is:%s\n",State_Machine[current_state].light);
		printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
	}
	else
	{
		RaisingGear();
	}
	}

//GearUp state.
void GearUp(void)
{
	current_state=GEAR_UP;
	printf("Enter the status of pilot's lever:");
	fflush(stdout);
	scanf("%d",&pl);
	if(pl==falling)
	{
	current_state=CHECK_BEFORE_LANDING;
	printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
	printf("Light is:%s\n",State_Machine[current_state].light);
	printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
	else
	{
		GearUp();
	}

}

//Check Before Landing state.
void CheckBeforeLanding(void)
{
	current_state=CHECK_BEFORE_LANDING;
	printf("Enter the status of pilot's lever and hydraulic mechanism status:");
	fflush(stdout);
	scanf("%d %d",&pl,&hm);
	if(pl==falling && hm==working)
	{
		current_state=LOWERING_GEAR;
		printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
		printf("Light is:%s\n",State_Machine[current_state].light);
		printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
	}
	else if(pl==falling && hm==not_working)
	{
		current_state=LOWERING_GEAR;
		printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
		printf("Light is:%s\n",State_Machine[current_state].light);
		printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
		printf("Status of gas pressurised Spring System:%s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);
	}
	else if(pl==(Raising))
	{
		CheckBeforeLanding();
	}
}

//LoweringGear.
void LoweringGear(void)
{
	current_state=LOWERING_GEAR;
		printf("Enter the status of pilot's lever and limit switch:");
		fflush(stdout);
		scanf("%d %d",&pl,&limit_switch);
		if(pl==falling && limit_switch==on)
		{
			current_state=CHECKING_BEFORE_TAKEOFF;
			printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
			printf("Light is:%s\n",State_Machine[current_state].light);
		}
		else if(pl==Raising && limit_switch==off)
		{
			current_state=GEAR_DOWN;
			printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
			printf("Light is:%s\n",State_Machine[current_state].light);
			printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
		}
		if(limit_switch==off)
		{
			LoweringGear();
		}
}

Code Explaination:

Step1: First we are creating seven function we want to carry out the process or controlling sets of gear under different condition.Based on above chart.

The function are:

Step2: Creation of static Table And then enter above function into the array of 6 element to access the finction based on requirement.

Step3: Creation of four type of enum structure in the program to carrry out comparison and easy way giving inputs.

Step4: Creating the object name for the 4 enum structures:

In above created enum structure defines static type because we can use this any where in the program volatile means it values are change/ vary.

Step5: Creation of the structure where we are giving the different condition where how to control the landing gears.

We are giving the name to above created structure as state_table.

Step6: Creating the object named as state-machine which is an array in which it contain six different type of condtional output:

we can access the inside array one element using dot sign.

We are creating the main function: In main function we are calling the function name is Intiate State machine function:with no argument.

Step7: Implementing the logic for each function created in accordance to flowchart mentioned above.

In above mentioned function we are changing the current state of gear by getting the pilot inputs if the pilot give inputs as raising and switch on it means ready to takes off and changing th state as checking before take-off state, And then printing current state, light indication & other control mechanism as mentioned in the flow chart.

Observtion/Results:

Code for controlling the retraction and extension of Airplane’s landing gear has been successfully executed.

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.