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 using the concept of FSM to implement a code for controller of an airplane Landing and Takeoff mechanism. Basically we have a landing gear which has two major objectives retracting and extending. Retracting comes into picture immediately after takeoff and extension will be exactly before the landing of the airplane. This entire working is materialised using a finite state machine algorithm to be more precise using Moore Model (Output depends on only current state). The provided FSM consists of 6 states which are Gear Down, Checking Before Takeoff, Raising Gear, Gear Up, Checking Before Landing, Lowering Gear. The entire systems trnsits among these six states depending on various inputs such as Pilot Lever Status, Squat Switch Status, Limit Switch and output such as Direction Valve Staus, Light status, Landing Gear Control Status.
Goals:
- Giving the user most effecient and optimal code with point blank accuracy with no scope of compriomise in the safety of the airplane.
- Improvised and clear differenciation between two different states and giving the correct expected output as per the defined state diagram.
- Controlling of Retracting and Extending mechanism of Landing Gear of the Aeroplane along with the direction valve.
Key Highlights of the Project:
- We have taken into consideration various real time objects of landing gear mechanism such as Limit switch, Squat switch and comeup with a code module for airplane landing gear.
- All three landing gears are used which includes Nose Gear, Left Gear, Right Gear. Nose Gear will be in the front where as the left and right gears are near the belly of the aircraft.
- Direction valve is also considered which actually looks after the pressure which helps the user understand the current condition of the aircraft.
- If direction valve is up it means the aircraft is taking off.
- If the direction valve is down it means the aicraft is either Landed or is about to land.
- Light Indicators are used RED for transition(Raising or Lowering), GREEN for Gear Down, Light Off for Gear Up.
Deliverables of this Project:
- Here through this project we are delivering a fully functional landing gear mecahnism code for the aircraft controller by considering all the real time aspects.
- It consists of various copncepts of C programming which includes functions, enums, labels, switch cases
- We have used Enum to define various states of Finite State Machine and positions of limit switch, squat switch, pilot lever.
- Functions to define the functionality and behaviour of each state of the finite state machine.
- Labels to help user and prevent user from entering undefined values to the program and thereby preventing unexpected failures in the safety critical application program.
- Switch Case is used whereever there is possibility of transition into two different states such as in case of
Raising Gear -> Gear Up/ Check Before Landing.
Lowering Gear -> Gear Down/ Check Before Takeoff
Expected Outcomes:
- I have successfully learnt and implemented various concepts of C programming in this project such as functions, Enum, Switch Case, Labels.
- I have studied about the types of state machines such as Mealy(Output is Present State & Present Input Dependent) & Moore State Machine(Output Present State Dependent).
- I have learnt about the landing gear mechanism of the aircraft and its functional blocks.
- I have learnt about various Knobs, Gears, Switches, Valves of an complicated realtime aircraft along with their functioning.
Code:
#include<stdio.h> //Preprocessor for functions like printf(),Scanf()
void state_machine(); // Declaring Function for initialising state machine
void check_before_takeoff(); // Declaring Function for state: Checking before takeoff
void raising_gear(); // Declaring Function for state: Raising Gear
void lowering_gear(); // Declaring Function for state: Lowering Gear
void gear_down(); // Declaring Function for state: Gear Down
void gear_up(); // Declaring Function for state: Gear Up
void check_before_landing(); // Declaring Function for state: Check before Landing
// Enum for defining state types
enum State_Type { Gear_Down=0,
Check_Before_Takeoff,
Raising_Gear,
Gear_Up,
Check_Before_Landing,
Lowering_Gear
};
// Enum for defining Squat Switch positions
enum Squat_Switch_Status {
open=0,
close
};
// Enum for defining Limit Switch positions
enum Limit_Switch_Status {
lopen=0,
lclose
};
// Enum for defining Pilot Lever positions
enum Pilot_Lever_Status {
Falling=0,
Rising,
Up,
Down
};
// Enum for defining Hydraulic Mechanism status
enum Hydraulic_Mechanism_Status {
Working=0,
Malfunctioning
};
// Instatiation of Enum Objects
enum State_Type st;
enum Squat_Switch_Status ss;
enum Limit_Switch_Status ls;
enum Pilot_Lever_Status pls;
enum Hydraulic_Mechanism_Status hms;
// Main function of the program
int main()
{
state_machine(); // Initialising State machine
while(1)
{ if(st==Gear_Down)
{
gear_down(); // Calling Gear Down function based on condition
}
if(st==Check_Before_Takeoff)
{
check_before_takeoff(); // Calling Check Before Takeoff function based on condition
}
if(st==Raising_Gear)
{
raising_gear();
}
if(st==Check_Before_Landing)
{
check_before_landing(); // Calling Check Before Landing function based on condition
}
if(st==Lowering_Gear)
{
lowering_gear(); // Calling Lowering Gear function based on condition
}
if(st==Gear_Up)
{
gear_up(); // Calling Gear Up function based on condition
}
}
return 0;
}
void state_machine() // Defining Function for initialising state machine
{
printf("\n*****************************************\n");
printf(" Welcome to Aircraft Controller Module\n\n");
printf(" Current State = Gear Down State\n");
ls=lopen;
ss=close;
pls=Falling;
st=Gear_Down;
}
void gear_down() // Defining Function for Gear Down state
{
pilot:
printf("\n Please Enter Pilot Lever Position\n ");
printf("[0] for Falling\n [1] for Rising\n [2] for Up\n [3] for Down\n ");
fflush(stdout);
scanf("%d",&pls);
if(pls!=0 && pls!=1 && pls!=2 && pls!=3)
{
printf(" [%d] is Invalid Input\n ",pls);
goto pilot;
}
squat:
printf("\n Please Enter Squat Switch Position\n ");
printf("[1] for Closed\n [0] for Open\n ");
fflush(stdout);
scanf("%d",&ss);
if(ss!=0 && ss!=1)
{
printf(" [%d] is Invalid Input\n ",ss);
goto squat;
}
if(pls==1 || ss==0)
{
printf("\n Lights: GREEN\n\n");
printf(" Current State = Check Before Takeoff State\n\n");
printf(" Delay = 3 seconds\n");
st=Check_Before_Takeoff;
}
}
void raising_gear() // Defining Function for Raising Gear state
{
int i;
printf("Press [1] for Selecting Pilot Lever\n Press [2] for selecting Limit Switch\n ");
fflush(stdout);
scanf("%d",&i);
switch(i)
{
case 1:
pilot:
printf("\n Please Enter Pilot Lever Position\n ");
printf("[0] for Falling\n [1] for Rising\n [2] for Up\n [3] for Down\n ");
fflush(stdout);
scanf("%d",&pls);
if(pls!=0)
{
printf(" [%d] is Invalid Input\n\n ",pls);
goto pilot;
}
if(pls==0)
{
printf("\n Current State = Check Before Landing State\n");
printf("\n Lights: RED\n\n ");
st=Check_Before_Landing;
}
break;
case 2:
lswitch:
printf("\n Please Enter Limit Switch Position\n ");
printf("[1] for Closed\n [0] for Open\n ");
fflush(stdout);
scanf("%d",&ls);
if(ls!=1)
{
printf(" [%d] is Invalid Input\n\n ",ls);
printf("Only option [1] for Limit Switch is allowed\n ",pls);
goto lswitch;
}
if(ls==1)
{
printf("\n Current State = Gear Up State\n");
printf("\n Landing Gear Control Disabled\n");
printf("\n Lights: OFF\n\n ");
st=Gear_Up;
}
break;
}
}
void gear_up() // Defining Function for Gear Up state
{
pilot:
printf("\n Please Enter Pilot Lever Position\n ");
printf("[0] for Falling\n [1] for Rising\n [2] for Up\n [3] for Down\n ");
fflush(stdout);
scanf("%d",&pls);
if(pls!=0)
{
printf(" [%d] is Invalid Input\n ",pls);
printf("Only option [0] for Pilot Lever falling is allowed\n ",pls);
goto pilot;
}
if(pls==0)
{
printf(" Current State = Check Before Landing State\n\n");
printf(" Landing Gear Control Enabled\n\n");
printf("\n Lights: RED\n\n");
st=Check_Before_Landing;
}
}
void check_before_takeoff() // Defining Function for Check Before Takeoff state
{
pilot:
printf("\n Please Enter Pilot Lever Position\n ");
printf("[0] for Falling\n [1] for Rising\n [2] for Up\n [3] for Down\n ");
fflush(stdout);
scanf("%d",&pls);
if(pls!=0 && pls!=1 && pls!=2 && pls!=3)
{
printf(" [%d] is Invalid Input\n ",pls);
goto pilot;
}
if(pls==2)
{
printf("\n Current State = Raising Gear State\n");
printf("\n Direction Valve: UP\n\n Lights: RED\n\n ");
st=Raising_Gear;
}
else if(pls==0 || ss==1)
{
printf("\n Current State = Gear Down State\n");
printf("\n Lights: RED\n");
st=Gear_Down;
}
}
void check_before_landing() // Defining Function for Check Before Landing state
{
pilot:
printf("\n Please Enter Pilot Lever Position\n ");
printf("[0] for Falling\n [1] for Rising\n [2] for Up\n [3] for Down\n ");
fflush(stdout);
scanf("%d",&pls);
if(pls!=0 && pls!=1 && pls!=2 && pls!=3)
{
printf(" [%d] is Invalid Input\n ",pls);
goto pilot;
}
if(pls==3)
{
printf("\n Current State = Lowering Gear State\n");
printf("\n Direction Valve = Down\n\n ");
st=Lowering_Gear;
}
}
void lowering_gear() // Defining Function for Lowering Gear state
{
int i;
printf("\n Press [1] for Selecting Pilot Lever\n Press [2] for selecting Limit Switch\n ");
fflush(stdout);
scanf("%d",&i);
switch(i)
{
case 1:
pilot:
printf("\n Please Enter Pilot Lever Position\n ");
printf("[0] for Falling\n [1] for Rising\n [2] for Up\n [3] for Down\n ");
fflush(stdout);
scanf("%d",&pls);
if(pls!=1)
{
printf(" [%d] is Invalid Input\n ",pls);
printf("Only option [1] for Pilot Lever Raising is allowed\n ",pls);
goto pilot;
}
if(pls==1)
{
printf("\n Current State = Check Before Takeoff State\n");
printf("\n Delay = 3 seconds\n");
printf("\n Lights: RED\n\n ");
st=Check_Before_Takeoff;
}
case 2:
lswitch:
printf("\n Please Enter Limit Switch Position\n ");
printf("[1] for Closed\n [0] for Open\n ");
fflush(stdout);
scanf("%d",&ls);
if(ls!=0)
{
printf(" [%d] is Invalid Input\n\n ",ls);
printf("Only option [0] for Limit Switch is allowed\n ",pls);
goto lswitch;
}
if(ls==0)
{
printf("\n Current State = Gear Down State\n");
printf("\n Lights: GREEN\n\n ");
st=Gear_Down;
}
break;
}
}
Code Screenshots:
Function Declarations & Enum Definitions

Instantiation of Enum Objects

Main Function

Definition of State Machine Initialisation Function and Gear Down Function

Raising Gear Function Definition

Definition of Gear Up Function

Definition of Check Before Take of Function & Check Before Landing

Definition of Lowering Gear Function

Continuation...Definition of Lowering Gear Function

Output Screenshots:
Initialisation of State Machine(Gear Down State) and transition to Check Before Take Off State.

Transition from Check Before Take Off State to Raising Gear State

Transition from Check Before Take Off State to Gear Down State

Transition from Raising Gear State to Check Before Landing State

Transition from Raising Gear State to Gear Up State

Transition from Gear Up to Check Before Landing State

Transition from Check Before Landing State to Lowering Gear State

Transition from Lowering Gear State to Check Before Take Off State

Transition from Lowering Gear State to Gear Down State
