Challenge

Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear

To implement the code for control retraction and extension of airplanes landing gear implementation using Finite State Machine (FSM).

The most efficient algorithm is the FSM, which is a mathematical processing model.

OBJECTIVE:

Controlling the retraction and extension of airplane’s landing gear Using controlling the direction of hydraulic pressure valve.

WORKING:

Basically an airplane has 3 gears for landing: Nose gear, Left gear, Right gear.

Landing gear is the undercarriage of an aircraft that is used for take-off or landing.

For aircraft, the landing gear supports the craft when it is not flying, allowing it to take off, land, and taxi safely.

To decrease air-drag in flight, gears are folded in body of aircraft such gears called ‘retraction gear’.

When aircraft is on run-way the gear is in down(extension) condition.

Once aircraft is in air, gear is retracted means folded in body of aircraft(retraction).

Before landing, gear is put in extension condition (gear down).

Retraction and extension are done by hydraulic mechanism

Basic mechanism is shown in above figure

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.

When the direction of the valve is down then it is landed or gear down position.

Similarly when the direction of valve is up then it is in rising gear or taking off.

When gear is up then light status is off.

Gear is down then the light status is green.

Gear is raising or lowering then the colour of light is red

//code:-

//MAIN.C

/*
* main.c
*
* Created on: 05-Oct-2022
* Author: Arkam
*/

#include<stdio.h>
#include "Header.h"/

static void(*state_table[])(void) = {Gear_Down,Checking_Before_Takeoff,Raising_Gear,Gear_Up,Checking_Before_Landing,Lowering_Gear};

int main()
{
Init_State_Machine();
while(1)
{
state_table[current_state]();
}
}

//HEADER.H

/*
* Header.h
*
* Created on: 05-Oct-2022
* Author: Arkam
*/
#ifndef HEADER_H_
#define HEADER_H_

#include<stdio.h>

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
{
GR_DWN,
CHK_BFR_TKFF,
RSING_GR,
GR_UP,
CHK_BFR_LND,
LWRNG_GR

}State_Type;

typedef enum Switch
{
Open,
Close

}Switch_Status;

typedef enum Pilot_Lever
{

Rising,
Falling,
UP,
DOWN

}Pilot_Lever_Status;

typedef enum Hydraulic_Mechanism
{
Working,
notworking

}Hydraulic_Mechanism_Status;

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;

typedef struct
{
char* current_state_indication;
char* light_status;
char* direction_valve_status;
char* hydraulic_pump_control_status;
}State_Table;

static State_Table State_Machine[6] =
{
{"GearDown","Green","Down","Enabled"},
{"Checking Before Take Off","Green","Down","Enabled"},
{"Raising Gear","Red","Up","Enabled"},
{"Gear Up","Off","Null","Disabled"},
{"Checking Before Landing","Red","Down","Enabled"},
{"Lowering Gear","Green","Down","Enabled"}

};

#endif /* HEADER_H_ */

//INITIAL_STATE.C

#include"Header.h"

void Init_State_Machine()
{
current_state = GR_DWN;
printf("\nState Machine is initialized & Program is in Gear_Down State & Light Status: %s\n",State_Machine[current_state].light_status);
}

//GEAR_DOWN

#include"Header.h"

void Gear_Down(void)
{
current_state = GR_DWN;
printf("\n Enter the Pilot's Lever Position and Squat Switch Status:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch);
if(pilot_lever == Rising && squat_switch == Open)
{
current_state = CHK_BFR_TKFF;
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n", State_Machine[current_state].light_status);

}
else
{
Gear_Down();
}
}

//Checking_Before_Takeoff.C

#include "Header.h"

void Checking_Before_Takeoff()
{
current_state = CHK_BFR_TKFF;
printf("\nEnter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:");
fflush(stdout);
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
printf("\nWait for 2 secs\n");
if(pilot_lever == Falling || squat_switch == Close)
{
Gear_Down();
}
else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)
{
current_state = RSING_GR;
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n", State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n\n", State_Machine[current_state].direction_valve_status);
}
else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == notworking)
{
current_state = RSING_GR;
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n", State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);
}
}

//Raising_Gear.C

#include"Header.h"

void Raising_Gear()
{
current_state = RSING_GR;
printf("\nEnter the Limit Switch Status,Pilots Leaver Status:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&limit_switch);
printf("\nWait for 1 sec\n");
if(pilot_lever == Falling && limit_switch == Open)
{
current_state = CHK_BFR_LND;
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

}
else if(pilot_lever == UP && limit_switch == Close )
{
current_state = GR_UP;
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n", State_Machine[current_state].light_status);
printf("Hydraulic Control for Landing Gear Status:%s\n", State_Machine[current_state].hydraulic_pump_control_status);

}
else
{
Raising_Gear();

}

}

//Gear_Up.C

#include"Header.h"

void Gear_Up()
{
current_state = GR_UP;
printf("\nEnter the Pilot's Lever Position:");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Falling)
{
current_state = CHK_BFR_LND;
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n", State_Machine[current_state].light_status);
printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
}
else
{Gear_Up();

}
}

//Checking_Before_Landing.C

#include "Header.h"
void Checking_Before_Landing()
{
current_state = CHK_BFR_LND;
printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
if(pilot_lever == DOWN && hydraulic_mechanism == Working)
{
current_state = LWRNG_GR;
printf("\nCurrent State:%s\n", State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n", State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);
}
else if(pilot_lever == DOWN && hydraulic_mechanism == notworking)
{
current_state = LWRNG_GR;
printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n", State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);

}
else if(pilot_lever == (UP || Rising || Falling))

{
Checking_Before_Landing();
}
}

//Lowering_Gear.C

#include "Header.h"
void Lowering_Gear()
{
current_state = LWRNG_GR;
printf("\nEnter the Limit Switch Status,Pilots Leaver Status:");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if(limit_switch == Close && pilot_lever == Rising )
{
current_state = CHK_BFR_TKFF;
printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);

}
if(limit_switch == Open && pilot_lever == DOWN)
{
current_state = GR_DWN;
printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
printf("Hydraulic Controlfor Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

}
else
{
Lowering_Gear();
}

}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.