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 the Airplane’s landing gear.
Overview of the Project:
In this project, controlling the retraction and extension of the Airplane’s landing gear can be implemented using Finite State Machine (FSM). FSM is the most efficient algorithm which is a mathematical model of computation.
Goals :
- Controlling the direction of Valve.
- Controlling the retraction and extension of the 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 the Airplane’s landing gear using the Finite state machine with the knowledge of various states of switch and gear.
Expected Outcomes:
The student will be getting the Knowledge of Finite State Machine algorithm which is used to achieve control over the retraction and extension of the Airplane’s landing gear using the switch and gear states of the Airplane.
Answer-
/*
* Project_2_Main.c
*
* Created on: 02-Aug-2023
* Author: Sachin Kushare
* Copyright : Your copyright notice
Description : Implement the Code for controlling the retraction and extension of Airplane’s landing gear
*/
#include<stdio.h>
#include "state.h"
static void (*state_table[])(void)={GearDown,CheckingBeforeTakeOff,RaisingGear,GearUp,CheckBeforeLanding,LoweringGear}; /*Here we static to declare the global variables*/
int main() /*Main Function*/
{
Initiate_State_Machine();
while(1)
{
state_table[current_state]();
}
}
/*
* State.h
*
* Created on: 02-Aug-2023
* Author: Sachin Kushare
*/
#ifndef STATE_H_
#define STATE_H_
void Initiate_State_Machine(); /*Here We declare the function Initiate State Machine */
void GearDown(); /*Here We declare the function Gear Down */
void CheckingBeforeTakeOff(); /*Here We declare the function Checking Before TakeOff */
void RaisingGear(); /*Here We declare the function Raising Gear */
void GearUp(); /*Here We declare the function Gear Up */
void CheckBeforeLanding(); /*Here We declare the function Check Before Landing */
void LoweringGear(); /*Here We declare the function Lowering Gear */
typedef enum State /*Here we declare the Enum for the State*/
{
GEAR_DOWN, /*Here value of GEAR_DOWN=0*/
CHECKING_BEFORE_TAKEOFF, /*Here value of CHECKING_BEFORE_TAKEOFF=1*/
RAISING_GEAR, /*Here value of RAISING_GEAR=2*/
GEAR_UP, /*Here value of GEAR_UP=3*/
CHECK_BEFORE_LANDING, /*Here value of CHECK_BEFORE_LANDING=4*/
LOWERING_GEAR /*Here value of LOWERING_GEAR=5*/
}State_Type;
typedef enum Switch /*Here we declare the Enum for the Switch*/
{
Open, /*Here value of Open=0*/
Close /*Here value of Close=1*/
}Switch_status;
typedef enum Pilot_Lever /*Here we declare the Enum for the Pilot_Lever*/
{
Raising, /*Here value of Raising=0*/
Falling, /*Here value of Falling=1*/
Up, /*Here value of Up=2*/
Down /*Here value of Down=3*/
}Pilot_lever_Status;
typedef enum Hydraulic_Mechanism /*Here we declare the Enum for the Hydraulic Mechanism*/
{
working, /*Here value of working=0*/
Malfunctioaning /*Here value of Malfunctioning=1*/
}Hydraulic_Mechanism_Status;
static volatile Switch_status squat_switch; /*Here we declare the variables using static volatile because in the program we want to change the value of variable multiple time */
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 /*Here We used typedef with structure to define a new data type and then use that data type to define structure variables directly*/
{
char* current_state_indication;
char* light_status;
char* direction_valve_status;
char* gas_pressurized_spring_status[2];
char* hydraulic_pump_control_status;
}State_Table;
static State_Table State_Machine[6]= /*Here we declare the global variable for State_Machine */
{
{"GearDown","Green","Down","Enabled",0,0},
{"CheckingBeforeTakeOff","Green","Down","Enabled",0,0},
{"RaisingGear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"GearUp","Off","Null","Disabled",0,0},
{"CheckBeforeLanding","Red","Down","Enabled",0,0},
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
#endif /* STATE_H_ */
/*
* Raising_Gear.c
*
* Created on: 02-Aug-2023
* Author: Sachin Kushare
*/
#include<stdio.h>
#include "state.h"
/*Raising Gear*/
void RaisingGear(void) /*Here we define the Raising Gear*/
{
current_state= RAISING_GEAR;
printf("\n Enter the status of pilot's lever and limit switch :");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
printf("\n Wait for 1secs \n");
if(pilot_lever==Falling && limit_switch==Open)
{
current_state= CHECK_BEFORE_LANDING;
printf("Current 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(pilot_lever==Up && limit_switch==Close)
{
current_state= GEAR_UP;
printf("Current 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
{
RaisingGear();
}
}
/*
* Lowering_Gear.c
*
* Created on: 02-Aug-2023
* Author: Sachin Kushare
*/
#include "state.h"
#include<stdio.h>
/*Lowering Gear*/
void LoweringGear(void) /*Here we define the Lowering Gear*/
{
current_state= LOWERING_GEAR;
printf("\n Enter the status of pilot's lever and limit switch :");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if(pilot_lever==Raising && limit_switch==Close)
{
current_state= CHECKING_BEFORE_TAKEOFF;
printf("\n Current state : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n",State_Machine[current_state].light_status);
}
if(pilot_lever==Down && limit_switch==Open)
{
current_state= GEAR_DOWN;
printf("Current 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
{
LoweringGear();
}
}
/*
* Initiate_State_Machine.c
*
* Created on: 02-Aug-2023
* Author: Sachin Kushare
*/
#include "state.h"
void Initiate_State_Machine() /*Here we define the Initiate State Machine*/
{
current_state= GEAR_DOWN;
printf("\n State Machine is Initialized and the program is in Gear_Down State & Light_Status:%s\n",State_Machine[current_state].light_status);
}
/*
* Gear_Up.c
*
* Created on: 02-Aug-2023
* Author: Sachin Kushare
*/
#include "state.h"
#include<stdio.h>
/*Gear Up*/
void GearUp(void) /*Here we define the Gear Up*/
{
current_state= GEAR_UP;
printf("\n Enter the status of pilot's lever :");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever==Falling)
{
current_state= CHECK_BEFORE_LANDING;
printf("Current 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
{
GearUp();
}
}
/*
* Gear_Down.c
*
* Created on: 02-Aug-2023
* Author: Sachin Kushare
*/
#include "state.h"
#include<stdio.h>
/*Gear Down*/
void GearDown(void) /*Here we define the Gear Down*/
{
current_state= GEAR_DOWN;
printf("\n 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)
{
current_state= CHECKING_BEFORE_TAKEOFF;
printf("\n Current state : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n",State_Machine[current_state].light_status);
}
else
{
GearDown();
}
}
/*
* Checking_Before_TakeOFF.c
*
* Created on: 02-Aug-2023
* Author: Sachin Kushare
*/
#include "state.h"
#include<stdio.h>
/*Checking Before TakeOff*/
void CheckingBeforeTakeOff(void) /*Here we define the Checking Before TakeOff*/
{
current_state= CHECKING_BEFORE_TAKEOFF;
printf("\n 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);
printf("\n Wait for 2secs \n");
if(pilot_lever==Falling || squat_switch==Close)
{
GearDown();
}
else if (pilot_lever==Up && squat_switch==Open && hydraulic_mechanism==working)
{
current_state= RAISING_GEAR;
printf("Current state : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n",State_Machine[current_state].light_status);
printf("Status of Direction valve : %s\n",State_Machine[current_state].direction_valve_status);
}
else if (pilot_lever==Up && squat_switch==Open && hydraulic_mechanism==Malfunctioaning)
{
current_state= RAISING_GEAR;
printf("Current state : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n",State_Machine[current_state].light_status);
printf("Status of Direction valve : %s\n",State_Machine[current_state].direction_valve_status);
printf("Status of Gas Pressurized Spring System :%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
}
/*
* Checking_Before_Landing.c
*
* Created on: 02-Aug-2023
* Author: Sachin Kushare
*/
#include<stdio.h>
#include "state.h"
/*Check Before Landing*/
void CheckBeforeLanding(void) /*Here we define the Check Before Landing*/
{
current_state= CHECK_BEFORE_LANDING;
printf("\n 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==working)
{
current_state= LOWERING_GEAR;
printf("Current state : %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n",State_Machine[current_state].light_status);
printf("Status of Direction valve : %s/n",State_Machine[current_state].direction_valve_status);
}
else if(pilot_lever==Down && hydraulic_mechanism==Malfunctioaning)
{
current_state= LOWERING_GEAR;
printf("Current state : %s\n",State_Machine[current_state].current_state_indication);
printf("Light is: %s\n",State_Machine[current_state].light_status);
printf("Status of Direction valve : %s/n",State_Machine[current_state].direction_valve_status);
printf("Status of Gas Pressurized Spring System :%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
if(pilot_lever==(Up || Raising || Falling))
{
CheckBeforeLanding();
}
}
Output-
State Machine is Initialized and the program is in Gear_Down State & Light_Status:Green
Enter the status of pilot's lever and squat switch :0 0
Current state : CheckingBeforeTakeOff
Light Status: Green
Enter the status of pilot's lever and squat switch and Hydraulic Mechanism:2 0 0
Wait for 2secs
Current state : RaisingGear
Light Status: Red
Status of Direction valve : Up
Enter the status of pilot's lever and limit switch :2 1
Wait for 1secs
Enter the status of pilot's lever and limit switch :1 2
Wait for 1secs
Current state : GearUp
Light Status: Off
Hydraulic Control for Landing Gear Status:(null)
Enter the status of pilot's lever :1
Current state : CheckBeforeLanding
Light Status: Red
Hydraulic Control for Landing Gear Status:(null)
Enter the status of pilot's lever and hydraulic mechanism status :3 0
Current state : LoweringGear
Light Status: Green
Status of Direction valve : Down/n
Enter the status of pilot's lever and limit switch :3 0
Enter the status of pilot's lever and limit switch :0 1
Enter the status of pilot's lever and limit switch :1 0
Current state : CheckingBeforeTakeOff
Light Status: Green
Enter the status of pilot's lever and limit switch :


