Challenge

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.

Answer:-

Landing Gear of an Airplane:-

It is the undercarriage of an airplane, which is used for either take off or landing.

It was also formerly called alighting gear by some manufacturers, such as the Glenn L. Martin company.

An airplane has 3 gears for landing:- Nose gear, Left gear, Right gear.

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.

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.

Considering above flow diagram we make a table which helps us complete this project:-

Declaring as used in code:-

State_Type Switch_Status Pilot_Lever_Status Hydraulic_Mechanicsm_Status

gr_dwn open rising working

chk_bfr_tkof close falling

rsing_gr up malfunctioning

gr_up down

chk_bfr_lnd

lwrng_gr

CODE:-

#include <stdio.h> //PREPROCESSOR//

#include "States.h" //HEADER FILE INCLUDING//

static void (*state_table[])(void) = {gear_down, checking_before_takeoff, raising_gear,

gear_up, checking_before_landing, lowering_gear}; //DECLARING VARIABLES TO STATE TABLE//

int main() //MAIN FUNCTION//

{

init_state_machine(); //INITIALIZE STATE MACHINE//

while(1) //WHILE LOOP//

{

state_table[current_state](); //CALLING STATE TABLE//

}

}

STATE.H FILE:-

#ifndef STATES_H_ //INCLUDING HEADER FILE//

#define STATES_H_

void init_state_machine(); //FUNCTION DECLARING INITIAL STATE MACHINE//

void gear_down(); //FUNCTION DECLARING GEAR DOWN//

void checking_before_takeoff(); //FUNCTION DECLARING CHECKING BEFORE TAKE OFF//

void raising_gear(); //FUNCTION DECLARING RISING GEAR//

void gear_up(); //FUNCTION DECLARING GEAR UP//

void checking_before_landing(); //FUNCTION DECLARING CHECKING BEFORE LANDING//

void lowering_gear(); //FUNCTION DECLARING LOWERING GEAR//

typedef enum state //TYPEDEF ENUM FUNCTION TO DEFINE STATE TYPE//

{

gr_dwn,

chk_bfr_tkof,

rsing_gr,

gr_up,

chk_bfr_lnd,

lwrng_gr

}state_type;

typedef enum Switch //TYPEDEF ENUM FUNCTION TO DEFINE SWITCH//

{

open,

close

}Switch_status;

typedef enum pilot_lever //TYPEDEF ENUM FUNCTION TO DEFINE PILOT LEVER STATUS//

{

rising,

falling,

up,

down

}pilot_lever_status;

typedef enum hydraulic_mechanism //TYPEDEF ENUM FUNCTION TO DEFINE HYDRAULIC MECHANISM STATUS//

{

working,

malfunctioning

}hydraulic_mechanism_status;

static volatile Switch_status squat_switch; //INPUT VARIABLE FOR CHANGING THE STATES//

static volatile Switch_status limit_switch; //INPUT VARIABLE FOR CHANGING THE STATES//

static volatile pilot_lever_status pilot_lever; //INPUT VARIABLE FOR CHANGING THE STATES//

static volatile hydraulic_mechanism_status hydraulic_mechanism; //INPUT VARIABLE FOR CHANGING THE STATES//

state_type current_state; //DEFINING CURRENT STATE AS STATE TYPE//

typedef struct //DEFINING STATE TABLE VARIABLES AS TYPEDEF STRUCTURE WITH CHARACTER DATATYPE//

{

char* current_state_indication;

char* light_status;

char* direction_valve_status;

char* hydraulic_pump_control_status;

char* gas_pressurized_spring_status[2];

}State_table;

static State_table state_machine[6] = {

{"geardown","green","down","enabled",0,0},

{"checking before take off","green","down","enabled",0,0},

{"raising gear","red","up","enabled",{"disabled","enabled"}},

{"gear up","off","null","disabled",0,0},

{"checking before landing","red","down","enabled",0,0},

{"lowering gear","green","down","enabled",{"disabled","enabled"}}

}; //STATE TABLE ARRAY DECLARATION//

#endif /* STATES_H_ */ //END OF HEADER FILE//

INITIALIZED STATE MACHINE:-

#include "States.h" //INCLUDING HEADER FILE//

void init_state_machine() //FUNCTION INITIAL STATE MACHINE CALLED//

{

current_state = gr_dwn; //ASSIGNING CURRENT STATE TO LOWERING GEAR//

printf("\nstate machine is initialized & program is in gear down state & light status:%s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

}

GEAR DOWN:-

#include "States.h" //INCLUDING HEADER FILE//

#include <stdio.h> //PREPROCESSOR//

void gear_down(void) //FUNCTION GEAR DOWN CALLED//

{

current_state=gr_dwn; //ASSIGNING CURRENT STATE TO GEAR DOWN//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nenter the pilot lever position & squat switch status:"); //PRINT THE MESSAGE//

fflush(stdout); //CLEAR CACHE MEMORY//

scanf("%d %d",&pilot_lever,&squat_switch); //READS AND STORES THE DATA//

if(pilot_lever==rising && squat_switch==open) //IF CONDITION TO CHECK THE CONDITIONS//

{

current_state = chk_bfr_tkof; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO CHECK BEFORE TAKEOFF//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

}

else //IF CONDITIONS ARE NOT SATISFIED GO TO GEAR DOWN FUNCTION//

{

gear_down(); //REPEAT//

}

}

CHECKING BEFORE TAKEOFF:-

#include "States.h" //INCLUDING HEADER FILE//

#include <stdio.h> //PREPROCESSOR//

void checking_before_takeoff() //FUNCTION CHECKING BEFORE LANDING CALLED//

{

current_state=chk_bfr_tkof; //ASSIGNING CURRENT STATE TO CHECK BEFORE TAKEOFF//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nenter the pilot lever position,squat switch status & status of hydraulic mechanism:"); //PRINT THE MESSAGE//

fflush(stdout); //CLEAR CACHE MEMORY//

scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism); //READS AND STORES THE DATA//

printf("\nwait for 2 secs\n"); //PRINT THE MESSAGE//

if(pilot_lever==falling || squat_switch==close) //IF CONDITION TO CHECK THE CONDITIONS//

{

gear_down(); //IF CONDITION IS TRUE GO TO GEAR DOWN FUNCTION//

}

else if(pilot_lever==up && squat_switch==open && hydraulic_mechanism==working) //NESTED IF CONDITION TO CHECK OTHER CONDITION//

{

current_state = rsing_gr; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO RISING GEAR//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

printf("direction valve status:%s\n",state_machine[current_state].direction_valve_status); //DISPLAY DIRECTION VALVE STATUS//

}

else if(pilot_lever==up && squat_switch==open && hydraulic_mechanism==malfunctioning) //NESTED IF CONDITION TO CHECK OTHER CONDITION//

{

printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

printf("direction valve status:%s\n",state_machine[current_state].direction_valve_status); //DISPLAY DIRECTION VALVE STATUS//

printf("gas pressurized spring status:%s\n",state_machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]); //DISPLAY GAS PRESSURIZED SPRING STATUS//

}

}

RISING GEAR:-

#include "States.h" //INCLUDING HEADER FILE//

#include <stdio.h> //PREPROCESSOR//

void raising_gear() //FUNCTION RAISING GEAR CALLED//

{

current_state=rsing_gr; //ASSIGNING CURRENT STATE TO RISING GEAR//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nenter the limit switch status,pilot lever position:"); //PRINT THE MESSAGE//

fflush(stdout); //CLEAR CACHE MEMORY//

scanf("%d %d",&pilot_lever,&limit_switch); //READS AND STORES THE DATA//

printf("\nwait for 1 sec\n"); //PRINT THE MESSAGE//

if(pilot_lever==falling && limit_switch==open) //IF CONDITION TO CHECK THE CONDITIONS//

{

current_state = chk_bfr_lnd; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO CHECK BEFORE LANDING//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

printf("hydraulic control for landing gear status:%s\n",state_machine[current_state].hydraulic_pump_control_status); //DISPLAY HYDRAULIC PUMP CONTROL STATUS//

}

else if(pilot_lever==up && limit_switch==close) //NESTED IF CONDITION TO CHECK OTHER CONDITION//

{

current_state=gr_up; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO GEAR UP//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

printf("hydraulic control for landing gear status:%s\n",state_machine[current_state].hydraulic_pump_control_status); //DISPLAY HYDRAULIC PUMP CONTROL STATUS//

}

else //IF CONDITIONS ARE NOT SATISFIED GO TO RAISING GEAR FUNCTION//

{

raising_gear(); //REPEAT//

}

}

GEAR UP:-

#include "States.h" //INCLUDING HEADER FILE//

#include <stdio.h> //PREPROCESSOR//

void gear_up() //FUNCTION GEAR UP CALLED//

{

current_state=gr_up; //ASSIGNING CURRENT STATE TO GEAR UP//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nenter the pilot lever position:"); //PRINT THE MESSAGE//

fflush(stdout); //CLEAR CACHE MEMORY//

scanf("%d",&pilot_lever); //READS AND STORES THE DATA//

if(pilot_lever==falling) //IF CONDITION TO CHECK THE CONDITIONS//

{

current_state = chk_bfr_lnd; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO CHECK BEFORE LANDING//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

printf("hydraulic control for landing gear status:%s\n",state_machine[current_state].hydraulic_pump_control_status); //DISPLAY HYDRAULIC PUMP CONTROL STATUS//

}

else //IF CONDITIONS ARE NOT SATISFIED GO TO GEAR UP FUNCTION//

{

gear_up(); //REPEAT//

}

}

CHECKING BEFORE LANDING:-

#include "States.h" //INCLUDING HEADER FILE//

#include <stdio.h> //PREPROCESSOR//

void checking_before_landing() //FUNCTION CHECKING BEFORE LANDING CALLED//

{

current_state=chk_bfr_lnd; //ASSIGNING CURRENT STATE TO CHECK BEFORE LANDING//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nenter the pilot lever position & status of hydraulic mechanism:"); //PRINT THE MESSAGE//

fflush(stdout); //CLEAR CACHE MEMORY//

scanf("%d %d",&pilot_lever,&hydraulic_mechanism); //READS AND STORES THE DATA//

if(pilot_lever==down && hydraulic_mechanism==working) //IF CONDITION TO CHECK THE CONDITIONS//

{

current_state = lwrng_gr; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO LOWERING GEAR//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

printf("direction valve status:%s\n",state_machine[current_state].direction_valve_status); //DISPLAY DIRECTION VALVE STATUS//

}

else if(pilot_lever==down && hydraulic_mechanism==malfunctioning) //NESTED IF CONDITION TO CHECK OTHER CONDITION//

{

current_state = lwrng_gr; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO LOWERING GEAR//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

printf("direction valve status:%s\n",state_machine[current_state].direction_valve_status); //DISPLAY DIRECTION VALVE STATUS//

printf("gas pressurized spring status:%s\n",state_machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]); //DISPLAY GAS PRESSURIZED SPRING STATUS//

}

else if (pilot_lever == (up || rising || falling)) //NESTED IF CONDITION TO CHECK OTHER CONDITION//

{

checking_before_landing(); //REPEAT//

}

}

LOWERING GEAR:-

#include "States.h" //INCLUDING HEADER FILE//

#include <stdio.h> //PREPROCESSOR//

void lowering_gear() //FUNCTION LOWERING GEAR CALLED//

{

current_state=lwrng_gr; //ASSIGNING CURRENT STATE TO LOWERING GEAR//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nenter the limit switch status,pilot lever position:"); //PRINT THE MESSAGE//

fflush(stdout); //CLEAR CACHE MEMORY//

scanf("%d %d",&limit_switch,&pilot_lever); //READS AND STORES THE DATA//

if (limit_switch == close && pilot_lever==rising) //IF CONDITION TO CHECK THE CONDITIONS//

{

current_state = chk_bfr_tkof; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO CHECK BEFORE TAKEOFF//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nlight state: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

}

else if(limit_switch==open && pilot_lever==down) //NESTED IF CONDITION TO CHECK OTHER CONDITION//

{

current_state = gr_dwn; //IF CONDITION IS TRUE ASSIGN CURRENT STATE TO GEAR DOWN//

printf("\ncurrent state: %s\n",state_machine[current_state].current_state_indication); //DISPLAY CURRENT STATE//

printf("\nlight status: %s\n",state_machine[current_state].light_status); //DISPLAY LIGHT STATE//

printf("hydraulic control for landing gear status:%s\n",state_machine[current_state].hydraulic_pump_control_status); //DISPLAY HYDRAULIC PUMP CONTROL STATUS//

}

else //IF CONDITIONS ARE NOT SATISFIED GO TO LOWERING GEAR FUNCTION//

{

lowering_gear(); //REPEAT//

}

}

OVERVIEW OF THE PROJECT:-

The project is to know the knowledge of retraction and extensions of landing gear using a code.

This can be achieved by using finite state machine which is used in the states header file.

FSM (Finite state machine) is a mathematical model of computation.

It is the most efficient algorithm which can be used.

The creation of source file helps us easy to understand the program.

GOALS:-

The main goals are to control the direction of valve and retraction and extension of landing gear.

The control of direction valve is controlled by pilot lever which we can see in the program (reference given in attachment provided).

The retraction and extension of landing gear is controlled by switch states in the program.

Hence, all the goals are achieved.

KEY HIGHLIGHTS OF PROJECT:-

We can observe that the direction valve helps us to raise or lower the landing gear.

The direction valve is controlled by the software.

With the help of this software we control the hydraulic mechanism.

The hydraulic pump controls the raising or lowering of the landing gear.

The hydraulic mechanism helps us to land and take off of the airplane.

DELIVERABLES OF THIS PROJECT:-

The retraction and extension of landing gears is controlled by various switch and gear.

The status of these switches and gears are shown below in various tables.

Table1:-

Switch State

State of Gears

Limit Switch CLOSED

Gear is UP

Limit Switch OPENED

Gear is DOWN

Switch State

State of Airplane

Squat Switch CLOSED

Airplane is grounded and Gears are locked

Squat Switch OPENED

Airplane is taking off / landing / airborne

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

Table 2:-

Status of Direction Valve

States of landing gear

Direction valve = Down

(Gear Down)(Parked at bay or Landed)

Direction valve = Up

Raising Gear(Taking Off)

Control of hydraulic pump for the landing gear part is disabled

Gear Up(Airborne)

Direction valve = down

Lowering Gear(Landing)

INPUT FOR THE DIRECTION VALVE:-

Table 3:-

Pilot’s Lever State

Direction Valve State

Lever UP

Direction valve = Up

Lever Down

Direction valve = Down

Table 4:-

Pilot’s Lever State

Light Status

Lever Rising Edge

Red

Lever Falling Edge

Table 5:-

Every gear has one light. According to the state of the gear,color of light is changing.

Landing Gear State

Light Status

Gear is up

OFF

Gear is down

Green

Gear in transit(Raising or Lowering)

Red

EXPECTED OUTCOMES:-

In this project we get a good knowledge about the finite state machine algorithm.

This algorithm helps us to achieve the control over the retraction and extension of airplane's landing gear.

The switch states and gear states of airplane plays a major role in control of retraction and extension.

The project has a easy logics which is shown in flowchart diagram which makes it easy and interesting.

All the .c files, .h file and screenshots of outputs are uploaded for the reference.

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.