Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Overview of the Project:
In this Project we used the finite State Machine concept for implementing of "controlling the retraction and extension of Airplane’s landing gear". FSM is mathematical model of computation. FSM can change its state from one to another based on some condition and also the input given to it. In this project there are set of condition which will help in knowing the exact state of the Airplane.
Goals:
- The main is to controll the retraction and extention of the airplane's landing Gear.
- To use the concept of FSM to implement this Project.
- To controll the direction valve.
Key Highlight:
- The Direction Valve is being controlled by the program which is done by analyzing the exact state of the gears and the state in which it is present which allow the hydralic to gear it up or down.
Deliverables of this Project:
- The knowledge of the FSM will help to set the exact condition so that the rectraction and extention of the landing gear would be done with aout any failure.
Code:
// Start of the program
#include<stdio.h>
#include<stdlib.h>
//Function Declaration: here each function represent a state
void Initial_state();
void Gear_Down();
void Checking_Before_Take_Off();
void Raising_Gear();
void Gear_Up();
void Checking_Before_Landing();
void Lowering_Gear();
// creating a function pointer
static void (* state_fun[]) (void) = {Gear_Down, Checking_Before_Landing, Raising_Gear, Gear_Up, Checking_Before_Landing, Lowering_Gear};
// Different State Types of the Landing Gear
typedef enum state
{
gear_down,
checking_before_take_off,
raising_gear,
gear_up,
checking_before_landing,
lowering_gear
} State_Type;
// Defining Switch State
typedef enum Switch
{
on,
off
} Switch_State;
// Position of the Pilot Lever
typedef enum Pilot_Lever
{
raising,
falling
} Pilot_Lever_State;
// Defining Hydraulic State
typedef enum Hydraulic_Mechanism
{
working,
notworking
} Hydraulic_State;
static volatile Switch_State limit_switch;
static volatile Switch_State squat_switch;
static volatile Pilot_Lever_State pls;
static volatile Hydraulic_State hs;
//State Variable
State_Type current_state;
typedef struct State_Table
{
char* current_state_indication;
char* light;
char* direction_valve_status;
char* landing_gear_hydraulic_control;
char* Gas_Pressurized_Spring_system_status[2];
} statetable;
// creating the state table
static statetable State_Machine[6]={{"GearDown","Green","Down","Enabled",{NULL,NULL}},
{"CheckingBeforeTakeOFF","Green","Down","Enabled",{NULL,NULL}},
{"RaisingGear","Red","Up","Enabled",{NULL,NULL}},
{"GearUp","Off","NULL","Disabled",{NULL,NULL}},
{"CheckBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
int main()
{
Initial_state(); // calling the initial state
while(1)//finite loop for knowing the exact present state.
{
state_fun[current_state]();
}
return 0;
}
// Function defining the Initial state of Gears
void Initial_state()
{
current_state= gear_down;
printf("The Finite State Machine has been intialized\n");
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
}
//Gear down State
void Gear_Down()
{
current_state = gear_down;
printf("Enter the Status of of Pilot Lever and Squat Switch");
scanf("%d %d",&pls, &squat_switch);
if(pls==raising && squat_switch==on) // Checking the condition for the change of the state.
{
current_state = checking_before_take_off;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
}
else
{
Gear_Down();
}
}
// Checking Before Take off state
void Checking_Before_Take_Off()
{
current_state = checking_before_take_off;
printf("Enter the Status of of Pilot Lever, Squat Switch and Hydraulic State ");
scanf("%d %d %d",&pls,&squat_switch,&hs);
if(pls==raising && squat_switch==on)
{
Gear_Down();
}
else if(pls== raising && squat_switch==on && hs==working)
{
current_state = raising_gear;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
printf("Status of Direction Valve %s\n",State_Machine[current_state].direction_valve_status);
}
else if(pls== raising && squat_switch==on && hs==notworking)
{
current_state = raising_gear;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
printf("Status of Direction Valve %s\n",State_Machine[current_state].direction_valve_status);
}
else
{
Checking_Before_Take_Off();
}
}
// Raising Gear State Definition
void Raising_Gear()
{
current_state = raising_gear;
printf("Enter the Status of of Pilot Lever and Limit Switch");
scanf("%d %d",&pls,&limit_switch);
if(pls== falling && limit_switch==off)
{
current_state = gear_up;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
printf("Status of Landing Gear Hydraulic Control %s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else if(pls== falling && limit_switch==on)
{
current_state = checking_before_landing;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
printf("Status of Direction Valve %s\n",State_Machine[current_state].direction_valve_status);
}
else
{
Raising_Gear();
}
}
// Gear Up State Definition
void Gear_Up()
{
current_state = gear_up;
printf("Enter the Status of of Pilot Lever");
scanf("%d",&pls);
if(pls== falling)
{
current_state = checking_before_landing;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
printf("Status of Direction Valve %s\n",State_Machine[current_state].direction_valve_status);
}
else
{
Gear_Up();
}
}
//Checking Befor Landing State Definition
void Checking_Before_Landing()
{
current_state = checking_before_landing;
printf("Enter the Status of of Pilot Lever and Hydraulic State ");
scanf("%d %d",&pls,&hs);
if(pls== raising && hs==working)
{
current_state = lowering_gear;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
printf("Status of Direction Valve %s\n",State_Machine[current_state].direction_valve_status);
}
else if(pls== raising && hs==notworking)
{
current_state = lowering_gear;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
printf("Status of Direction Valve %s\n",State_Machine[current_state].direction_valve_status);
}
else
{
Checking_Before_Landing();
}
}
//lowering Gear State Definition
void Lowering_Gear()
{
current_state = lowering_gear;
printf("Enter the Status of of Pilot Lever and Limit Switch");
scanf("%d %d",&pls,&limit_switch);
if(pls== falling && limit_switch==off)
{
current_state = gear_down;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
printf("Status of Landing Gear Hydraulic Control %s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else if(pls== falling && limit_switch==on)
{
current_state = checking_before_take_off;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light: %s\n",State_Machine[current_state].light);
printf("Status of Direction Valve %s\n",State_Machine[current_state].direction_valve_status);
}
else
{
Lowering_Gear();
}
}
// End of the Program.