Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
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.
PROGRAM:
/*
* project2.c
*
* Created on: 20-Apr-2023
* Author: Admin
*/
#include<stdio.h>
#include<stdlib.h>
//function prototyping
void Initial_state_machine();
void GearDown();
void CheckingBeforeTakeOff();
void RaisingGear();
void GearUP();
void CheckBeforeLanding();
void LoweringGear();
typedef enum State_Type
{
Gear_Down,
Checking_before_takeoff,
Raising_Gear,
Gear_Up,
Checking_before_landing,
Lowering_Gear
}state_val;
typedef enum Switch
{
open,
close
}switch_val;
typedef enum Pilot_Lever
{
Up,
Down,
Raising,
Falling
}pilot_lav;
typedef enum Hydraulic_Mechanism
{
working,
not_working
}hydraulic_val;
static volatile switch_val limit_switch;
static volatile switch_val squat_switch;
static volatile pilot_lav pilot_lever;
static volatile hydraulic_val hydraulic_mechanism;
state_val current_state;
typedef struct
{
char* next_state;
char* light;
char* direction_valve;
char* hydraulic_control;
}state_table;
static void(*stateTable[])(void)={GearDown, CheckingBeforeTakeOff, RaisingGear, GearUP, CheckBeforeLanding, LoweringGear};
static state_table State_Machine[6]={
{"Gear_Down", "Green", "Down", "Enabled"},
{"Checking_before_takeoff", "Green","Down", "Enabled"},
{"Raising_Gear", "Red", "Up", "Enabled"},
{"Gear_Up"," close", "Null", "Disabled"},
{"Checking_before_landing", "Red" ,"Down", "Enabled"},
{"Lowering_Gear", "Green" , "Down", "Enabled"}
};
void Initial_state_machine()
{
current_state = Gear_Down; //during initialization, system is at gear down.
printf("\n state machine is initials and at first program is in gear down and its light status is:%s\n",State_Machine[current_state].light);
}
void GearDown(void)
{
current_state=Gear_Down;
printf("Enter the status of pilot's lever and squat switch:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch);
if((pilot_lever==Raising)&& (squat_switch==open))//input is 2 0
{
current_state=Checking_before_takeoff;//if the condition is true current state is changed
printf("Next state: %s\n", State_Machine[current_state].next_state);
printf("Light is : %s \n", State_Machine[current_state].light);
printf("direction valve is : %s \n", State_Machine[current_state].direction_valve);
printf("hydraulic control is : %s \n", State_Machine[current_state].hydraulic_control);
}
else
{
GearDown();//until it calls the Funtions when it becomes true
}
}
void CheckingBeforeTakeOff()
{
current_state=Checking_before_takeoff;
printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism:");
fflush(stdout);
scanf("%d %d %d", &pilot_lever, &squat_switch, &hydraulic_mechanism);
if((pilot_lever==Falling)&& (squat_switch==close))//input is 3 1
{
current_state=Gear_Down;//if the condition is true current state is changed
printf("Next state: %s\n", State_Machine[current_state].next_state);
printf("Light is : %s \n", State_Machine[current_state].light);
printf("direction valve is : %s \n", State_Machine[current_state].direction_valve);
printf("hydraulic control is : %s \n", State_Machine[current_state].hydraulic_control);
}
else if((pilot_lever==Up)&& (hydraulic_mechanism==working))//input is 0 0
{
current_state=Raising_Gear;//if the condition is true current state is changed
printf("Next state: %s\n", State_Machine[current_state].next_state);
printf("Light is : %s \n", State_Machine[current_state].light);
printf("direction valve is : %s \n", State_Machine[current_state].direction_valve);
printf("hydraulic control is : %s \n", State_Machine[current_state].hydraulic_control);
}
else
{
CheckingBeforeTakeOff();//until it calls the Funtions when it becomes true
}
}
void RaisingGear()
{
current_state=Raising_Gear;
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&limit_switch);
if(pilot_lever==Falling)//input value is 3
{
current_state=Checking_before_landing;//if the condition is true current state is changed
printf("Next state: %s\n", State_Machine[current_state].next_state);
printf("Light is : %s \n", State_Machine[current_state].light);
printf("direction valve is : %s \n", State_Machine[current_state].direction_valve);
printf("hydraulic control is : %s \n", State_Machine[current_state].hydraulic_control);
}
else if(limit_switch==close)// input value is 1
{
current_state=Gear_Up;//if the condition is true current state is changed
printf("Next state: %s\n", State_Machine[current_state].next_state);
printf("Light is : %s \n", State_Machine[current_state].light);
printf("direction valve is : %s \n", State_Machine[current_state].direction_valve);
printf("hydraulic control is : %s \n", State_Machine[current_state].hydraulic_control);
}
else{
RaisingGear();//until it calls the Funtions when it becomes true
}
}
void GearUP()
{
current_state=Gear_Up;
printf("Enter the status of pilot's lever:");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever==Falling)//input value is 3
{
current_state=Checking_before_landing;//if the condition is true current state is changed
printf("Next state: %s\n", State_Machine[current_state].next_state);
printf("Light is : %s \n", State_Machine[current_state].light);
printf("direction valve is : %s \n", State_Machine[current_state].direction_valve);
printf("hydraulic control is : %s \n", State_Machine[current_state].hydraulic_control);
}
else
{
GearUP();//until it calls the Funtions when it becomes true
}
}
void CheckBeforeLanding()
{
current_state=Checking_before_landing;
printf("Enter the status of pilot's lever and hydraulic mechanism status :");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
if((pilot_lever==Down)&&( hydraulic_mechanism==not_working))//input value is 1 1
{
current_state=Lowering_Gear;//if the condition is true current state is changed
printf("Next state: %s\n", State_Machine[current_state].next_state);
printf("Light is : %s \n", State_Machine[current_state].light);
printf("direction valve is : %s \n", State_Machine[current_state].direction_valve);
printf("hydraulic control is : %s \n", State_Machine[current_state].hydraulic_control);
}
else
{
CheckBeforeLanding();//until it calls the Funtions when it becomes true
}
}
void LoweringGear()
{
current_state=Lowering_Gear;
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if(limit_switch==open)//input value is 0
{
current_state=Gear_Down;//if the condition is true current state is changed
printf("Next state: %s\n", State_Machine[current_state].next_state);
printf("Light is : %s \n", State_Machine[current_state].light);
printf("direction valve is : %s \n", State_Machine[current_state].direction_valve);
printf("hydraulic control is : %s \n", State_Machine[current_state].hydraulic_control);
}
else if(pilot_lever==Raising)//input value is 2
{
current_state=Checking_before_takeoff;//if the condition is true current state is changed
printf("Next state: %s\n", State_Machine[current_state].next_state);
printf("Light is : %s \n", State_Machine[current_state].light);
printf("direction valve is : %s \n", State_Machine[current_state].direction_valve);
printf("hydraulic control is : %s \n", State_Machine[current_state].hydraulic_control);
}
else
{
LoweringGear();//until it calls the Funtions when it becomes true
}
}
int main()
{
Initial_state_machine();//calling the initial function
while(1)
{
stateTable[current_state]();
}
}
Result:


Expected Outcomes:
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.