Challenge

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

AIM:-To create a program controlling the retraction and extension of Airplane’s landing gear can be implemented using Finite State Machine (FSM).

Condition of State:-

There are 6 different satate

1.Gear down(initial state)->Checking before Take Off->Rising Gear->Gear Up->Checking Before Landing->Lowering Gear(Final)

The airplane has 3 Gears

1.Left Gear

2.Right Gear

3.Nose Gear

-Every leg of the gear has one limit switch.Nose gear has one extra Squat Switch to determine whether the airplane is in ground or not.

A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.

-Every gear has one light. According to the state of the gear,color of light is changing .(Green & Red)

There is a hydraulic pump which is exerting pressure to the gears to bring it down or pull it up and that pump is electrically driven.In case of Hydraulic system failure,there are two gas pressurized springs by which gears can be extended

-When the airplane is parked at the bay and nose gear is down,then the nose gear is always experiencing a pressure on it due to airplane weight,weight of luggage and weight of passengers boarding on the airplane.

Hydraulic mechanism is monitoring the pressure exerted on the nose gear and to neutralize that pressure its applying a
pressure on the opposite direction

Program:

//Header File(.h file)

#ifndef STATE_H_
#define STATE_H_

#include<stdio.h>

void init_state_Machine();
void gear_down();
void check_before_takeoff();
void rising_gear();
void gear_up();
void check_before_landing();
void landing_gear();

typedef enum state
{
gr_down,
chk_bfr_tkof,
rising_gr,
gr_up,
chk_bfr_lnd,
lwar_gear
}state_type;

typedef enum Switch
{
Open,
Close
}Switch_status;

typedef enum pilot_lever
{
rising,
falling,
up,
down
}pilot_lever_status;

typedef enum hydraulic_machine
{
working,
malfunctioning
}hydraulic_machine_status;

static volatile Switch_status squat_switch;
static volatile Switch_status limit_switch;
static volatile pilot_lever_status pilot_lever;
static volatile hydraulic_machine_status hydraulic_machine;

state_type current_state;

typedef struct
{
char* current_state_indication;
char*light_status;
char*direction_valve_status;
char*hydraulic_pump_control_status;
char*gas_pressur_spring_status[2];
}state_table;

static state_table state_Machine[6]=
{
{"Gear Down","Green","Dowm","Enabled",{NULL,NULL}},
{"Checking Before TakeOff","Green","Down","Enabled",{NULL,NULL}},
{"Rising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"Gear Up","Off","Null","Disabled",{NULL,NULL}},
{"Check Before Landing","Red","Down","Enabled",{NULL,NULL}},
{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}


};


#endif /* STATE_H_ */

//Main Function

#include "state.h"

static void(*function[])(void)={gear_down,check_before_takeoff,rising_gear,gear_up,check_before_landing,landing_gear};

int main()
{
init_state_Machine();
while(1)
{
function[current_state]();
}
}

//Initial State:

#include "state.h"

void init_state_Machine()
{
current_state = gr_down;
printf("\n State Machine initialized & program is in gear down state light status : %s\n",
state_Machine[current_state].light_status);
}

//Check Before Take Off

#include "state.h"

void check_before_takeoff()
{
current_state=chk_bfr_tkof;

printf("\n Enter pilots lever position,squat switch status and hydraulic machine status:");
fflush(stdout);
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_machine);

if(pilot_lever==falling || squat_switch==Close)
{
gear_down();
}
else if(pilot_lever==up && squat_switch==Open && hydraulic_machine==working)
{
current_state=rising_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_machine==malfunctioning)
{
current_state=rising_gr;
printf("\n current 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);
printf("Gas Pressurised spring system status:%s\n",state_Machine[current_state].gas_pressur_spring_status[hydraulic_machine]);

}
}

//Rising Gear

#include "state.h"

void rising_gear()
{
current_state=rising_gr;

printf("\nEnter Limit switch Status & Pilot Lever Status:");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);

if(pilot_lever==falling && limit_switch==Open)
{
current_state=chk_bfr_lnd;
printf("\n current 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(limit_switch==Close && pilot_lever==up)
{
current_state=gr_up;
printf("\n current 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
{
rising_gear();
}
}

//Gear Up

#include "state.h"

void gear_up()
{
current_state=gr_up;
printf("\n Enter Pilot's Lever Position:");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever==falling)
{
current_state = chk_bfr_lnd;
printf("\n current 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

#include "state.h"

void check_before_landing()
{
current_state=chk_bfr_lnd;

printf("Enter Pilot's lever position and hydraulic machine status");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_machine);
if(pilot_lever==down && hydraulic_machine==working)
{
current_state=lwar_gear;
printf("\n current 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==down && hydraulic_machine==malfunctioning)
{
current_state=lwar_gear;
printf("\n current 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);
printf("Gas Pressurised spring system status:%s\n",state_Machine[current_state].gas_pressur_spring_status[hydraulic_machine]);

}
if(pilot_lever== up||rising||falling)
{
check_before_landing();
}
}

//Lowering Gear

#include "state.h"

void landing_gear()
{
current_state=lwar_gear;

printf("Enter limit Switch Status and Pilot Lever status :");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if(pilot_lever==rising)
{
current_state=chk_bfr_tkof;
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)
{
current_state=gr_down;
printf("\n current 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);
}
if(limit_switch==Close)
{
landing_gear();
}
}

//Gear Down

#include "state.h"

void gear_down(void)
{
current_state=gr_down;

printf("\n Enter the Pilot's Lever Position and squat switch Position");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch);
if(pilot_lever==rising && squat_switch==Open)
{
current_state=chk_bfr_tkof;
printf("\n Current state :%s\n",state_Machine[current_state].current_state_indication);
printf("Light status:%s\n",state_Machine[current_state].light_status);
}
else
{
gear_down();
}
}

Outcome:

Initially the state machine was in Gear down

Input:

Pilot Lever Position: 0 (rising)

squat switch: 0 (Open)

state shift from Gear down to ->check before take Off

Pilot Lever Position: 2 (Up)

squat switch: 0 (Open)

Hydraulic Machine status:0(Working)

state shift from check before take Off to ->Rising Gear

Pilot Lever Position: 2 (Up)

Limit switch: 1 (Open)

state shift from Rising Gear to -> Gear Up

Pilot Lever Position: 1 (falling)

state shift from Gear Up to -> Check Before Landing

Pilot Lever Position: 3 (Down)

Hydraulic machine status:0(Working)

state shift fromCheck Before Landing to -> 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.

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.