Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
OVERVIEW OF THE PROJECT :
- In this project we are going to controll the retraction and extension of Airplane’s landing gear can be implemented using Finite State Machine (FSM).
- Airplane has three gears namely "Nose gear, Right gear, Left gear" .
- These gears are connected with a hydraulic pump for the pull up and push down works.
- These gears are responsible for the Aircraft for takeoff and landing.
GOAL OF THE PROJECT:
- Valve direction can be easily controlled
- Controlling of Extension and retraction of airplane landing gear.
KEY HIGHLIGHT OF THE PROJECT:
- The gear has a direction valve, this is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.
- 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.
DELIVERABLES OF THE PROJECT :
- An airplane gear has six state namely"Gear down, cheak before takeoff, Raising up, Gear down, cheak before landing, Lowering gear".
- Each state has a algorithm and perform a certain action that is responsible for the state change.
EXPECTED OUTCOMES:
Gear down;
Current status-Geardown
Light-Green
Direction valve-Down
Hydraulic mechanism-Enabled
Check before takeoff;
Current status-check before takeoff
Light-Green
Direction valve-Down
Hydraulic mechanism-Enabled
Raising gear;
Current status-Raising gear
Light-Red
Direction valve-Up
Hydraulic mechanism-Enabled
Gear Up;
Current status-GearUp
Light-Close
Direction valve-Null
Hydraulic mechanism-Disabled
Check before landing;
Current status- Check before landing
Light-Red
Direction valve-Down
Hydraulic mechanism-Enabled
Lowering gear;
Current status-Lowering gear
Light-Green
Direction valve-Down
Hydraulic mechanism-Enabled
CODE:
#include
void Gear_Down();
void Check_before_Takeoff();
void Raising_Gear();
void Gear_Up();
void Check_before_Landing();
void Lowering_Gear();
//These are the function we're going to implement in this program
typedef enum
{
GEAR_DOWN,
CHECK_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECK_BEFORE_LANDING,
LOWERING_GEAR
}State_Type;
//squat switch conditions
typedef enum
{
Open,
Close
}Switch;
typedef enum
{
Rising,
Falling,
}Pilot_lever;
typedef enum
{
Working,
Not_Working
}Hydraulic_Mechanism;
static volatile Switch Squat;
static volatile Switch Limit;
static volatile Pilot_lever Pilevel;
static volatile Hydraulic_Mechanism Hymech;
State_Type Current_State;
typedef struct{
char* Current_State;
char* Light;
char* Direction_valve;
char* Hydraulic_control;
} State;
//Array of function pointer
static void(*State_Table[])(void)={Gear_Down,Check_before_Takeoff,Raising_Gear,Gear_Up,Check_before_Landing,Lowering_Gear};
static State State_Machine[6]={{"Gear_Down","Green","Down","Enabled"},
{"Check_before_Takeoff","Green","Down","Enabled"},
{"Raising_Gear","Red","Up","Enabled"},
{"Gear_Up","Close","Null","Disabled"},
{"Check_before_Landing","Red","Down","Enabled"},
{"Lowering_Gear","Green","Down","Enabled"}
};
int main()//Main function
{
while(1)
{
State_Table[Current_State]();
}
}
//Gear down State
void Gear_Down()
{
Current_State=GEAR_DOWN;
printf("n Enter the status of Pilevel and Squat:");
fflush(stdout);
scanf("%d %d", &Pilevel, &Squat);
if(Pilevel==Rising && Squat==Open) // if this condition satisfies the state changes to next state
{
Current_State=CHECK_BEFORE_TAKEOFF;
printf("n %s",State_Machine[Current_State].Current_State);
printf("n %s",State_Machine[Current_State].Light);
printf("n %s",State_Machine[Current_State].Direction_valve);
printf("n %s",State_Machine[Current_State].Hydraulic_control);
}
else
{
Gear_Down();
}
}
// Cheak before takeoff State
void Check_before_Takeoff()
{
Current_State=CHECK_BEFORE_TAKEOFF;
printf("n Enter the status of Pilevel,Squat and Hymech:");
fflush(stdout);
scanf("%d %d %d",&Pilevel,&Squat,&Hymech);
if(Pilevel==Falling && Squat==Close) //if this condition satisfies the state changes to previous state
{
Current_State=GEAR_DOWN;
printf("n %s",State_Machine[Current_State].Current_State);
printf("n %s",State_Machine[Current_State].Light);
printf("n %s",State_Machine[Current_State].Direction_valve);
printf("n %s",State_Machine[Current_State].Hydraulic_control);
}
if(Pilevel==Rising && Hymech==Working)
{
Current_State=RAISING_GEAR;//if this condition satisfies the state changes to next state
printf("n %s",State_Machine[Current_State].Current_State);
printf("n %s",State_Machine[Current_State].Light);
printf("n %s",State_Machine[Current_State].Direction_valve);
printf("n %s",State_Machine[Current_State].Hydraulic_control);
}
else
{
Check_before_Takeoff();
}
}
//Raising gear State
void Raising_Gear()
{
Current_State=RAISING_GEAR;
printf("n Enter the status of Pilevel and Limit switch:");
fflush(stdout);
scanf("%d %d",&Pilevel,&Limit);
if(Pilevel==Falling)//if this condition satisfies the state changes to next state
{
Current_State=CHECK_BEFORE_LANDING;
printf("n %s",State_Machine[Current_State].Current_State);
printf("n %s",State_Machine[Current_State].Light);
printf("n %s",State_Machine[Current_State].Direction_valve);
printf("n %s",State_Machine[Current_State].Hydraulic_control);
}
if(Limit==Close)//if this condition satisfies the state changes to next state
{
Current_State=GEAR_UP;
printf("n %s",State_Machine[Current_State].Current_State);
printf("n %s",State_Machine[Current_State].Light);
printf("n %s",State_Machine[Current_State].Direction_valve);
printf("n %s",State_Machine[Current_State].Hydraulic_control);
}
}
//gear up State
void Gear_Up()
{
Current_State=GEAR_UP;
printf("n Enter the status of Pilevel:");
fflush(stdout);
scanf("%d",&Pilevel);
if(Pilevel==Falling)//if this condition satisfies the state changes to next state
{
Current_State=CHECK_BEFORE_LANDING;
printf("n %s",State_Machine[Current_State].Current_State);
printf("n %s",State_Machine[Current_State].Light);
printf("n %s",State_Machine[Current_State].Direction_valve);
printf("n %s",State_Machine[Current_State].Hydraulic_control);
}
else
{
Gear_Up();
}
}
//check before landing State
void Check_before_Landing()
{
Current_State=CHECK_BEFORE_LANDING;
printf("n Enter the status of Pilevel and Hymech:");
fflush(stdout);
scanf("%d,%d",&Pilevel,&Hymech);
if(Pilevel==Falling||Hymech==Not_Working)//if this condition satisfies the state changes to next state
{
Current_State=LOWERING_GEAR;
printf("n %s",State_Machine[Current_State].Current_State);
printf("n %s",State_Machine[Current_State].Light);
printf("n %s",State_Machine[Current_State].Direction_valve);
printf("n %s",State_Machine[Current_State].Hydraulic_control);
}
else
{
Check_before_Landing();
}
}
//Lowering gear State
void Lowering_Gear()
{
Current_State=LOWERING_GEAR;
printf("n Enter the status of Squat and Pilevel: ");
fflush(stdout);
scanf("%d %d",&Squat,&Pilevel);//if this condition satisfies the state changes to next state
if(Squat==Close)
{
Current_State=GEAR_DOWN;
printf("n %s",State_Machine[Current_State].Current_State);
printf("n %s",State_Machine[Current_State].Light);
printf("n %s",State_Machine[Current_State].Direction_valve);
printf("n %s",State_Machine[Current_State].Hydraulic_control);
}
if(Pilevel==Rising)//if this condition satisfies the state changes to next state
{
Current_State=CHECK_BEFORE_TAKEOFF;
printf("n %s",State_Machine[Current_State].Current_State);
printf("n %s",State_Machine[Current_State].Light);
printf("n %s",State_Machine[Current_State].Direction_valve);
printf("n %s",State_Machine[Current_State].Hydraulic_control);
}
else
{
Lowering_Gear();
}
}