Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Implement the code for controlling the retraction and extensioin of Airplane's Landing gear
Introduction :
An airplne has three gears for landing:
- Nose Gear
- Left Gear
- Right Gear
The hydraulic pump are used for 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.
Squat switch: only nose gear have squat switch to determine whether the airplan 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 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 the light is changing.
| Landing Gear State | Light Status |
|
Gear is up |
OFF |
| Gear is down | Green |
| Gear in transit | Red |
By incorperating all these constraints we can come to result as shown below.

Program:
Objective:
Here we are going to control the Airplanes landing gear.
What is 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 problem
To carry out the problem we need the states with their respective finctions.
Here we are using the switch states,Direction of valves with respect to gear.




From the above input we are creating six differernt conditions and function.In this function we are determing or controlling the land gear in diffferent conditions.

This flow chart represent condition of the state and condition required to jump into next state.
coding:
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:

And then we are entering this finction into the array of 6 element to access the finction based on require ment.In the name of static table.

And we are creating enu type structure to creating the alise number to our function which is easy to carrry out comparison and easy way giving inputs.
We are creating four type of enum in program:

And then we are creating the object name for the 4 enum structures:

And we mentioned that as static type because we can use this any where in the program volatile means it values are changable:
This step is very imporatant we are creating the structure where we are giving the different condition where how to control the landing gears.

We are giving the name to structure as state_table.
we are creating the object named as statemachine 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
In the function part

Inside we are changing the current state to Gear down which means it is 0 in the enum function
And printing the staemachine[0].light status which is in statetable.

It return output like above.
Next step:
It enter into the while loop

In the while loop we have function statetable with the argument of current table.
Now argument as 0 which means current state is geardown:

In the gear down function we are changing the current state to gear down
And getting the pilot inputs if the pilot give inputs as raising anf switch on it means ready to takes off and changing th state as checking before takeooff state
And then printing current indication and light.

Now current state changes to checking before takeoff in current state.
It enters to current state finction which is checking before take off

In the checking before takeoff function we are getting the input from pilot for liver,squat switch.
If the liver is falling it goes to the geardown fuction part.
otherwise when the liver is raising and switch is up the current state is changes to next state that is Raising gear
Print the direction of valve,light,indication statemachine.

NEXT STATE IS RAISING GEAR:

In the raising gear function getting input from the pilot as lever is falling and switch is on it means it change state is check before landing and print the respectine value.If the lever is up then state changes to gear up and following output we will get.

NEXT FUNCTION IS CHECKING BEFORE LANDING

In this function we are pilot input as lever is falling and haydraulis finction as same then state changes to lowering gear and show corresponding output from the statemachine array.
If the lever is falling and hydralics not working it shows the gas pressure system.
THIS THE LAST FUNCTION or STATE

If we are getting input as lever falling and limit switch is on then state is checking before landing and it is output is shown from state machine.
If we are getting input as lever raising and limit switch is off then state is gear down and it is output is shoen from state machine.
If limit switch is off the it goes to lowering gear function itself in.
