Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Question:
Overview of the Project: (5 to 6 lines)
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 ( 2 to 3 points)
Controlling the direction of Valve.
Controlling the retraction and extension of Airplane’s landing gear.
Key Highlights of the Project: (4 to 5 points)
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: (4 to 5 points)
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.
Expected Outcomes: (4 to 5 points)
The student will be getting the Knowledge of Finite State Machine 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.
Answer:
Step to Devlop the code:
- Inclusion of Header Files.
- Initialization of Variables
- Writing program for different cases(i.e. States in FSM)
- Main file includes
- While loop for continuous execution of program
- Writing if loops for various conditions of inputs
- calling States using switch case conditions(FSM implementation)
Code:
#include
#include
static volatile int Red_Light;
static volatile int Green_Light;
static volatile int LimitSw;
static volatile int SquatSw;
static volatile int PilotLv_Falling_edge;
static volatile int PilotLv_Rising_edge;
static volatile int ValveDir_UP;
static volatile int ValveDir_Down;
static volatile int PilotLVUP;
static volatile int PilotLVDN;
static volatile int Gear_ctrl;
void state_GearDown()//State 1
{
PilotLv_Falling_edge=0; //Input signal restore as per the actual condition
printf("Gear is Down\n");
Green_Light=1;
printf("Green Light is ON\n");
printf("Update Status of Pilots Lever Rising Edge Signal and Squat Switch Signal(1,0)\n"
"in case pilot started taking off otherwise(0,1)\n");
fflush(stdout);
scanf("%d %d",&PilotLv_Rising_edge,&SquatSw);
}
void state_CheckingBfrTakeoff()//State 2
{
PilotLv_Rising_edge=0;
printf("Airplane taking off \n");
Green_Light=1;
printf("Green Light is ON\n");
sleep(3);//Delay for checking before take off
printf("Update Status of Pilots Lever Falling Edge Signal and Squat\n"
" Switch Signal(0,0 in case of safe take off otherwise (1,1))\n");
fflush(stdout);
scanf("%d %d",&PilotLv_Falling_edge,&SquatSw);
printf("Update Status of Pilots Lever UP (1 in case of safe take off)\n");
fflush(stdout);
scanf("%d",&PilotLVUP);
}
void state_RisingGear()//State 3
{
PilotLVDN=0;
printf("Rising Gear UP\n");
Red_Light=1;
ValveDir_UP=1;
printf("Red Light is ON\n");
printf("Direction of Valve is UP\n");
printf("Update the status of Pilot Lever Falling Edge(1 in case pilot abort take off)\n");
fflush(stdout);
scanf("%d",&PilotLv_Falling_edge);
printf("Update the status of Limit Switch(1 in case of safe take off)\n");
fflush(stdout);
scanf("%d",&LimitSw);
}
void state_GearUp()//State 4
{
printf("Gear is UP\n");
Red_Light=0;
Green_Light=0;
Gear_ctrl=0;
printf("Red Light and Green Light are OFF\n");
printf("Gear Control is Disabled\n");
printf("Update the status of Pilot Lever Falling\n"
" Edge(1 in case pilot started landing procedure)\n");
fflush(stdout);
scanf("%d",&PilotLv_Falling_edge);
}
void state_CheckingbeforeLanding()//State 5
{
PilotLv_Falling_edge=0;
PilotLVUP=0;
printf("System is checking before landing\n");
Red_Light=1;
Gear_ctrl=1;
printf("Gear Control is Enabled\n");
printf("Red Light is ON\n");
printf("Update the status of Pilot Lever Down(1)\n");
fflush(stdout);
scanf("%d",&PilotLVDN);
}
void LoweringGear()//State 6
{
printf("Lowering Gears Down\n");
ValveDir_Down=1;
printf("Update the status of Pilots Lever Rising Edge signal\n"
"(1 in case off pilot aborted landing otherwise 0)\n");
fflush(stdout);
scanf("%d",&PilotLv_Rising_edge);
if(PilotLv_Rising_edge==1)
{
PilotLVDN=0;
}
printf("Update the status of Limit Switch(0 in case off landing gear fully down)\n");
fflush(stdout);
scanf("%d",&LimitSw);
}
int main()
{
int State=1;// considering Gear Down as Initial State
while(1)
{
if(SquatSw==1||PilotLv_Falling_edge==1)//Squatsw is closed or Pilots lever is falling
{
State=1;
}
if(LimitSw==0)//Limit Switch is Opened
{
State=1;
}
//State 2 Execution conditions
if(SquatSw==0&&PilotLv_Rising_edge==1)//Squatsw is closed or Pilots lever is falling
{
State=2;
}
if(PilotLv_Rising_edge==1)// Pilot aborted Landing
{
State = 2;
}
//State 3 Execution conditions
if(PilotLVUP==1)//Pilot lever is up
{
State=3;
}
//State 4 Execution conditions
if(LimitSw==1)//Limit Switch UP i.e. Gear UP
{
State=4;
}
//State 5 Execution conditions
if(PilotLv_Falling_edge==1)//Limit Switch UP i.e. Gear UP
{
State=5;
}
//State 6 Execution conditions
if(PilotLVDN==1)//
{
if(LimitSw==0)
{
State=1;
}
else
{
State=6;
}
}
switch(State)
{
case 1: state_GearDown();
break;
case 2: state_CheckingBfrTakeoff();
break;
case 3: state_RisingGear();
break;
case 4: state_GearUp();
break;
case 5: state_CheckingbeforeLanding();
break;
case 6: LoweringGear();
break;
}
}
return 0;
}
OUTPUT:
Case1 : Normal Operation of Take off and Landing,


Case 2: If Pilot Aborted Take off,

Case3: If Pilot aborted Landing,