Challenge

Airplane Landing Gear Retraction and Extension Control System

Aim:To control the retraction and extension of Airplane’s landing gear using Finite State Machine (FSM).

Objective:

  • Controlling the direction of Valve.
  • Controlling the retraction and extension of Airplane’s landing gear.

Deliverables of this project :

Implementing the control for the retraction and extension of Airplane’s landing gear using the Finite state machine with the knowledge of various states of switch and gear.

In this Project we will proceed with using implementing header files and multiple c files extension for better readablity and understanding.

using FSM the code has been implemented :

CODE:

//main() :

#include <stdio.h>


#include "states.h" // included the user defined header file

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

//static function


int main()
{
init_State_Machine(); //default state function call

while(1) // infinte loop
{
state_table[current_state](); //call with current state of plane
}

return 0;
}

//User defined header file():

/*
* states.h
*
* Created on: 03-May-2022
* Author: kabhi
*/

#include<stdio.h>

#ifndef STATES_H_
#define STATES_H_ //defined .h file

void init_State_Machine(); //intiliazing all the function
void Gear_Down();
void Checking_Before_Takeoff();
void Raising_Gear();
void Gear_up();
void Checking_Before_Landing();
void Lowering_Gear();

typedef enum state_table{ //assigning numeric value to call
GR_DWN, //0
CHK_BFR_TKFF, //1
RSING_GR, //2
GR_UP, //3
CHK_BFR_LND, //4
LWRNG_GR //5
}State_Type; //object

typedef enum Switch{ //likewise for switch case
open,
close
}Switch_Status;

typedef enum Pilot_Lever //pilot lever case
{
Rising,
Falling,
UP,
Down
}Pilot_Lever_Status;

typedef enum Hydraulic_Mechanism //Hydraulic mechanism case
{
working,
Mafunctioning
}Hydraulic_Mechanism_Status;

static volatile Switch_Status squat_switch; //intialized object call variable
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; /*create structure table to assign predefined values */
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] = { //all 6 cases
{"Gear Down","Green","Down","Enabled",{NULL,NULL}},

{"Checking Before Take Off","Green","Down","Enabled",{NULL,NULL}},

{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},

{"Gear Up","Off","Null","Disabled",{NULL,NULL}},

{"Checking Before Landing","Red","Down","Enabled"},

{"Lowering Gear","Green","Down","Enabled"}
};


#endif /* STATES_H_ */

//Gear Down():

/*
* Gear_Down.c
*
* Created on: 03-May-2022
* Author: kabhi
*/

#include "states.h" //stating the predefined set values

void Gear_Down(void)
{
current_state=GR_DWN; //setting up the values

printf("\nCurrent state : %s",State_Machine[current_state].current_state_indication);

printf("\nEnter the pilot's Lever position and squat switch staus : ");
fflush(stdout);

scanf("%d %d",&pilot_lever,&squat_switch);

if(pilot_lever==Rising && squat_switch ==open) //condition check
{
current_state=CHK_BFR_TKFF;
printf("\nCurrent state : %s",State_Machine[current_state].current_state_indication);
printf("\nLight Status : %s ",State_Machine[current_state].light_status);

}

else{
Gear_Down(); //repeat the same calling
}
}

// Checking before take off():

#include "states.h" //stating the predefined set values

void Checking_Before_Takeoff()
{
current_state=CHK_BFR_TKFF; //setting up the values

printf("\ncurrent state : %s",State_Machine[current_state].current_state_indication);

printf("\nEnter the pilot's Lever position and squat switch status : ");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch);

printf("\nHydraulic mechanism status : ");
fflush(stdout);
scanf("%d",&hydraulic_mechanism);

printf("\nwait for 2 secs ");

if(pilot_lever==Falling || squat_switch==close)
{
Gear_Down();
} //condition check

else if(pilot_lever==UP && squat_switch==open && hydraulic_mechanism==working)
{
current_state=RSING_GR;

printf("\ncurrent state : %s",State_Machine[current_state].current_state_indication);

printf("\nLight Status : %s ",State_Machine[current_state].light_status);

printf("\nDirection Valve status :%s",State_Machine[current_state].direction_valve_status);

printf("\nGas pressurized spring status : %s",
State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);

}
}

//Raising Gear():

#include "states.h" //stating the predefined set values


void Raising_Gear()
{
current_state=RSING_GR;
printf("\ncurrent state : %s",State_Machine[current_state].current_state_indication);

printf("\nEnter the pilot's Lever position and limit switch status : ");
fflush(stdout);
scanf("%d %d",&pilot_lever,&limit_switch);

printf("\nwait for 2 secs ");

if(pilot_lever==Falling && limit_switch==open) //condition check
{
current_state=CHK_BFR_LND;
printf("\ncurrent state : %s",State_Machine[current_state].current_state_indication);
printf("\nLight Status : %s ",State_Machine[current_state].light_status);
printf("\nhydraulic control for landing gear status : %s",State_Machine[current_state].hydraulic_pump_control_status);
}

else if(limit_switch==close && pilot_lever==UP) //condition check
{
current_state=GR_UP;
printf("\ncurrent state : %s",State_Machine[current_state].current_state_indication);
printf("\nLight Status : %s ",State_Machine[current_state].light_status);
printf("\nhydraulic control for landing gear status : %s",State_Machine[current_state].hydraulic_pump_control_status);
}

else
{
Raising_Gear(); //repeat the same calling
}
}

Gear UP():

#include "states.h"

void Gear_up()
{
current_state=GR_UP;

printf("\ncurrent state : %s",State_Machine[3].current_state_indication);
printf("\nEnter the pilot's Lever position : ");
fflush(stdout);
scanf("%d",&pilot_lever);

if(pilot_lever==Falling) //condition check
{
current_state=CHK_BFR_LND;
fflush(stdout);
printf("\ncurrent state : %s",State_Machine[current_state].current_state_indication);
printf("\nLight Status : %s ",State_Machine[current_state].light_status);
printf("\nhydraulic control for landing gear status : %s",State_Machine[current_state].hydraulic_pump_control_status);
}

else
{
Gear_up(); //repeat the same calling
}

}

Checking Before landing():

#include "states.h"

void Checking_Before_Landing()
{
current_state = CHK_BFR_LND;
printf("\ncurrent state : %s",State_Machine[current_state].current_state_indication);
printf("\nEnter the pilot's Lever position & hydraulic mechanism : ");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);

//condition check
if(pilot_lever==Down && hydraulic_mechanism==working)
{
current_state=LWRNG_GR;
printf("\ncurrent state : %s",State_Machine[current_state].current_state_indication);
printf("\nLight Status : %s ",State_Machine[current_state].light_status);
printf("\nDirection valve status : %s",State_Machine[current_state].direction_valve_status);
} //condition check

else if(pilot_lever==Down && hydraulic_mechanism == Mafunctioning)
{
current_state=LWRNG_GR;
printf("\ncurrent state : %s",State_Machine[current_state].current_state_indication);
printf("\nLight Status : %s ",State_Machine[current_state].light_status);
printf("\nDirection valve status : %s",State_Machine[current_state].direction_valve_status);
}

if(pilot_lever==(Falling)) //condition check
{
Checking_Before_Landing(); //repeat the same calling
}

}

Lowering Gear():

#include "states.h"

void Lowering_Gear()

{
current_state=LWRNG_GR;

printf("\nCurrent state : %s\n",State_Machine[current_state].current_state_indication);
printf("\nEnter the pilot's Lever position and limit switch staus : ");
fflush(stdout);
scanf("%d %d",&pilot_lever,&limit_switch);

if(pilot_lever==Rising) //condition check
{
current_state=CHK_BFR_TKFF;

printf("\nCurrent state : %s\n",State_Machine[current_state].current_state_indication);
printf("\nLight Status : %s ",State_Machine[current_state].light_status);

}

if(limit_switch==open) //condition check
{
current_state=GR_DWN;

printf("\nCurrent state : %s",State_Machine[current_state].current_state_indication);
printf("\nLight Status : %s ",State_Machine[current_state].light_status);
printf("\nhydraulic control for landing gear status : %s",State_Machine[current_state].hydraulic_pump_control_status);

}

if(limit_switch==close)
{
Lowering_Gear(); //repeat the same calling
}
}

OUTPUT


State machine is intialized & program is in gear down and light status : Green
Current state : Gear Down
Enter the pilot's Lever position and squat switch staus : 0 0

Current state : Checking Before Take Off
Light Status : Green
current state : Checking Before Take Off
Enter the pilot's Lever position and squat switch status : 2 0

Hydraulic mechanism status : 0

wait for 2 secs
current state : Raising Gear
Light Status : Red
Direction Valve status : Up
Gas pressurized spring status : Disabled
current state : Raising Gear
Enter the pilot's Lever position and limit switch status : 2 1

wait for 2 secs
current state : Gear Up
Light Status : Off
hydraulic control for landing gear status : Disabled
current state : Gear Up
Enter the pilot's Lever position : 1

current state : Checking Before Landing
Light Status : Red
hydraulic control for landing gear status : Enabled
current state : Checking Before Landing
Enter the pilot's Lever position & hydraulic mechanism : 3 0

current state : Lowering Gear
Light Status : Green
Direction valve status : Down
Current state : Lowering Gear

Enter the pilot's Lever position and limit switch staus : 1 0

Current state : Gear Down
Light Status : Green
hydraulic control for landing gear status : Enabled
Current state : Gear Down
Enter the pilot's Lever position and squat switch staus :

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.