Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Aim:
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.
1.Here controlling the retraction and extension of Airplanes landing gear:
- State_Type
- Switch_Status
- Pilot_Lever_Status
- Hydraulic_Mechanis
- GEAR_DOWN- pilot's lever rising && squat switch open/light=GREEN it is not satified then it will return to Squat Switch close or pilots lever falling to CHECK_BEFORE TAKE OFF
- CHECK_BEFORE TAKE OFF-pilots lever up/Direction valve =UP,light= RED to RAISING_GEAR.
- RAISING_GEAR-limt Switch closed/light OFF, control for landing gear disabled and (it will check the checking before landing also simultaneously)plots lever falling/ light =RED to GEAR_UP and CHECKING_ BEFORE _LANDING.
- GEAR_UP-pilots lever falling /control enabled,light =RED to GEAR_UP and CHECKING_ BEFORE _LANDING.GEAR_UP and
- CHECKING_ BEFORE _LANDING-pilots lever down/direction valve =DOWN to LOWERING_GEAR.
- LOWERING_GEAR-limt switch opened/light =GREEN after it is go again first to GEAR_ DOWN .if it not satisfied then it will go to CHECKING BEFORE TAKE OFF DELAY 3sec
Objective:
- Controlling the direction Valve.
- Controlling the retraction and extension of Airplane’s landing gear.
CONTROLLING DIRECTION VALVE:
- pilot's lever state is lever UP then its will must be direction will be UP
- pilot's lever state is lever DOWN then its will must be direction will be DOWN
CONTROLLING AIRPLANE'S GEAR:
- Limit Switch CLOSED then it is gear is UP
- limit switch OPEND then it is gear is DOWN
A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.
- Direction valve is DOWN then it will be GEAR DOWN
- Direction vave is UP then it will be Raising gear (Takeoff)
- Control of hydraulic pump for the landing gear part is disable then it will be Gear UP(airborne)
- Direction valve is DOWN then it will be Lowering Gear (Landing)
we have to perfroming the many direction valve controlling:
- GEAR_DOWN
- CHECKING_BEFORE TAKE OFF
- RAISING_GEAR
- GEAR_UP
- CHECKING_ BEFORE _LANDING
- LOWERING_GEAR
State Table for each States to control Airoplan's Landing Gear
| State Table for Each state | |||||
| Current State | Light Status | Piloto Lever Position | Hydraulic Mechanism | Gas Presurised Spring System If Hydraulic Mechanism Disabled | |
| State 1 | State 2 | ||||
| Gear Down | Green | Down | Enabled | NULL | NULL |
| Checking Before TakeOff | Green | Down | Enabled | NULL | NULL |
| Raising Gear | Red | Up | Enabled | Disabled | Enabled |
| Gear Up | OFF | NULL | Disabled | NULL | NULL |
| Checking Before Landing | Red | Down | Enabled | NULL | NULL |
| Lowering Gear | Green | Down | Enabled | Disabled | Enabled |
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.
Deliverables of this project:
- State Machine Initiated and Program is in Gear Down state: GearDown and Light Status : Green
- Enter the Pilot's Lever Position and Squat Switch Status: 2 0
Enter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status: 0 0 1
Enter the Limit Switch Status, Pilot's Lever Position :1 0
Enter the Pilot's Lever Position:3
Enter the Pilot's Lever Position and Status of Hydraulic Mechanism:1 0
Enter the Limit_Switch Status,Pilot_Lever Status : 0 1

Expected Outcomes:
| State Table | ||||||
| Current State | Condition | Input | Next State | |||
| Pilot lever | Squat Switch | Limit Switch | Hydraulic Mechanism | |||
| Gear Down | IF | Raising | Open | Check Before TakeOff | ||
| ELSE | Gear Down Function | |||||
| Checking Before Take Off | If | Up | Open | working | Raising Gear | |
| ELSE IF | Up | Open | Not Working | Raising Gear | ||
| Raising Gear | IF | Falling | Open | Check Before Take Landing | ||
| ELSE IF | Up | Close | Gear Up | |||
| Else | Raising Gear Function | |||||
| Gear Up | IF | Falling | Check Before Landing | |||
| ELSE | Gear Up Function | |||||
| Checking Before landing | IF | Down | Working | Lowering Gear | ||
| ElSE IF | Down | Not Working | Lowering Gear | |||
| ELSE | Checking Before Landing Function | |||||
| Lowering Gear | IF | Raising | Close | Check Before TakeOff | ||
| IF | Down | Open | Gear Down | |||
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.
Gear_Down(0):
State Machine is initialized & Program is in Gear_Down State & Light_Status : Green
Enter the Pilot's Lever Position and Squat Switch Status:2 0
Current State:Checking Before Take Off
Light Status:Green
CHECKING_Before_TakeOff(1):
Enter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status: 0 0 1
Wait for 3 secs
Current State: Raising Gear
Light Status:Red
Direction Value Status:Up
Raising_Gear(2):
Enter the Limit Switch Status, Pilot's Lever Position :1 0
Wait for 1 sec
Current State: Gear Up
Light Status:Off
Hydraulic Control for Landing Gear Status:Disabled
Gear_Up(3):
Enter the Pilot's Lever Position:3
Current State:Checking Before Landing
Light Status:Red
Hydraulic Control for Landing Gear Status:Enabled
Checking_Before_Landing(4):
Enter the Pilot's Lever Position and Status of Hydraulic Mechanism: 1 0
Current State : Lowering Gear
Light Status:Green
Direction Valve Status:Down
Gas Pressurized Spring System Status:Enabled
Lowering_Gear(5):
Enter the Limit_Switch Status,Pilot_Lever Status : 0 1
Current State: Checking Before Take Off
Light Status:Green
Program for controlling the retraction and extension of Airplane’s landing gear is:
Main file
/*
* Gear.c
*
* Created on: Dec 19, 2022
* Author: laxma
*/
#include<stdio.h>
#include"states.h"
static void(*state_table[])(void) = {Gear_Down,Checking_Before_TakeOff,Raising_Gear,Gear_Up,Checking_Before_Landing,Lowering_Gear};
int main()
{
Initiate_State_Machine();
while(1) /*While loop */
{
state_table[current_state]();
}
}
Sub file is:
/*
* states.c
*
* Created on: Dec 19, 2022
* Author: laxma
*/
#include<stdio.h> /* including standard IO library */
#include"states.h" /* calling states.h file */
void Initiate_State_Machine() /*Function declaration */
{
current_state = GearDown;
printf("\nState Machine Initiated and Program is in Gear Down state: %s\n",State_Machine[current_state].CurrentStateIndication);
printf("\n Light Status : %s\n",State_Machine[current_state].Light);
}
void Gear_Down()
{
current_state = GearDown;
printf("\n Enter the Pilot Lever position and Squat Switch: ");
fflush(stdout);
scanf("%d %d",&Pilot_LeverStatus,&Squat_Switch);
if (Pilot_LeverStatus == Raising && Squat_Switch == Open)
{
current_state = CheckBeforeTakeOff;
printf("\nCurrent State: %s\n",State_Machine[current_state].CurrentStateIndication);
printf("\n Switch State :%s\n",State_Machine[current_state].Light);
}
else
{
Gear_Down();
}
}
void Checking_Before_TakeOff()
{
current_state = CheckBeforeTakeOff;
printf("\nEnter the pilot position, Squat Switch status and Hydraulic mechanism status: ");
fflush(stdout);
scanf("%d %d %d",&Pilot_LeverStatus, &Squat_Switch, &HM_Status);
printf("\nWait for 3 seconds\n");
if (Pilot_LeverStatus == Falling || Squat_Switch == Close)
{
Gear_Down();
}
else if (Pilot_LeverStatus = Up && Squat_Switch == Open && HM_Status == Working)
{
current_state = RaisingGear;
printf("\nCurrent Status : %s\n",State_Machine[current_state].CurrentStateIndication);
printf("Light status : %s\n",State_Machine[current_state].Light);
printf("\n Direction Valve Status : %s\n",State_Machine[current_state].DirectionValve);
printf("\nGAs Pressurized spring system status : %s\n",State_Machine[current_state].GasPressurizedSpringSystem[HM_Status]);
}
else if (Pilot_LeverStatus == Up && Squat_Switch == Open && HM_Status == Not_Working)
{
current_state = RaisingGear;
printf("\nCurrent Status : %s\n",State_Machine[current_state].CurrentStateIndication);
printf("\nDirection Valve Status : %s\n",State_Machine[current_state].DirectionValve);
printf("\nGAs Pressurized spring system status : %s\n",State_Machine[current_state].GasPressurizedSpringSystem[HM_Status]);
}
}
void Raising_Gear()
{
current_state = RaisingGear;
printf("\n Enter the limit Switch status and Pilot Lever position : ");
fflush(stdout);
scanf("%d %d",&Limit_Switch, &Pilot_LeverStatus);
if (Pilot_LeverStatus == Falling && Limit_Switch == Open)
{
current_state = CheckBeforeLanding;
printf("\nCurrent Status : %s\n",State_Machine[current_state].CurrentStateIndication);
printf("\n Light Status : %s\n",State_Machine[current_state].Light);
printf("Hydraulic pump Control status : %s\n",State_Machine[current_state].LandingGearHydraulicControl);
}
else if (Limit_Switch == Close && Pilot_LeverStatus == Up)
{
current_state = GearUp;
printf("\nCurrent Status : %s\n",State_Machine[current_state].CurrentStateIndication);
printf("\nLight Status : %s\n",State_Machine[current_state].Light);
printf("\nHydraulic Status for Landing Gear : %s\n",State_Machine[current_state].LandingGearHydraulicControl);
}
else
{
Raising_Gear();
}
}
void Gear_Up()
{
current_state = GearUp;
printf("\nEnter Pilot Lever position : ");
fflush(stdout);
scanf("%d",&Pilot_LeverStatus);
if (Pilot_LeverStatus == Falling)
{
current_state = CheckBeforeLanding;
printf("\nCurrent Status : %s\n",State_Machine[current_state].CurrentStateIndication);
printf("\nLight Status : %s\n",State_Machine[current_state].Light);
printf("\nHydraulic control for Landing Gear status : %s\n",State_Machine[current_state].LandingGearHydraulicControl);
}
else
{
Gear_Up();
}
}
void Checking_Before_Landing()
{
current_state = CheckBeforeLanding;
printf("\nEnter the Pilot Lever position and Hydraulic Mechanism: \n");
fflush(stdout);
scanf("%d %d",&Pilot_LeverStatus, &HM_Status);
if (Pilot_LeverStatus == Down && HM_Status == Working)
{
current_state = LoweringGear;
printf("\nCurrent Status : %s\n",State_Machine[current_state].CurrentStateIndication);
printf("\nLight Status : %s\n",State_Machine[current_state].Light);
printf("\nDirection Valve : %s\n",State_Machine[current_state].DirectionValve);
printf("\nGas pressurized Spring system status : %s\n",State_Machine[current_state].GasPressurizedSpringSystem[HM_Status]);
}
else if (Pilot_LeverStatus == Down && HM_Status == Not_Working)
{
current_state = LoweringGear;
printf("\nCurrent Status : %s\n",State_Machine[current_state].CurrentStateIndication);
printf("\nLight Status : %s\n",State_Machine[current_state].Light);
printf("\nDirection Valve : %s\n",State_Machine[current_state].DirectionValve);
printf("\nGas pressurized Spring system status : %s\n",State_Machine[current_state].GasPressurizedSpringSystem[HM_Status]);
}
else //(Pilot_LeverStatus == Up || Raising || Falling)
{
Checking_Before_Landing();
}
}
void Lowering_Gear()
{
current_state = LoweringGear;
printf("Enter Limit Switch Status and Pilot Lever Status: ");
fflush(stdout);
scanf("%d %d",&Limit_Switch, &Pilot_LeverStatus);
if (Pilot_LeverStatus == Raising || Limit_Switch == Close)
{
current_state = CheckBeforeTakeOff;
printf("\nCurrent Status : %s\n",State_Machine[current_state].CurrentStateIndication);
printf("\nLight Status : %s\n",State_Machine[current_state].Light);
}
if (Limit_Switch == Open || Pilot_LeverStatus == Down)
{
current_state = GearDown;
printf("\nCurrent Status : %s\n",State_Machine[current_state].CurrentStateIndication);
printf("\nLight Status : %s\n",State_Machine[current_state].Light);
printf("\nHydraulic control for Landing Gear status : %s\n",State_Machine[current_state].LandingGearHydraulicControl);
}
else
{
Lowering_Gear();
}
}
Header File is:
/*
* states.h
*
* Created on: Dec 19, 2022
* Author: laxma
*/
#ifndef STATES_H_
#define STATES_H_
#include<stdio.h> /* including standard IO library */
void initiate_State_machine(); /* Declaring fuctions */
void Gear_Down();
void Checking_Before_TakeOff();
void Raising_Gear();
void Gear_Up();
void Checking_Before_Landing();
void Lowering_Gear();
typedef enum State /* A type def means declaring the alternative names */
{
GearDown, /*Calling Different States */
CheckBeforeTakeOff,
RaisingGear,
GearUp,
CheckBeforeLanding,
LoweringGear
}State_Type;
typedef enum Switch
{
Open, /* Calling switch state */
Close
}Switch_Status;
typedef enum Pilot
{
Up, /* Calling Pilot Lever states */
Down,
Raising,
Falling
}Pilot_Lever;
typedef enum Mechanism
{
Working, /* Calling Hydraulic Mechanism states */
Not_Working
}Hydraulic_Mechanism;
static volatile Switch_Status Squat_Switch; /* A function that has a scope that is limited to its object file */
static volatile Switch_Status Limit_Switch;
static volatile Pilot_Lever Pilot_LeverStatus;
static volatile Pilot_Lever Direction_Valve;
static volatile Hydraulic_Mechanism HM_Status;
State_Type current_state;
typedef struct Table /* Calling status of struct */
{
char* CurrentStateIndication;
char* Light;
char* DirectionValve;
char* GasPressurizedSpringSystem[2];
char* LandingGearHydraulicControl;
}State_Table;
static State_Table State_Machine[6] = { /* Calling State Table */
{"GearDown","Green","Down","Enabled","NULL","NULL"},
{"ChecKBeforetakeOff","Green","Down","Enabled","NULL","NULL"},
{"RaisingGear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"GearUp","Off","NULL","Disabled","NULL","NULL"},
{"CheckBeforeLanding","Red","Down","Enabled","NULL","NULL"},
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
#endif /* STATES_H_ */
Make File is:
LandingGear: Gear.c states.c states.h
gcc Gear.c states.c states.h -o CurrentState -I.
OutPut:
D:\BHANOTH LAXMAN\BHANOTH LAXMAN\NOTES AND BOOKS\SKILL LYNC\3. Embedded C\embadded\Challenges\Project 2\Project 2>gdb CurrentState.exe
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from D:\BHANOTH LAXMAN\BHANOTH LAXMAN\NOTES AND BOOKS\SKILL LYNC\3. Embedded C\embadded\Challenges\Project 2\Project 2\CurrentState.exe...done.
(gdb) r
Starting program: D:\BHANOTH LAXMAN\BHANOTH LAXMAN\NOTES AND BOOKS\SKILL LYNC\3. Embedded C\embadded\Challenges\Project 2\Project 2/CurrentState.exe
[New Thread 21128.0x6520]
[New Thread 21128.0x5bb4]
State Machine Initiated and Program is in Gear Down state: GearDown
Light Status : Green
Enter the Pilot Lever position and Squat Switch: 0 0
Enter the Pilot Lever position and Squat Switch: 0 1
Enter the Pilot Lever position and Squat Switch: 1 0
Enter the Pilot Lever position and Squat Switch: 1 1
Enter the Pilot Lever position and Squat Switch: 2 1
Enter the Pilot Lever position and Squat Switch: 3 0
Enter the Pilot Lever position and Squat Switch: 3 1
Enter the Pilot Lever position and Squat Switch: 2 1
Enter the Pilot Lever position and Squat Switch: 2 0
Current State: ChecKBeforetakeOff
Switch State :Green
Enter the pilot position, Squat Switch status and Hydraulic mechanism status: 0 0 0
Wait for 3 seconds
Enter the pilot position, Squat Switch status and Hydraulic mechanism status: 0 0 1
Wait for 3 seconds
Current Status : RaisingGear
Direction Valve Status : Up
GAs Pressurized spring system status : Disabled
Enter the limit Switch status and Pilot Lever position : 1 0
Current Status : GearUp
Light Status : Off
Hydraulic Status for Landing Gear : NULL
Enter Pilot Lever position : 1 0
Enter Pilot Lever position :
Enter Pilot Lever position : 0 1
Enter Pilot Lever position :
Enter Pilot Lever position : 1 1
Enter Pilot Lever position :
Enter Pilot Lever position : 3
Current Status : CheckBeforeLanding
Light Status : Red
Hydraulic control for Landing Gear status : NULL
Enter the Pilot Lever position and Hydraulic Mechanism:
1 0
Current Status : LoweringGear
Light Status : Green
Direction Valve : Down
Gas pressurized Spring system status : Enabled
Enter Limit Switch Status and Pilot Lever Status: 0 1
Current Status : GearDown
Light Status : Green
Hydraulic control for Landing Gear status : NULL
Enter the Pilot Lever position and Squat Switch: 2 0
Current State: ChecKBeforetakeOff
Switch State :Green
Enter the pilot position, Squat Switch status and Hydraulic mechanism status: 0 0 1
Wait for 3 seconds
Current Status : RaisingGear
Direction Valve Status : Up
GAs Pressurized spring system status : Disabled
Enter the limit Switch status and Pilot Lever position : 0 3
Current Status : CheckBeforeLanding
Light Status : Red
Hydraulic pump Control status : NULL
Enter the Pilot Lever position and Hydraulic Mechanism:
0 0
Enter the Pilot Lever position and Hydraulic Mechanism:
2 0
Enter the Pilot Lever position and Hydraulic Mechanism:
3 0
Enter the Pilot Lever position and Hydraulic Mechanism:
1 1
Current Status : LoweringGear
Light Status : Green
Direction Valve : Down
Gas pressurized Spring system status : Disabled
Enter Limit Switch Status and Pilot Lever Status: [New Thread 21128.0x20a0]
1 2
Current Status : ChecKBeforetakeOff
Light Status : Green