Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
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.
FSM :- "finite state machine" this are the FSM functionalities
- Finite state machine is used to recognize patterns.
- Finite automata machine takes the string of symbol as input and changes its state accordingly. In the input, when a desired symbol is found then the transition occurs.
- While transition, the automata can either move to the next state or stay in the same state.
- FA has two states: accept state or reject state. When the input string is successfully processed and the automata reached its final state then it will accept.
retractable gear :-


different states in different functionality :-
|
SWITCH STATE |
STATE OF GEARS |
|
LIMIT SWITCH CLOSE |
GEAR IS UP |
|
LIMIT SWITCH OPEN |
GEAR IS DOWN |
|
SWITCH STATE |
STATE OD AIRPLANE |
|
SQUAT SWITCH CLOSED |
AIRPLANE IS GROUNDED AND GEARS ARE LOCKED |
|
SQUAT SWITCH OPENED |
AIRPLANE IS TAKING OFF / LANDING /AIRBORNE |
|
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) |
|
PILOT’S LEVER STATE |
DIRECTION VALVE STATE |
|
LEVER UP |
DIRECTION VALVE = UP |
|
LEVER DOWN |
DIRECTION VALVE = DOWN |
|
PILOT’S LEVER STATE |
LIGHT STATE |
|
LEVER RISING EDGE |
RED |
|
LEVER FALLING EDGE |
RED |
|
LANDING GEAR STATE |
LIGHT STATUS |
|
GEAR IS UP |
OFF |
|
GEAR IS DOWN |
GREEN |
|
GEAR IN TRANSIT(RAISING OR LOWERING) |
RED |
---------------------------------------------------------------------------------------------------------------------------------------------------------
final code :-
#include // this is main header file
void starting_State_Machine(); //starting step of the FSM
void GearDown(); //function prototype for GearDown
void CheckingBeforeTakeOFF(); // function prototype for CheckingBeforeTakeOFF
void RaisingGear(); // function prototype for RaisingGear
void GearUp(); //function prototype for GearUp
void CheckBeforeLanding(); //function prototype for CheckBeforeLanding
void LoweringGear(); //function prototype for LoweringGear
static void(*statetable[])(void)={GearDown, CheckingBeforeTakeOFF, RaisingGear, GearUp, CheckBeforeLanding, LoweringGear};// this function for compile the prototype in order
typedef enum State // this ENUM state function for knowing the FSM in which state
{
GEAR_DOWN,//0
CHECKING_BEFORE_TAKEOFF,//1
RAISING_GEAR,//2
GEAR_UP,//3
CHECK_BEFORE_LANDING,//4
LOWERING_GEAR,//5
}State_Type;// this is alias name for my function
State_Type current_state;//current_state is also variable for state_Type
typedef enum Switch//switch function for change the status of switch
{
on,//0
off//1
}Switch_status;//alias name
typedef enum pilot_lever//lever function
{
Raising,//0
falling//1
}pilot_lever;//alias name
typedef enum hydraulic_mechanism
{
working,
not_working
}hydraulic_mechanism;
static volatile Switch_status squat_switch;//variable for switch_status
static volatile Switch_status limit_switch;//variable for switch_status
static volatile pilot_lever pl;//p1 is variable for pilot_lever
static volatile hydraulic_mechanism hm;//hm variable for hydraulic_mechanism
typedef struct
{
char* current_state_indication; //pointer variables
char* light;
char* direction_valve_status;
char* landing_gear_hydraulic_control;
char* Gas_Pressurized_Spring_system_status[2];
}State_Table;//alias name for function
static State_Table State_Machine[6]={{"GearDown","Green","Down","Enabled",{NULL,NULL}},
{"CheckingBeforeTakeOFF","Green","Down","Enabled",{NULL,NULL}},
{"RaisingGear","Red","Up","Enabled",{NULL,NULL}},
{"GearUp","Off","NULL","Disbled",{NULL,NULL}},
{"CheckBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}// we created one ary for showing the changes in FSM
};
int main() // main function to call the all prototype functions
{
starting_State_Machine(); // calling the define prototype
while(1) // while 1 for infinite loop
{
statetable[current_state](); // this function for change the states of the "FSM"
}
}
void GearDown(void) //prototype function definition
{
current_state=GEAR_DOWN;//current_state value is 0
printf("Enter the status of pilot's lever and squat switch");//gives the external values
fflush(stdout);
scanf("%d %d",&pl,&squat_switch); //stores the values
if(pl==Raising && squat_switch==on) //when condition true if statement works
{
current_state=CHECKING_BEFORE_TAKEOFF;//current_state value is 1
printf("current state:%s\n",State_Machine[current_state].current_state_indication);//prints the current_state of machine
printf("Light is :%s\n", State_Machine[current_state].light); //prints the light condition
}
else//whenever if condition not true else statement works
{
GearDown(); //calling the function
}
}
//CheckingBeforeTakeOFF
void CheckingBeforeTakeOFF(void) //prototype function definition
{
current_state=CHECKING_BEFORE_TAKEOFF;//current_state value is 1
printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism:");//gives the lever value and hydraulic value
fflush(stdout);
scanf("%d %d",&pl,&squat_switch);//stores the values in &p1 and &squat_switch
if(pl==falling&&squat_switch==off)//when condition is true if statement works
{
GearDown();
}
else if(pl==Raising && squat_switch==on )//when if condition not true else if statement works
{
current_state=RAISING_GEAR;//current_state value is 2
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);//print current_state of FSM
printf("Light is:%s\n",State_Machine[current_state].light);//print the light state of FSM
printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);//print the direction of FSM
}
else if(pl==Raising && squat_switch==on)// whenever if and else if statements are not true this condition work
{
current_state=RAISING_GEAR;
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
printf("Status of gas pressurised Spring System:%s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);
}
}
//RaisingGear
void RaisingGear(void) //prototype function definition
{
current_state=RAISING_GEAR;//current_state value is 2
printf("Enter the status of pilot's lever and limit switch:");// we giving the lever values
fflush(stdout);
scanf("%d %d",&pl,&limit_switch);//stores the values in &p1 and &limit_switch
if(pl==falling && limit_switch==on)//when condition is true if statement works
{
current_state=CHECK_BEFORE_LANDING;//current_state value is 4
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else if(pl==Raising && limit_switch==off)//when if condition not true else if statement works
{
current_state=GEAR_UP;//current_state value is 3
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
RaisingGear();
}
}
//GearUp
void GearUp(void) //prototype function definition
{
current_state=GEAR_UP;//current_state value is 3
printf("Enter the status of pilot's lever:");// we giving the lever values
fflush(stdout);//stores the values in &p1
scanf("%d",&pl);//stores the values in &p1
if(pl==falling)//when condition is true if statement works
{
current_state=CHECK_BEFORE_LANDING;//current_state value is 4
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
GearUp();
}
}
//CheckBeforeLanding
void CheckBeforeLanding(void) //prototype function definition
{
current_state=CHECK_BEFORE_LANDING;//current_state value is 4
printf("Enter the status of pilot's lever and hydraulic mechanism status:");//gives the lever value and hydraulic value
fflush(stdout);
scanf("%d %d",&pl,&hm);//stores the values in &p1 ,&hm
if(pl==falling && hm==working)//when condition is true if statement works
{
current_state=LOWERING_GEAR;//current_state value is 5
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
}
else if(pl==falling && hm==not_working)
{
current_state=LOWERING_GEAR;//current_state value is 5
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
printf("Status of gas pressurised Spring System:%s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status);
}
else if(pl==(Raising))
{
CheckBeforeLanding();
}
}
//LoweringGear.
void LoweringGear(void) //prototype function definition
{
current_state=LOWERING_GEAR;//current_state value is 5
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&pl,&limit_switch);
if(pl==falling && limit_switch==on)//when condition is true if statement works
{
current_state=CHECKING_BEFORE_TAKEOFF;//current_state value is 1
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
}
else if(pl==Raising && limit_switch==off)
{
current_state=GEAR_DOWN;
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
if(limit_switch==off)
{
LoweringGear();
}
}
void starting_State_Machine() //prototype function definition
{
current_state==GEAR_DOWN;//current_state value is 0
printf("The Finite State Machine is Intialized and current the program is in""GearDown State & Light is:%s\n",State_Machine[current_state].light);
}
OUTPUT :-


*****************************************************************************************************************







*****************************************************************************************************************