Challenge

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

Project: Implement the Code for controlling the retraction and extension of Airplane’s landing gear.

Overview of Project:

In this project,controlling the retraction and extension of airplane's landing gear can be implemented using Finite State Machine(FSM).FSM is the most efficient algorithm which is mathematical model of computation.

Goals:

Controlling the direction of valve,retraction and extension of airplane's landing gear.

Key Highlights:

Adirection valve is controlling by software to allow hydraulic pressure to either raise or lower the landing gear.

Deliverables:

Implementing the control for the retraction and extension of airplane's landing gear using FSM with various states of switch and gear.

Expected outcomes:

very usefull and geeting knowledge of FSM algorithm which is used to achieve the control over the retraction and extension of airplane's landing gear using the switch and gear states of airplane.

Code:

In Main.c file

#include<stdio.h>// preprocessor
#include"FSM.h"// header file of FSM


static void(*StateTable[])
(void)={GearDown,CheckingBeforetakeOFF,RaisingGear,Gearup,CheckingBeforeLanding,LoweringGear};//using state table,conditions cotrolling retraction and extension of airplane landing gear called
int main() // main function
{
Initiate_State_Machine(); // initial state machine is declared
while(1) // used for infinite loop
{
StateTable[current_state](); // current state is declared in state table
}
}

// Gear Down

void GearDown(void)
{

current_state= GEAR_DOWN;// current state is gear down
printf("Enter the status of pilot's lever and squat switch:");//printing statement
fflush(stdout); // clear console
scanf("%d %d",&p,&squat_switch);// taking input from user
if((p==Raising) && (squat_switch==On)) //used to decide wheather 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 statement
printf("Light is :%s\n",State_Machine[current_state].light);//printing statement
}
else //used to specify a block of code to be executed
{
GearDown();//gear down statement
}
}
//checkingBeforeTakeOFF
void CheckingBeforetakeOFF(void)
{
current_state=CHECKING_BEFORE_TAKEOFF;//current state is checking before takeoff
printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism :");//printing statement
fflush(stdout);//clear console
scanf("%d %d %d",&p,&squat_switch,&h);//taking input from the user
if((p==falling) && (squat_switch==Off))//used to decide wheather 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 first condition is false
{
current_state=RAISING_GEAR;//current state is rising gear
printf("Current state:%s\n",State_Machine[current_state].current_state_indication);//printing statement
printf("Light is:%s\n",State_Machine[current_state].light);//printing statement
printf("Status of direction valve:%s\n",State_Machine[current_state].direction_valve_status);//printing statement
printf("Status of Gas Pressurized Spring system:%s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status[0]);//printing statement
}
}

//RaisingGear
void RaisingGear(void)
{
current_state=RAISING_GEAR;//current state is rising gear
printf("Enter the value of pilot's lever and limit switch");//printing statement
fflush(stdout);//clear console
scanf("%d %d",&p,&limit_switch);//taking input from user
if((p==falling) && (limit_switch==On))//used to decide wheather 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 statement
printf("Light is:%s\n",State_Machine[current_state].light);//printing statement
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);//printing statement

}
else if ((p==Raising) && (limit_switch==Off))//used to decide wheather certain statement will be executed or not
{
current_state=GEAR_UP;// current state is gear up
printf("Current state:%s\n",State_Machine[current_state].current_state_indication);//printing statement
printf("Light is:%s\n",State_Machine[current_state].light);////printing statement
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);////printing statement

}
else
{
RaisingGear();
}
}
//GearUp
void Gearup(void)
{
current_state=GEAR_UP;//current state is gearup
printf("Enter the value of pilot's lever:");//printing statement
fflush(stdout);//clear console
scanf("%d",&p);//taking input from user
if(p==falling)//checking condition
{
current_state=CHECK_BEFORE_LANDING;
printf("Current state:%s\n",State_Machine[current_state].current_state_indication);//printing statement
printf("Light is:%s\n",State_Machine[current_state].light);//printing statement
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);//printing statement
}
else
{
Gearup();
}
}
//ChechBeforeLanding
void CheckingBeforeLanding(void)
{
current_state=CHECK_BEFORE_LANDING;//current state check before landing
printf("Enter the status of pilot's lever and hydraulic mechanism :");//printing statement
fflush(stdout);//clear console
scanf("%d %d",&p,&h);//taking input from user
if((p==falling) && (h==working))//used to decide wheather certain statement will be executed or not
{
current_state=LOWERING_GEAR;
printf("Current state:%s\n",State_Machine[current_state].current_state_indication);//printing statement
printf("Light is:%s\n",State_Machine[current_state].light);//printing statement
printf("status of direction valve :%s\n",State_Machine[current_state].direction_valve_status);//printing statement
}
else if ((p==falling)&&(squat_switch==On)&&(h==notworking))////used to decide wheather certain statement will be executed or not
{
current_state=LOWERING_GEAR;
printf("Current state:%s\n",State_Machine[current_state].current_state_indication);//printing statement
printf("Light is:%s\n",State_Machine[current_state].light);//printing statement
printf("status of direction valve :%s\n",State_Machine[current_state].direction_valve_status);//printing statement
printf("Status of gas pressurized spring system:%s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status[0]);//printing statement
}

}
//LoweringGear
void LoweringGear(void)
{
current_state=LOWERING_GEAR;//current state is lowering gear
printf("Enter the status of pilot's lever and limit switch");//printing statement
fflush(stdout);//clear console
scanf("%d %d",&p,&limit_switch);//taking input from user
if((p==falling) && (limit_switch==On))//used to decide wheather 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 statement
printf("Light is:%s\n",State_Machine[current_state].light);//printing statement
}
else if((p==Raising)&&(limit_switch==Off))
{
current_state=GEAR_DOWN;
printf("Current state:%s\n",State_Machine[current_state].current_state_indication);//printing statement
printf("Light is:%s\n",State_Machine[current_state].light);//printing statement
printf("Landing gear Hydraulic control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);//printing statement
}
if(limit_switch==Off)//used to decide wheather 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 gear down
printf("The finite state machine is initialized and current program is in" "GearDown state &Light is :%s\n",State_Machine[current_state].light);//printing statement
}

In FSM.h File:

#ifndef FSM_H_ // allow conditional compilation of FSM.h
#define FSM_H_ //defines FSM.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 takeoff is declared using void
void RaisingGear();//raising gear is declared using void
void Gearup();//gearup is declared using void
void CheckingBeforeLanding();//checkingbeforelanding is declared using void
void LoweringGear();//lowering gear is declared using void

typedef enum state{ //declares as 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 alternative name as switch
{
On,// open condition of switch
Off // plane is on Ground

} Switch_status; //status of switch

typedef enum pilot_lever { //declares alternative name as pilot lever

Raising, //raising state of lever
falling //falling state of lever
}pilot_lever; //pilot lever declared

typedef enum hydraulic_mechanism //declares 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 is stored in main memory as squat switch
static volatile Switch_status limit_switch;//switch status is stored in main memory as limit switch
static volatile pilot_lever p; //pilot lever is stored in main memory as p
static volatile hydraulic_mechanism h;// hydraulic mechanism is 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 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;

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}},//checkingbefore takeoff,green light,down enabled declared
{"RaisingGear","Red","Up","Enabled",{"Disabled","Enabled"}},//raising gear red light up enabked declared
{"GearUp","Off","Null","Disabled",{NULL,NULL}},//gearup off light disabled
{"CheckingBeforeLanding","Red","Down","Enabled",{NULL,NULL}},//checkingbeforelanding red light down enabled
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}//lowering gear green light down enabled declared
};


# endif /* FSM_H_ */ //end of declaration

Output:

The finite state machine is initialized and current program is inGearDown state &Light is :Green
Enter the status of pilot's lever and squat switch:0 0
Current state:CheckingBeforeTakeOFF
Light is :Green
Enter the status of pilot's lever and squat switch and hydraulic mechanism :0 0 1
Current state:RaisingGear
Light is:Red
Status of direction valve:Up
Status of Gas Pressurized Spring system:Disabled
Enter the value of pilot's lever and limit switch 0 1
Current state:GearUp
Light is:Off
Landing Gear Hydraulic Control:Disabled
Enter the value of pilot's lever:1
Current state:CheckingBeforeLanding
Light is:Red
Landing Gear Hydraulic Control:Enabled
Enter the status of pilot's lever and hydraulic mechanism :1 0
Current state:LoweringGear
Light is:Green
status of direction valve :Down
Enter the status of pilot's lever and limit switch 1 0
Current state:CheckingBeforeTakeOFF
Light is:Green
Enter the status of pilot's lever and squat switch and hydraulic mechanism :

Output:

In FSM.h

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.