Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Aim
To create a code for 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.
Overview
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_Mechanism
Goals
Valve's direction can be controlled.
Controlling the retraction and extension of the landing gear on an aeroplane.
The code for the project is shown below.
Header file
/*
* state.h
*
* Created on: 02-Oct-2022
* Author: Prave
*/
#ifndef STATE_H_
#define STATE_H_
#include //header file
#include //header file
//function declaration
void Init_State_Machine();
void Gear_Down();
void Checking_Before_Takeoff();
void Raising_Gear();
void Gear_Up();
void Checking_Before_Landing();
void Lowering_Gear();
typedef enum State //declares an alternative name as state
{
GR_DOWN, //here calling the different state
CHK_BFR_TKOFF,
RISING_GR,
GEAR_UP,
CHK_BFR_LAND,
LOWERING_GR
}State_Type;
typedef enum Switch //declares an alternative name as switch
{
Open, //here calling the different switch
Close
}Switch_Status;
typedef enum Pilot_Lever //declares an alternative name as pilot lever
{
Raising, //here calling the different pilot lever
Falling,
UP,
DOWN
}Pilot_Lever_Status;
typedef enum Hydraulic_Mechanism //declares an alternative name as hydraulic mechnism
{
Working, //here calling the different hydraulic mechanism
Malfunctioning
}Hydraulic_Mechanism_Status;
//A function that has a scope that is limited to its object file
static volatile Switch_Status Squat_Switch;
static volatile Switch_Status limit_switch;
static volatile Pilot_Lever_Status pilot_lever;
static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;
State_Type current_state; //current state is the state type
typedef struct //declaration of structure using typedef
{
char* current_state_indication;
char* light_status;
char* direction_valve_status;
char* Landing_Gear_Hydraulic_Control_status;
char* gas_pressurized_spring_system_status[2];
}State_Table;
//calling the state_ Table
static State_Table State_Machine[6]={
{"GearDown","Green","Down","Enabled",{NULL,NULL}},
{"Checking Before Take Off","Green","Down","Enabled",{NULL,NULL}},
{"Rising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"Gear Up","Off","Null","Disabled",{NULL,NULL}},
{"Checking Before Landing","Red","Down","Enabled",{NULL,NULL}},
{"Lowerig Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
#endif /* STATE_H_ */
C code
/*
* airplane.c
*
* Created on: 02-Oct-2022
* Author: Prave
*/
#include "State.h" //state header file
#include //preprocessor header file
#include
//using state table the condition controlling the retraction and extension of airoplane's landig gear
static void(*state_table[])(void) = {Gear_Down,Checking_Before_Takeoff,Raising_Gear,Gear_Up,
Checking_Before_Landing,Lowering_Gear};
// main function
int main()
{
Init_State_Machine(); //declare initial state machine
//while loop executed
while(1)
{
state_table[current_state](); // current state is the declare in the state table
}
}
void Init_State_Machine() //initial state machine condition
{
current_state = GR_DOWN; //current state is gear down
printf("\n State Machine is initialized & Program is in Gear_Down_state & Light_Status :%s\n",State_Machine[current_state].light_status);
//dispaly state machine is initialized and gear down state with status of light
}
void Gear_Down(void) //gear down condition
{
current_state = GR_DOWN; //current state is gear down
printf("\nEnter the pilot's Lever Position, Squat Switch Status "); //writes to console enter the pilot lever position and //squat switch status
fflush(stdout); //to clear standard out console buffer
scanf("%d %d",&pilot_lever, &Squat_Switch); //reads to console pilot lever and squat switch
//if pilot lever is raising and switch is open
if(pilot_lever == Raising && Squat_Switch == Open)
{
current_state = CHK_BFR_TKOFF; //current state is check before takeoff
printf("\n Current State :%s\n",State_Machine[current_state].current_state_indication); //print current state
printf("\nLight State :%s\n",State_Machine[current_state].light_status); //print light status
}
else
{
Gear_Down(); //gear down statement
}
}
void Checking_Before_Takeoff() //checking before takeoff condition
{
current_state = CHK_BFR_TKOFF; //current state is checking before takeoff
printf("\n Enter the pilot's lever Position,Squat Switch Status and Hydraulic Mechanism Status :"); // writes to console //dispaly enter pilot lever position,switch squat, hydraulic mechanism status
fflush(stdout); //to clear standard out console buffer
scanf("%d %d %d",&pilot_lever,&Squat_Switch,&hydraulic_mechanism); //reads to console poilot lever, squat switch, //hydraulic mechanism
printf("\n Wait for 2 sec\n"); //dispaly wiat for two sec
if(pilot_lever == Falling || Squat_Switch == Close) //if pilot lever is falling then switch is open
{
Gear_Down(); //gear down condition
}
else if(pilot_lever == UP && Squat_Switch == Open && hydraulic_mechanism == Working) //lever is up , switch is //open and hydraulic mechanism is working
{
current_state = RISING_GR; //current state is rising gear
printf("\n Current State :%s\n",State_Machine[current_state].current_state_indication); //print current state
printf("\n Light Status :%s\n",State_Machine[current_state].light_status); //print light status
printf("Direction valve Staus :%s\n",State_Machine[current_state].direction_valve_status); //print direction value //status
}
else if(pilot_lever == UP && Squat_Switch == Open && hydraulic_mechanism == Malfunctioning) //pilot lever is //up,switch is open and hyd mechanism is malfunctioning
{
printf("Light Status:%s\n", State_Machine[current_state].light_status); //print light status
printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_valve_status); //print direction valve //status
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_system_status[hydraulic_mechanism]); //print //gas pressurized spring system status
}
}
void Raising_Gear() // raising gear operation
{
current_state = RISING_GR; // current state is raising gear
printf("\n Enter the Limit Switch Status,Pilots Lever Status:"); //writes to console enter limit switch and pilot lever status
fflush(stdout); //to clear standard out console buffer
scanf("%d %d",&limit_switch,&pilot_lever); //reads to console limit switch ,pilot lever
printf("\n Wait for 1 sec\n"); //display wait for 1 sec
if(pilot_lever == Falling && limit_switch == Open) //if pilot lever is falling then limit switch is open
{
current_state=CHK_BFR_LAND; //current state is checking before landing
printf("\n Current State :%s\n",State_Machine[current_state].current_state_indication); //print current state
printf("\n Light State :%s\n",State_Machine[current_state].light_status); //print light status
printf("Hydraulic Control for Landing Gear State :%s\n\n",State_Machine[current_state].Landing_Gear_Hydraulic_Control_status); //print landing grar hydraulic control //status
}
else if(limit_switch == Close && pilot_lever == UP) //limit switch close then poilot lever is open
{
current_state = GEAR_UP; //current state is gear up
printf("\n Current State :%s\n",State_Machine[current_state].current_state_indication); // print current state
printf("\n Light State :%s\n",State_Machine[current_state].light_status); //print light status
printf("\n Hydraulic Control for landing Gear Status :%s\n",State_Machine[current_state].Landing_Gear_Hydraulic_Control_status); //print landing grar hydraulic control //status
}
else
{
Raising_Gear(); //raising gear operation is perform
}
}
void Gear_Up() //gear up condition
{
current_state = GEAR_UP; //current state is gear up
printf("\n Enter the Pilot's lever Position :"); //writes to console display enter pilot lever position
fflush(stdout); //to clear standard out console buffer
scanf("%d",&pilot_lever); //reads to console pilot lever
if(pilot_lever == Falling) //if pilot lever is falling
{
current_state=CHK_BFR_LAND; //current state is checking before landing
printf("\n Current State :%s\n",State_Machine[current_state].current_state_indication); //print current state
printf("\nLight Status :%s\n",State_Machine[current_state].light_status); //print light status
printf("Hydraulic Control for Landing Gear Status :%s\n",State_Machine[current_state].Landing_Gear_Hydraulic_Control_status); //print landing grar hydraulic control //status
}
else
{
Gear_Up(); //gear up operation is perform
}
}
void Checking_Before_Landing() //checking before landing condition
{
current_state = CHK_BFR_LAND; // current state is checking before landing
printf("\n Enter the Pilot's Lever Position and Hydraulic Mechanism Status :"); //writes to console enter the pilot lever //position and hydraulic mechanism
fflush(stdout); //to clear standard out console buffer
scanf("%d %d",&pilot_lever, &hydraulic_mechanism); //reads to console pilot lever and hydraulic mechanism
if(pilot_lever == DOWN && hydraulic_mechanism == Working) //if pilot lever is down then hydraulic mechanism is //working
{
current_state = LOWERING_GR; //current state is lowering gear
printf("\n Current State:%s\n",State_Machine[current_state].current_state_indication); //print current state
printf("\nLight State: %s\n",State_Machine[current_state].light_status); //print light status
printf("Direction Valve Status:%s\n\n",State_Machine[current_state].direction_valve_status); //print direction valve //status
}
else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning) //pilot lever is down then hydraulic //mechanism is malfunctioning
{
current_state = LOWERING_GR; //current state is lowering gear
printf("\n Current State :%s\n",State_Machine[current_state].current_state_indication); //print current state
printf("\n Light Status :%s\n",State_Machine[current_state].light_status); //print light status
printf("Direction Valve Status :%s\n",State_Machine[current_state].direction_valve_status); //print direction valve //status
printf("Gas Pressurized Spring System Status :%s\n",State_Machine[current_state].gas_pressurized_spring_system_status[hydraulic_mechanism]); //print gas //pressurized spring system status
}
if(pilot_lever == (UP||Raising||Falling)) //if pilot lever is up,raising or falling
{
Checking_Before_Landing(); //landing gear operation is perform
}
}
void Lowering_Gear() //lowering gear condition
{
current_state = LOWERING_GR; //current state is lowering gear
printf("\n Enter the limit switch Squat Status.pilot's lever Position :"); //writes to console display enter the limit switch //status and pilot switch status
fflush(stdout); //to clear standard out console buffer
scanf("%d %d",&pilot_lever,&limit_switch); //reads to console pilot lever ,limit switch
if(limit_switch == Close && pilot_lever == Raising) //if limit switch is close then pilot lever is raising
{
current_state = CHK_BFR_TKOFF; //current state is checking before takeoff
printf("\n Current State :%s\n",State_Machine[current_state].current_state_indication); //print current state
printf("\n Light Status :%s\n",State_Machine[current_state].light_status); //print light status
}
if(limit_switch == Open && pilot_lever == DOWN) //if limit switch is open then pilot lever is down
{
current_state = GR_DOWN; //current state is gear down
printf("\n Current State :%s\n",State_Machine[current_state].current_state_indication); //print current state
printf("\n Light Status :%s\n",State_Machine[current_state].light_status); //print light_status
printf("Hydraulic Control For Landing Gear Status :%s\n",State_Machine[current_state].Landing_Gear_Hydraulic_Control_status); //print //Landing_Gear_Hydraulic_Control_status
}
else
{
Lowering_Gear(); //lowering gear operation is perform
}
}
Output

Conclussion
We have created a program for 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.
The cproject file is attached below