Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear

theory page 2

theory page 3

thory page 4

FINAL STATE DIAGRAM AND STATE TABLE


CODE SCREEN SHOT 1

CODE SCREEN SHOT 2

CODE SCREEN SHOT 3

CODE SCREEN SHOT 4

CODE SCREEN SHOT 5

CODE SCREEEN SHOT 6

CODE SCREEN SHOT 7

CODE OUTPUT SCREENSHOT

/*
* project2.c
*
* Created on: 12-Oct-2023
* Author: CHIRAG
*
* PROJECT 2 Implement the Code for controlling the retraction and extension of Airplane’s
*
*
# 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.
*/
#include
static int x,y,z,l;
//================================================= Function declaration=========================================//
void Initiate_State_Machine(); // function declaration to Initiate_State_Machine
void GearDown(); // function declaration GearDown();
void CheckingBeforeTakeOFF(); // function declaration CheckingBeforeTakeOFF();
void RaisingGear(); // function declaration RaisingGear();
void GearUp(); // function declaration GearUp();
void CheckBeforeLanding(); // function declaration CheckBeforeLanding();
void LoweringGear(); // function declaration LoweringGear();
static void(*statetable[])(void)={GearDown, //declaring function arrays pointer
CheckingBeforeTakeOFF, //to point different fnctions
RaisingGear,
GearUp,
CheckBeforeLanding,
LoweringGear};
//================================================== Declaring Enum datatype for state===========================//
typedef enum State // Creating User defined Data type enum which has alias name state type
{
GEAR_DOWN, // GEAR_DOWN,State
CHECKING_BEFORE_TAKEOFF, // CHECKING_BEFORE_TAKEOFF,State
RAISING_GEAR, // RAISING_GEAR,State
GEAR_UP, // GEAR_UP,State
CHECK_BEFORE_LANDING, // CHECK_BEFORE_LANDING,sate
LOWERING_GEAR, // LOWERING_GEAR
}State_Type; // Creating currentstate variable of type State_Type
//======================= Declaring Enum datatype for LIMIt and squat switch ============================= //
typedef enum Switch // Creating User defined Data type enum which has alias name Switch_status
{
on, // limit switch is close plane is flying
off // squat switch is ON plane is parked gear is locked
}Switch_status;
//======================= Declaring Enum datatype for PILOT LEVER======================================== //
typedef enum pilot_lever // Creating User defined data type enum which has alias name pilot_lever
{
Raising,
falling
}pilot_lever;
//========================= Declaring Enum datatype for hydraulic_mechanism================================ //
typedef enum hydraulic_mechanism // creating user defines data type enum which has alias name hydraulic machine
{
working,
not_working
}hydraulic_mechanism;
//============================ Declaring variables for Enum==================================================//
static volatile Switch_status squat_switch; //declaring variable for type Switch_status
static volatile Switch_status limit_switch; //declaring variable for type Switch status
static volatile pilot_lever pl; //declaring variable for pilot lever
static volatile hydraulic_mechanism hm; //declaring variable for hydraulic_mechanism
State_Type current_state; // variable name current state of type state_type
//=====================================USER define STRUCT which has string members============================//
typedef struct
{
char* current_state_indication;
char* light;
char* direction_valve_status;
char* landing_gear_hydraulic_control;
char* Gas_Pressurized_Spring_system_status[2];
}State_Table;
//=================================for displaying status for differen state=====================================//
static State_Table State_Machine[6]={{"GearDown","Green","Down","Enabled",{NULL,NULL}}, //arrays of state machine of type state table
{"CheckingBeforeTakeOFF","Green","Down","Enabled",{NULL,NULL}},
{"RaisingGear","Red","Up","Enabled",{"Disable","Enabled"}},
{"GearUp","Off","NULL","Disabled",{NULL,NULL}},
{"CheckBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
//================================= Main Function ====================================================== //
int main()
{
Initiate_State_Machine(); // Initializing FSM calling function
while(1)
{
statetable[current_state](); //infinite loop for current state
}
}
//================================= GEARDOWN Function ===================================================//
void GearDown(void) // no return no argument
{
current_state=GEAR_DOWN;
printf("you are in GEAR DOWN NOW \n");
printf("Enter the status of pilot's lever and squat switch ");
fflush(stdout); // for clearing buffer in console
scanf("%d %d",&x,&y); //to assign value to Pl and squat switch
pl=x;
squat_switch=y;
if(pl==Raising && squat_switch==on) //testing condition
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("current state:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is :%s\n", State_Machine[current_state].light);
printf("The direction valve is:%s\n", State_Machine[current_state].direction_valve_status);
printf("=============================================================\n\n");
}
else
{
GearDown();
}
}
//================================= CheckingBeforeTakeOFF(void) Function ===============================//
void CheckingBeforeTakeOFF(void)
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("you are in CHEKING BEFORE TAKE OFF\n");
printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism: ");
fflush(stdout);
scanf("%d %d %d",&x,&y,&z);
pl=x;
squat_switch=y;
hm=z;
if(pl==falling && squat_switch==on && hm==working)
{
printf("Once again in GearDown\n\n");
GearDown();
}
else if(pl==Raising && squat_switch==on && hm==working)
{
current_state=RAISING_GEAR;
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
printf("Status of gas pressurised Spring System:%s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status[0]);
//since Hydraulic mechanism is working gas pressure system is disable
printf("===============================================================================\n");
}
else if(pl==Raising && squat_switch==on && hm==not_working)
{
printf("the RAISING_GEAR in ON\n");
current_state=RAISING_GEAR;
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
printf("Status of landing gear hydraulic control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
printf("Status of gas pressurised Spring System:%s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status[1]);
//since Hydraulic mechanism is working gas pressure system is disable
printf("===============================================================================\n");
}
}
//================================================RaisingGear(void) Function ===================================//
void RaisingGear(void)
{
current_state=RAISING_GEAR;
printf("you are in RAISING GEAR\n");
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&x,&l);
pl=x;
limit_switch=l;
if(pl==falling && limit_switch==on)
{
current_state=CHECK_BEFORE_LANDING;
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
printf("===============================================================================\n");
}
else if(pl==Raising && limit_switch==on)
{
current_state=GEAR_UP;
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
printf("===============================================================================\n");
}
else
{
RaisingGear();
}
}
//==================================================GearUp(void) function========================================= //
void GearUp(void)
{
current_state=GEAR_UP;
printf("you are in GEARUP\n");
printf("Enter the status of pilot's lever:");
fflush(stdout);
scanf("%d",&x);
pl=x;
if(pl==falling)
{
current_state=CHECK_BEFORE_LANDING;
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
printf("===============================================================================\n");
}
else
{
GearUp();
}
}
//==================================================CheckBeforeLanding(void) function==================================== //
void CheckBeforeLanding(void)
{
current_state=CHECK_BEFORE_LANDING;
printf("you are in CHECK BEFORE LANDIND\n");
printf("Enter the status of pilot's lever and hydraulic mechanism status:");
fflush(stdout);
scanf("%d %d",&x,&z);
pl=x;
hm=z;
if(pl==falling && hm==working)
{
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);
printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
printf("===============================================================================\n");
}
else if(pl==falling && hm==not_working)
{
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);
printf("Status of Direction valve:%s\n",State_Machine[current_state].direction_valve_status);
printf("Status of gas pressurised Spring System:%s\n",State_Machine[current_state].Gas_Pressurized_Spring_system_status[1]);
printf("===============================================================================\n");
}
else if(pl==(Raising))
{
CheckBeforeLanding();
}
}
//====================================================LoweringGear(void) Function============================================//
void LoweringGear(void)
{
current_state=LOWERING_GEAR;
printf("you are in LOWERING GEAR\n");
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&x,&l);
pl=x;
limit_switch=l;
if(pl==Raising && limit_switch==off)
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("===============================================================================\n");
}
else if(pl==falling && limit_switch==off)
{
current_state=GEAR_DOWN;
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
printf("===============================================================================\n");
}
if(limit_switch==on)
{
LoweringGear();
}
}
//======================================================Initiate_State_Machine(void) function===================================//
void Initiate_State_Machine()
{
printf(" The Finite State Machine is InItialized and \n current the program is in 'GearDown' State & Light is: %s \n",State_Machine[current_state].light);
printf("=============================================================\n\n");
GearDown();
}
//======================================================================END PROGRAMM============================================================================//