Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Question:
Controlling the retraction and extension of Airplane’s landing gear can be implemented using Finite State Machine (FSM)
Answer:
Here in this project the airplanes landing gear system operation need to be implemented using finite state machine. A finite state machine is a computation model with finite number of states.
The landing gear of air craft having two states extended state and retracted state. the landing gear will completly extended at the time of landing and retract into the wheel cup when flying. Any system with finite number of ststes can be considered as finite state machine.
for the landing gear of air craft having 2 ,finite number of states
1.retracted state
2.extended state
The control input for the transition between these two states is by means of gear inside the cockpit operated by the pilot. The leaver that pilot operating from the cockpit having two states, up and down. And one neutral condition is there. when the pilot pull and lock the leaver at the up end the landing gear completly retracted and locked inside the wheel cup of the air craft. like wise when the pilot pulls the gear down then the landing gear goes fromthe retracted state to extended state. simply these can be illustrated as,
| current state | pilots leaver position | next state |
| retracted state | up | retracted state |
| retracted state | down | extended state |
| extended state | up | retracted state |
| extended state | down | extended state |
part from this to under statnd the status of the landing gear indicator lights were also provided inside the cock pit, red , green and an yellow light for indicating the transition of landing gear from retacting to extending and extending to retracting.
also two switches were attched along, limit switch and squat switch.
including all these we can modify our transition table like
| current state | input | next state | indicator | active switch |
| retracted | up | retracted | green | squat switch |
| retracted | down | extended | red | limit switch |
| extended | up | retracted | green | squat switch |
| extended | down | extended | red | limit switch |
once more by marking the on and off positions of indicators and switches the state table becomes,
| current state | input | next state | red indicator | green indicator | limit switch | squat switch |
| retracted | up | retracted | off | on | off | on |
| retracted | down | extended | on | off | on | off |
| extended | up | retracted | off | on | off | on |
| extended | down | extended | on | off | on | off |
by replacing the attributes of the table with 0's and 1's then,
| current state | input | next state | red indicator | green indicator | limit switch | squat switch |
| 0 | 1 | 0 | 0 | 1 | 0 | 1 |
| 0 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 1 | 0 | 1 |
| 1 | 0 | 1 | 1 | 0 | 1 | 0 |
the state digram for the above state table is as,

In this state diagram two states and transition between those two states are given. The two staes were retracted stae of the landing gear or extended state of the landing gear. From one state sy reracted state it may continue in that state itself or by the pulling the hand gear from the cock pit it may transit from retracted stae to extended state. the corresponding inputs an outputs obtained from the state table also indicated inthe state diagram.the transition between states is controlled by means of pilots leaver gear. the position of the pilots hand gear determines the landing gear need to be retracted or extended.
The finite state macine implementation for the above using c code is as shown below,
#include
//system state declaration
typedef enum //type def of state type is defined with two states retracted and extended of aircrafts landing gear
{
retractedstate,
extendedstate
}state_type;
//state table attributes
typedef struct //the state table is declared as struct
{
char* gear[2];//declared character array for down input
char* landinggear[2];//char array for up
int delaytime; //time variable for delay
state_type aircraft_state[2];//user defined variable type enum to ground floor or in firstfloor
char* indicator_light[2];//to indicate current state
}state;
//state table formation as array of structure take directly from the state table
state state_machine[2] = {
{{"UP","DOWN"},{"RETRACTED & LOCKED","EXTENDED & LOCKED"},1,{retractedstate,extendedstate},{"GREEN","RED"}},
{{"UP","DOWN"},{"RETRACTING","EXTENDING"},1,{retractedstate,extendedstate},{"GREEN","RED"}},
}; //array is a string.first element having two strings shows the status of gear in pilot's cockpit..second one for landing gear system.
//third for delay time.,then the state of aircraft and last the indicator light which is on in cockpit
state_type current_state; //current state input is taken
static int control_input;//control input is taken
static int geardown;//control input is taken
int main()// main function of the program
{
current_state = retractedstate; //initialized current state to retracted
while(1) //loop runs infinite no of times
{
printf("\n Enter the control inputs :");// display message in console
fflush(stdout);
scanf("%d",&control_input); //receving the control inputs
printf("\n Position of gear in cockpit - %s", state_machine[current_state].gear[control_input]);//passing the gear position to the state machine to dispalyed in the console
printf("\n Active indicator light in cockpit - %s", state_machine[current_state].indicator_light[control_input]);//passing the indicator light output as per the control input
printf("\n Landing gear status - %s\n", state_machine[current_state].landinggear[control_input]);//passing the landing gear status as per the control input given by the user
current_state = state_machine[current_state].aircraft_state[control_input];//assigning current state value again
}
}
(The screen shot of the code is attached below for reference)