Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Overview of the 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.
- Controlling the retraction and extension of Airplane’s landing gear.
Key Highlights of the Project:
A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the 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.
Main function:
#include
#include"States.h"
static void(*state_table[])(void)
{Gear_Down, Checking_Before_takeoff, Raising_Gear, Gear_Up, Checking_Before_landing, Lowering_Gear};
int main()
{
Init_State_Machine();
while(1)
{
state_table[current_state]();
}
}
Program Functions:
Gear Up:
#include "States.h"
#include
void Gear_Up()
{
current_state = GR_UP;
printf("\nEnter the Pilot's Lever Position:");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Falling)
{
current_state = CHK_BFR_LND;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
}
else
{
Gear_Up();
}
}
Gear Down:
#include "States.h"
#include
void Gear_Down(void)
{
current_state = GR_UP;
printf("\nEnter the Pilot's Lever Position and Squat Switch Status:");
fflush(stdout);
scanf("%d %d",&pilot_lever, &squat_switch);
if(pilot_lever == Rising && squat_switch == Open)
{
current_state = CHK_BFR_TKFF;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
}
else
{
Gear_Down();
}
}
Raising Gear:
#include "States.h"
#include <stdio.h>
void Raising_Gear()
{
current_state = GR_UP;
printf("\nEnter the Limit Switch Status & Pilot's Lever Status:");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if(pilot_lever == Falling && limit_switch == Open)
{
current_state = CHK_BFR_LND;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
}
else if(limit_switch == Close && pilot_lever == UP)
{
current_state = GR_UP;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
}
else
{
Raising_Gear();
}
}
Initial State Machine:
#include "States.h"
void Init_State_Machine()
{
//System Initialized and its in State_A
current_state = GR_DWN;
printf("\nState Machine is initialized & Program is in Gear_Down State & Light Status : %s\n"),State_Machine[current_state].light_status);
}
Checking Before Landing:
#include <stdio.h>
#include <States.h>
void Checking_Before_Landing()
{
current_state = CHK_BFR_LND;
printf("\nEnter the Pilot's Lever Position and Hydraulic Mechanism Status:");
fflush(stdout);
scanf("%d %d" ,&pilot_lever,&hydraulic_mechanism);
if(pilot_lever == Down || hydraulic_mechanism == Working)
{
current_state = LWRNG_GR;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_valve_status);
}
else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)
{
current_state = LWRNG_GR;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_valve_status);
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
else(pilot_lever == (UP || Rising || Falling))
{
Checking_Before_Landing();
}
}
Checking Before Takeoff:
#include <stdio.h>
#include <States.h>
void Checking_Before_Takeoff()
{
current_state = CHK_BFR_TKFF;
printf("\nEnter the Pilot's Lever Position, Sqat Switch Status and Hydraulic Mechanism Status:");
fflush(stdout);
scanf("%d %d %d" ,&pilot_lever, &squat_switch, &hydraulic_mechanism);
printf("\nWait for 2 sec\n");
if(pilot_lever == Falling || squat_switch == Close)
{
Gear_Down();
}
else if(pilot_lever == UP && squat_switcg == Open && hydraulic_mechanism == Working)
{
current_state = RSING_GR;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_valve_status);
}
else if(pilot_lever == UP && squat_switcg == Open && hydraulic_mechanism == Malfunctioning)
{
printf("Light Status:%s\n",State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_valve_status);
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
}
Header File:
#ifndef STATES_H_
#define STATES_H_
//Functions
void init_State_Machine();
void gear_down();
void Checking_Before_Takeoff();
void raising_gear();
void gear_Up();
void Checking_Before_Landing();
typedef enum State
{
GR_DWN,
CHK_BFR_TKFF,
RSING_GR,
CHK_BFR_LND,
LWRNG_GR
}State_Type;
typedef enum Switch
{
Open,
Close
}Switch_Status;
typedef enum Pilot_Lever
{
Rising,
Falling,
Up,
Down
}Pilot_Lever_Status;
typedef enum Hydraulic_Mechanism
{
Working,
Malfunctioning
}Hydraulic_Mechanism_Status;
//Input for changing the State
static volatile Switch_Status squat_switch;
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;
char* light_status;
char* direction_pump_control_status;
char* gas_pressurized_spring_status[2];
}State_Table;
static State_Table State_Machine[6] = {
{"GearDown","Green","Down","Enabled",0,0},
{"Checking_Before_Take_Off","Green","Down","Enabled",0,0},
{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"Gear Up","Off","Null","Enabled",{"Disabled","Enabled"}},
{Checking_Before_Landing}
};
#endif /* STATES_H_ */