Challenge

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

AIM:

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

Tool Used:

STM32 CUBEIDE

Theory:

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.

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.

Program:

PROJECT2.C (MAIN FILE)

/*
* project2.c
*
* Created on: 17-Nov-2022
* Author: maaza
*/
#include<stdio.h>//preprocessor section
#include "project2.h"//header file for Air

static void(*stateTable[])(void)={GearDown,CheckingBeforetakeOFF,RaisingGear,Gearup,CheckingBeforeLanding,LoweringGear};

//using state table, conditions controlling the retraction and extension of airplane's landing gear are called

int main() //main function//calling function the function should return an integer value
{
Initiate_State_Machine();//initial state machine is declared
while(1) //used for infinite loop, as 1 is there so condition is always true
{
stateTable[current_state]();//current state is declared in state table
}
}

void GearDown(void)//gear down condition
{
current_state=GEAR_DOWN;//current state is gear down
printf("Enter the status of pilot's lever and squat switch:");//printing the statement
fflush(stdout);//to use for immediate flush out the contents of output stream
scanf("%d %d", &p, &squat_switch);//taking input from the user

if((p==Raising) && (squat_switch==On))//used to decide whether a certain statement will be executed or not
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("Current state: %s\n", State_Machine[current_state].current_state_indication);//printing the statement
printf("Light is : %s\n", State_Machine[current_state].light);//printing the statement
}
else//used to specify a block of code to be executed, if the same condition is false
{
GearDown();//gear down statement
}
}

void CheckingBeforetakeOFF(void)//checking before take off condition
{
current_state=CHECKING_BEFORE_TAKEOFF;//current state is checking before take off
printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism:");//printing the statement
fflush(stdout);//to use for immediate flush out the contents of output stream
scanf("%d %d %d", &p, &squat_switch, &h);//taking input from the user

if ((p==falling) && (squat_switch==Off))//used to decide whether a certain statement will be executed or not
{
GearDown();//gear down condition
}
else if((p==Raising) && (squat_switch==On) && (h==notworking))//to specify new condition to test if the first condition false
{
current_state=RAISING_GEAR;//current state is raising gear
printf("Current state: %s\n", State_Machine[current_state].current_state_indication);//printing the statement
printf("Light is : %s\n", State_Machine[current_state].light);//printing the statement
printf("Status of Direction valve : %s\n", State_Machine[current_state].direction_valve_status);//printing the statement
printf("Status of Gas Pressurized Spring system: %s\n", State_Machine[current_state].Gas_Pressurized_Spring_system_status[0]);//printing the statement
}
}

void RaisingGear(void)//raising gear condition
{
current_state=RAISING_GEAR;//current state is raising gear
printf("Enter the status of pilot's lever and limit switch:");//printing the statement
fflush(stdout);//to use for immediate flush out the contents of output stream
scanf("%d %d", &p, &limit_switch);//taking input from the user

if((p==falling) && (limit_switch==On))//used to decide whether a certain statement will be executed or not
{
current_state=CHECK_BEFORE_LANDING;//current state is check before landing
printf("Current state : %s\n", State_Machine[current_state].current_state_indication);//printing the statement
printf("Light is : %s\n", State_Machine[current_state].light);//printing the statement
printf("Landing Gear Hydraulic Control : %s\n", State_Machine[current_state].landing_gear_hydraulic_control);//printing the statement
}

else if((p==Raising) && (limit_switch==Off))//to specify new condition to test if the first condition false
{
current_state=GEAR_UP;//current state is gear up
printf("Current state : %s\n", State_Machine[current_state].current_state_indication);//printing the statement
printf("Light is : %s\n", State_Machine[current_state].light);//printing the statement
printf("Landing Gear Hydraulic Control : %s\n", State_Machine[current_state].landing_gear_hydraulic_control);//printing the statement
}

else //used to specify a block of code to be executed, if the same condition is false
{
RaisingGear(); //raising gear operation
}
}

void Gearup(void) //gear up condition
{
current_state=GEAR_UP; //current state is gear up
printf("Enter the status of pilot's lever:"); //printing the statement
fflush(stdout); //to use for immediate flush out the contents of output stream
scanf("%d", &p); //taking input from the user
if(p==falling) //used to decide whether a certain statement will be executed or not
{
current_state=CHECK_BEFORE_LANDING;//current state is check before landing
printf("Current state : %s\n", State_Machine[current_state].current_state_indication);//printing the statement
printf("Light is : %s\n", State_Machine[current_state].light);//printing the statement
printf("Landing Gear Hydraulic Control : %s\n", State_Machine[current_state].landing_gear_hydraulic_control);//printing the statement
}
else //used to specify a block of code to be executed, if the same condition is false
{
Gearup(); //gear up condition
}
}

void CheckingBeforeLanding(void) //checking before landing condition
{
current_state=CHECK_BEFORE_LANDING;//current state is check before landing
printf("Enter the status of pilot's lever and hydraulic mechanism status:");//printing the statement
fflush(stdout);//to use for immediate flush out the contents of output stream
scanf("%d %d", &p, &h);//taking input from the user

if((p==falling) && (h==working))//used to decide whether a certain statement will be executed or not
{
current_state=LOWERING_GEAR;//current state is lowering gear
printf("Current state: %s\n", State_Machine[current_state].current_state_indication);//printing the statement
printf("Light is : %s\n", State_Machine[current_state].light);//printing the statement
printf("Status of Direction valve : %s\n", State_Machine[current_state].direction_valve_status);//printing the statement
}

else if((p==falling) && (squat_switch==On) && (h==notworking))//to specify new condition to test if the first condition false
{
current_state=LOWERING_GEAR;//current state is lowering gear
printf("Current state: %s\n", State_Machine[current_state].current_state_indication);//printing the statement
printf("Light is : %s\n", State_Machine[current_state].light);//printing the statement
printf("Status of Direction valve : %s\n", State_Machine[current_state].direction_valve_status);//printing the statement
printf("Status of Gas Pressurized Spring system: %s\n", State_Machine[current_state].Gas_Pressurized_Spring_system_status[0]);//printing the statement
}
/*if((p==Raising) || (p==falling))//used to decide whether a certain statement will be executed or not
{
CheckingBeforeLanding();//checking before landing operation
}*/
}

void LoweringGear(void)//lowering gear condition
{
current_state=LOWERING_GEAR;//current state is lowering gear
printf("Enter the status of pilot's lever and limit switch:");//printing the statement
fflush(stdout);//to use for immediate flush out the contents of output stream
scanf("%d %d", &p, &limit_switch);//taking input from the user

if((p==falling) && (limit_switch==On))//used to decide whether a certain statement will be executed or not
{
current_state=CHECKING_BEFORE_TAKEOFF;//current state is checking before take off
printf("Current state: %s\n", State_Machine[current_state].current_state_indication);//printing the statement
printf("Light is : %s\n", State_Machine[current_state].light);//printing the statement
}
else if((p==Raising) && (limit_switch==Off))//to specify new condition to test if the first condition false
{
current_state=GEAR_DOWN;//current state is gear down
printf("Current state : %s\n", State_Machine[current_state].current_state_indication);//printing the statement
printf("Light is : %s\n", State_Machine[current_state].light);//printing the statement
printf("Landing Gear Hydraulic Control : %s\n", State_Machine[current_state].landing_gear_hydraulic_control);//printing the statement
}
if(limit_switch==Off)//used to decide whether a certain statement will be executed or not
{
LoweringGear();//lowering gear condition
}
}

void Initiate_State_Machine()//initiate state machine condition
{
current_state=GEAR_DOWN;//current 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);//printing the statement of State_Machine[current_state].light
}

HEADER FILE PROJECT2.C

/*
* project2.h
*
* Created on: 19-Nov-2022
* Author: maaza
*/

#ifndef PROJECT2_H_
#define PROJECT2_H_

#include<stdio.h> //preprocessor section
void Initiate_State_Machine(); //initial state machine is declared using void
void GearDown(); //gear down is declared using void
void CheckingBeforetakeOFF(); //checking before take off is declared using void
void RaisingGear(); //raising gear is declared using void
void Gearup(); //gear up is declared using void
void CheckingBeforeLanding(); //checking before landing is declared using void
void LoweringGear(); //lowering gear is declared using void

typedef enum State //declares an alternative name as state
{
GEAR_DOWN, CHECKING_BEFORE_TAKEOFF, RAISING_GEAR, GEAR_UP, CHECK_BEFORE_LANDING, LOWERING_GEAR
}State_Type; //state type is declared

typedef enum Switch //declares the alternative name as switch
{
On, //open condition of switch
Off //close condition of switch
}Switch_status; //status of switch

typedef enum pilot_lever //declares the alternative name as pilot lever
{
Raising, //raising state of lever
falling //falling state of lever
}pilot_lever; //pilot lever declared

typedef enum hydraulic_mechanism //alternative name as hydraulic mechanism
{
working,//device is working
notworking//device is not working
}hydraulic_mechanism;//hydraulic mechanism declared

static volatile Switch_status squat_switch;//switch status stored in main memory as squat switch
static volatile Switch_status limit_switch;//switch status stored in main memory as limit switch
static volatile pilot_lever p;//pilot lever stored in main memory as p
static volatile hydraulic_mechanism h;//hydraulic mechanism stored in main memory as h
State_Type current_state;//current state is state type

typedef struct state_table// structure is declared using typedef
{
char* current_state_indication;//current state indication is declared using character
char* light;//light is declared using character
char* direction_valve_status;//direction valve status is declared using character
char* landing_gear_hydraulic_control;//landing gear hydraulic control is declared using character
char* Gas_Pressurized_Spring_system_status[2];//gas pressurized spring system status is declared using character
}State_Table;//state table declaration

static State_Table State_Machine[6]=
{
{"GearDown", "Green", "Down", "Enabled", {NULL, NULL}},//gear down, green light, down enabled table declared
{"CheckingBeforeTakeOFF", "Green", "Down", "Enabled", {NULL, NULL}},//checking before take off, green light, down, enabled table declared
{"RaisingGear", "Red", "Up", "Enabled", {"Disabled", "Enabled"}},//raising gear, red light, up direction, enabled table declared
{"GearUp", "Off", "Null", "Disabled", {NULL, NULL}},//gear up, off state switch, null and disabled condition declared
{"CheckingBeforeLanding", "Red", "Down", "Enabled", {NULL, NULL}},//checking before landing, red light, down, enabled table declared
{"LoweringGear", "Green", "Down", "Enabled", {"Disabled", "Enabled"}}//lowering gear, green light, down, enabled declared
};

#endif /* PROJECT2_H_ */

Result:

Hence we have successfully implemented the code for retraction and extension of Airplane’s landing gear.

Output:

--------------------------------------------------------------------------------------------------------------------------------------

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.