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 :
Ans:
Overview of the Project: In this project, a Finite State Machine is used to manage the retraction and extension of an airplane's landing gear (FSM). The most efficient algorithm is the FSM, which is a mathematical processing model. 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.
our target is:
1. Valve's direction can be controlled.
2. Controlling the retraction and extension of the landing gear on an aeroplane.
Explanation:
Landing Gear system is one of the critical subsystems of an aircraft and is often configured along with the aircraft structure because of its substantial influence on
the aircraft structural configuration itself. Landing gear detail design is taken up early in the aircraft design cycle due to its long product development cycle time. The need to design landing gear with minimum weight, minimum volume, reduced life cycle cost, and short development cycle time, poses many challenges to landing gear designers and practitioners. These challenges have advanced AI technologies, materials, analysis methods, processes and production methods. Various design and analysis tools have been developed over the years and new ones are still being developed.
The purpose of the landing gear in an aircraft is to provide a suspension system during take-off and landing. It is designed to absorb and dissipate the kinetic energy of landing impact, thereby reducing the impact loads transmitted to the air-frame. The landing gear also facilitates braking of the aircraft using a wheel braking system and provides directional control of the aircraft on ground using a wheel steering system. It is often made retractable to minimize the aerodynamic drag on the aircraft while flying. The landing gear design takes into account various requirements of strength, stability, stiffness, ground clearance, control and damping under all possible ground attitudes of the aircraft. These requirements are stipulated by the Air worthiness Regulations to meet operational requirements and safety. The landing gear should occupy minimum volume in order to reduce the storage space requirement in the aircraft. Further, weight should be at minimum to increase the performance of the aircraft. The service life of the landing gears should be same as that of the aircraft.
A Landing Gear system comprises of many structural and system components. The structural components include Main fitting, Shock absorber, Bogie beam/ Trailing arm, Axle, Torque links, Drag/ Side braces, Retraction actuator, Down lock mechanism, Up lock, Wheel, Tire etc. The system components are Brake unit, Anti-skid system, retraction system components. Typical Main Landing Gear (MLG) and Nose Landing Gear (NLG). The nose gear will have additional elements like steering actuator and steering mechanism.
code:
#include<stdio.h> // we have to include stdio.h (standard input and output library for C language) //
void Initiate_State_Machine(); //* void function which does not return any value directly to the calling program *//
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 //* Redefine the name of an existing variable type *//
{
GEAR_DOWN,
CHECKING_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECK_BEFORE_LANDING,
LOWERING_GEAR,
}State_Type;
typedef enum Switch //* Redefine the name of an existing variable type *//
{
open,
close,
on,
off,
}Switch_status;
typedef enum pilot_lever //* Redefine the name of an existing variable type *//
{
Raising,
falling,
up,
down,
}pilot_lever;
typedef enum hydraulic_mechanism //* Redefine the name of an existing variable type *//
{
working,
not_working
}hydraulic_mechanism;
//* The volatile keyword is intended to prevent the compiler from applying any optimizations on objects that can change in ways that cannot be determined by the compiler *//
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 //* Redefine the name of an existing variable type *//
{
char* current_state_indication;
char* light;
char* direction_valve_status;
char* landing_gear_hydraulic_control;
char* Gas_Pressurized_Spring_system_status;
}State_Table;
//* Array declaration *//
static State_Table State_Machine[6]={{"GearDown","Green","Down","Enabled","Good"},
{"CheckingBeforeTakeOFF","Green","Down","Enabled","Good"},
{"RaisingGear","Red","Up","Enabled","Good"},
{"GearUp","Off","NULL","Disabled","Good"},
{"CheckBeforeLanding","Red","Down","Enabled","Good"},
{"LoweringGear","Green","Down","Enabled","Good"}
};
int main() //* main function code *//
{ //* In Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear *//
Initiate_State_Machine();
while(1)
{
Statetable[current_state]();
}
}
void GearDown(void) //* void function prototype *//
{
current_state=GEAR_DOWN; //* present state is gear down *//
printf("Enter the status of pilot's lever and squat switch: "); //* print the input *//
fflush(stdout); //* clearing output stream buffer *//
scanf("%d %d",&pl,&squat_switch); //* storing the value *//
//* using if loop to check wheather pilot lever is rising or falling and squat switch is open or close *//
if(pl==Raising && squat_switch==open)
{
current_state=CHECKING_BEFORE_TAKEOFF; //* next state is checking before takeoff *//
printf("current state: %s\n",State_Machine[current_state].current_state_indication); //* print the input *//
printf("Light is : %s\n", State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);//* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
else
{
GearDown();
}
}
//* CheckingBeforeTakeOFF *//
void CheckingBeforeTakeOFF(void) //* void function prototype *//
{
current_state=CHECKING_BEFORE_TAKEOFF; //* present state is checking before takeoff *//
printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism: "); //* print the input *//
fflush(stdout); //* clearing output stream buffer *//
scanf("%d %d %d",&pl,&squat_switch,&hm); //* storing the value *//
//* using if loop to check wheather pilot lever is rising or falling and squat switch is open or close *//
if(pl==falling&&squat_switch==close)
{
current_state=GEAR_DOWN; //* next state is back to gear down *//
printf("current state: %s\n",State_Machine[current_state].current_state_indication);//* print the input *//
printf("Light is : %s\n", State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);//* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
//* using else if loop to check wheather pilot lever is up or down and squat switch is open or close and hydraulic controls are working or not working *//
else if(pl==up && squat_switch==open && hm==working)
{
current_state=RAISING_GEAR; //* next state is raising gear *//
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);//* print the input *//
printf("Light is: %s\n",State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);//* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
//* using else if loop to check wheather pilot lever is up or down and squat switch is open or close and hydraulic controls are working or not working *//
else if(pl==up && squat_switch==open && hm==not_working)
{
current_state=RAISING_GEAR; //* next state is raising gear *//
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);//* print the input *//
printf("Light is: %s\n",State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);//* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
else
{
CheckingBeforeTakeOFF();
}
}
//* RaisingGear *//
void RaisingGear(void) //* void function prototype *//
{
current_state=RAISING_GEAR; //* present state is raising gear *//
printf("Enter the status of pilot's lever and limit switch: "); //* print the input *//
fflush(stdout); //* clearing output stream buffer *//
scanf("%d %d",&pl,&limit_switch); //* storing the value *//
//* using if loop to check wheather pilot lever is raising or falling and limit switch is on or off *//
if(pl==falling && limit_switch==on)
{
current_state=CHECK_BEFORE_LANDING; //* next state is check before landing *//
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);//* print the input *//
printf("Light is: %s\n",State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);//* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
//* using else if loop to check wheather pilot lever is raising or falling and limit switch is on or off *//
else if(pl==Raising && limit_switch==off)
{
current_state=GEAR_UP; //* next state is gear up *//
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);//* print the input *//
printf("Light is: %s\n",State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);//* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
else
{
RaisingGear();
}
}
//* GearUp *//
void GearUp(void) //* void function prototype *//
{
current_state=GEAR_UP; //* present state is gear up *//
printf("Enter the status of pilot's lever: "); //* print the input *//
fflush(stdout); //* clearing output stream buffer *//
scanf("%d",&pl); //* storing the value *//
//* using if loop to check wheather pilot lever is raising or falling *//
if(pl==falling)
{
current_state=CHECK_BEFORE_LANDING; //* next state is check before landing *//
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);//* print the input *//
printf("Light is: %s\n",State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);//* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
else
{
GearUp();
}
}
//* CheckBeforeLanding *//
void CheckBeforeLanding(void) //* void function prototype *//
{
current_state=CHECK_BEFORE_LANDING; //* present state is check before landing *//
printf("Enter the status of pilot's lever and hydraulic mechanism status: "); //* print the input *//
fflush(stdout); //* clearing output stream buffer *//
scanf("%d %d",&pl,&hm); //* storing the value *//
//* using if loop to check wheather pilot lever is up or down and hydraulic controls are working or not working *//
if(pl==down && hm==working)
{
current_state=LOWERING_GEAR; //* next state is lowering gear *//
printf("Current State: %s\n",State_Machine[current_state].current_state_indication); //* print the input *//
printf("Light is: %s\n",State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status); //* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
//* using else if loop to check wheather pilot lever is up or down and hydraulic controls are working or not working *//
else if(pl==down && hm==not_working)
{
current_state=LOWERING_GEAR; //* next state is lowering gear *//
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);//* print the input *//
printf("Light is: %s\n",State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);//* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
//* using else if loop to check wheather pilot lever is rising or falling *//
else if(pl==(Raising))
{
CheckBeforeLanding();
}
}
//* LoweringGear *//
void LoweringGear(void) //* void function prototype *//
{
current_state=LOWERING_GEAR; //* present state is lowering gear *//
printf("Enter the status of pilot's lever and limit switch: "); //* print the input *//
fflush(stdout); //* clearing output stream buffer *//
scanf("%d %d",&pl,&limit_switch); //* storing the value *//
//* using if loop to check wheather pilot lever is rising or falling and limit switch is on or off *//
if(pl==Raising && limit_switch==off)
{
current_state=CHECKING_BEFORE_TAKEOFF; //* next state is checking before takeoff *//
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);//* print the input *//
printf("Light is: %s\n",State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);//* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
//* using else if loop to check wheather pilot lever is up or down and limit switch is on or off *//
else if(pl==down && limit_switch==on)
{
current_state=GEAR_DOWN; //* next state is gear down *//
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);//* print the input *//
printf("Light is: %s\n",State_Machine[current_state].light); //* print the input *//
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status); //* print the input *//
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);//* print the input *//
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control); //* print the input *//
}
//* using if loop to check wheather limit switch is on or off *//
if(limit_switch==off)
{
LoweringGear();
}
}
//* Initiate_State_Machine *//
void Initiate_State_Machine() //* void function prototype *//
{
current_state==GEAR_DOWN; //* present state is gear down *//
printf("The Finite State Machine is Initialized and current the program is in""GearDown State & Light is: %s\n",State_Machine[current_state].light); //* print the input *//
}
Inputs:
- 0 0
- 2 0 0
- 0 3
- 1
- 3 0
- 3 2
- 0 0
- 2 0 1
- 1 2
- 3 1
- 0 3
- 0 3
- 3 2
- 0 0