Challenge

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

AIM:Implement the Code for controlling the retraction and extension of Airplane’s landing gear.

OVERVIEW OF THE PROJECT:

*In this project we are going to find an retraction and extension of aeroplane,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.

*The program to find the retraction and extension of Airplane’s landing gear for an different states are doing in an source file inside an main file

*The following are the different states of an airplan gear extension

a)Initializing state machine of all condition

b)Gear down

c)checking before take off

d)raising gear

e)gear up condition

f)Check before landing

g)Lowering gear

*In an main.c file we are going to create an syntax of an function definition of an 10 and 17th line

*All this functions are defined inside the header file along with initialize state machine are declared in type def enum function.

Goals:

*The main goal is to write an code using the concept of finite state machine by using an typedef and also an enum

*Controlling the retraction and extension of Airplane’s landing gear and seeing in an different modes of an operation

*Controlling the direction of Valve of Airplane’s landing gear.

Highlights and deliverables of the project:

*By seeing an above state flow diagram all the conditions for an function are defined inside the header file.

*Along with the initialize state machine the functions are declined by an typedef enum ffunctions.

*Type def is used because the typedef can be changedv for an existing variable

*where,as enum is used because in the case of enum for each and every variable the number will get automatically allocated.

*A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear

*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.

*The retraction and also an extension of an aireplane landing gear is illustrated from this project.

MAIN.C FILE:

#include //preprocessor directives
#include "states.h"//preprocessor directives

static void (*state_table[])(void) = {Gear_Down,Checking_Before_Takeoff,Raising_Gear,//calling an different finite state condition inside the void function
		                                Gear_Up,Checking_Before_Landing,Lowering_Gear};
int main()//main function
{
    Init_State_Machine();//initializing the state of an machine
    while(1)//calling an while loop to execute an different condition
    {
    	state_table[current_state]();//initializing an array of an current state inside that of an state table
    }
}

header.h FILE:

#ifndef STATES_H_//PREPROCESSOR DIRECTIVES
#define STATES_H_//PREPROCESSOR DIRECTIVES

void Init_State_machine();//CHECKING FOR AN STATE FOR AN INITIAL STATE OF THE MACHINE
void Gear_Down();//Calling void for an gear down condition
void Checking_Before_Takeoff();//Calling void for an before takeoff condition
void Raising_Gear();//Calling void for an raising gear condition
void Gear_Up();//calling void for an gear up condition
void Checking_Before_Landing();//calling void for an checking before landing
void Lowering_Gear();//calling void for an lowering gear

typedef enum State//calling an typedef and an enum for different states
{

	GR_DWN,//gear down
	CHK_BFR_TKFF,//checking before takeoff
	RSING_GR,//raising gear
	GR_UP,//gear up
	CHK_BFR_LND,//checking before land
	LWRNG_GR//lowering gear
}State_Type;//end of the typedef function

typedef enum Switch//calling an typedef enum for an switch case
{
	Open,//during an open state
	Close//during an close state
}Switch_Status;//end of typedef enum function

typedef enum Pilot_Lever//calling an typedef enum for an pilot lever state
{
	Rising,//during rising state
	Falling,//during falling state
	UP,//during up condition
	DOWN//during down condition
}Pilot_Lever_Status;//end of typedef enum function

typedef enum Hydraulic_Mechanism//calling an typedef enum for an Hydraulic_Mechanism state
{
	Working,//during working state
	Malfunctioning////during Malfunctioning state
}Hydraulic_Mechanism_Status;//end of typedef enum function

static volatile Switch_Status squat_switch;//static volatile switch state condition for an squat switch
static volatile Switch_Status limit_switch;//static volatile switch state condition for an limit_switch
static volatile Pilot_Lever_Status pilot_lever;//static volatile switch state condition for an pilot_lever
static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;//static volatile switch state condition for an Hydraulic_Mechanism_Status

State_Type current_state;//end of state type loop

typedef struct//calling an structure inside an typedef
{
	char* current_state_indication;//calling pointer char for current state indication
	char* light_Status;//calling pointer char for light_Status
	char* direction_value_status;//calling pointer char for direction_value_status
	char* hydraulic_pump_control_status;//calling pointer char for hydraulic_pump_control_status
	char* gas_pressurized_spring_status[2];//calling pointer char for gas_pressurized_spring_status
}State_Table;

static State_Table State_Machine[6] = {//an different sate of an state machine is called in an arary of an state table witha an static data type
		{"GearDown","Green","Down","Enabled",0,0},
		{"Checking Before Take Off ","Green","Down","Enabled",0,0},
		{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
		{"Gear Up","Off","Null","Disabled",0,0},
		{"Checking Before Landing","Red","Down","Enabled",0,0},
		{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
# endif /* STATES_H_ *///end of an headerfile.

checking before landing .s FILE:

#include "States.h"//preprocessor directives
#include<stdio.h>//preprocessor directives
void Checking_Before_Landing()//calling an check before landing condition
{
	current_state = CHK_BFR_LND;//checking  for current state in check before land
		printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);//console input output statements
		printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:");
		fflush(stdout);
		scanf("%d %d",&pilot_lever,&hydraulic_mechanism);//console input output statements
		if(pilot_lever == DOWN && hydraulic_mechanism == Working)//execution of if loop
		{
			current_state = LWRNG_GR;
			printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
			printf("Light Status:%s\n",State_Machine[current_state].light_Status);
			printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_value_status);
		}
		else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)//execution of if else loop for pilot lever and also to an hydraulic mechanism
		{
			current_state = LWRNG_GR;//lowering gear sent to an current state of the gear
			printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
			printf("Light Status:%s\n",State_Machine[current_state].light_Status);
			printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_value_status);
			printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
		}//console input statements

		 if(pilot_lever == (UP || Rising || Falling))//ending an if loop statements
		{
				Checking_Before_Landing();
		}

}

checking before takeoff .s FILE:

#include "States.h"//preprocessor directives
#include<stdio.h>//preprocessor directives

void Checking_Before_Takeoff()//calling an void for Checking_Before_Takeoff state
{
	current_state = CHK_BFR_TKFF;// Checking_Before_Takeoff state to an current state
	printf("\n Enter the Pilot's Lever Position,Squat Switch Status and  Hydraulic Mechanism Status:");//console input output statement
	fflush(stdout);//to clear unwanted memory
	scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);//console input output statement
	printf("\n Wait for 2 secs\n");//console input output statement
	if(pilot_lever == Falling || squat_switch == Close)//execution of if loop
	{
		Gear_Down();
	}
	else if (pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)//execution of an else if in other state condition
	{
		current_state = RSING_GR;
	    printf("\n Current State: %s\n",State_Machine[current_state].current_state_indication);//console input output statement
		printf("Light Status:%s\n",State_Machine[current_state].light_Status);
		printf("Direction Value Status:%s\n\n",State_Machine[current_state].direction_value_status);
	}
	else if (pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Malfunctioning)//execution of an else if in other state condition
	{
		printf("Light Status:%s\n",State_Machine[current_state].light_Status);;//console input output statement
	    printf("Direction Value Status:%s\n",State_Machine[current_state].direction_value_status);
		printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
	}
}

gear down .s FILE:

#include "States.h"//preprocessor directives
#include<stdio.h>//preprocessor directives

void Gear_Down(void)
{
	current_state = GR_DWN;//calling an void for Gear_Down state
	printf("\n Enter the Pilot's Lever Position and Squat Switch Status:");
	fflush(stdout);//to clear unwanted memory
	scanf("%d %d",&pilot_lever,&squat_switch);//console input output statement

	if (pilot_lever == Rising && squat_switch == Open)//calling an if loop condition for raising and open state of an pilot gear
	{
		current_state = CHK_BFR_TKFF;
		printf("\n Current State:%s\n",State_Machine[current_state].current_state_indication);//console input output statement
		printf("Light Status:%s\n",State_Machine[current_state].light_Status);

	}
	else
	{
		Gear_Down();//end of aan if else staement 
	}
}

Initial state .s FILE:

#include"States.h"//preprocessor directives

void Init_State_Machine()//calling an void for initial satte machine
{
	current_state = GR_DWN;//then gear down state is put to an current stste of the machine
	printf("\nState Machine is initialized & Program is in Gear_Down State & Light_Status : %s\n",State_Machine[current_state].light_Status);//console input output statements

}

lowering gear .s FILE:

#include "States.h"//preprocessor directives
#include<stdio.h>//preprocessor directives
void Lowering_Gear()//calling an void for an lowering gear state
{
	current_state = LWRNG_GR;////calling an void for LWRNG_GR state
	printf("\n Enter the Limit_Switch Status,Pilot_Lever Status ::");
	fflush(stdout);//to clear unwanted memory
	scanf("%d %d",&limit_switch,&pilot_lever);//console input output statement
	if( limit_switch == Close && pilot_lever == Rising)//calling an if loop for an close an rising state for limit switch and pilot liver for if statement
	{
		current_state = CHK_BFR_TKFF;
		printf("\n Current State: %s\n",State_Machine[current_state].current_state_indication);//console input output statement
		printf("Light Status:%s\n",State_Machine[current_state].light_Status);//console input output statement
	}
	if(limit_switch == Open && pilot_lever == DOWN)//calling an if else statement
	{
		current_state = GR_DWN;//gear down initialized to an current state
		printf ("\n Current State: %s\n",State_Machine[current_state].current_state_indication);//console input output statement
		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
	{
		Lowering_Gear();//end of else statement for an lowering gear state
	}
}

lowering gear .s FILE:

#include "States.h"//preprocessor directives
#include<stdio.h>//preprocessor directives

void Raising_Gear()
{
	current_state = RSING_GR;// Checking_Before_raising gear to an current state
	printf("\n Enter the Limit Switch Status, Pilot's Lever Position :");
	fflush(stdout);//to clear unwanted memory
	scanf("%d %d",&limit_switch,&pilot_lever);//console input output statement
	printf("\nWait for 1 sec\n");//console input output statement
	if(pilot_lever == Falling && limit_switch == Open)//execution of an if in other state condition of an pilot liver and an limit switch
	{
		current_state = CHK_BFR_LND;
	    printf ("\n Current State: %s\n",State_Machine[current_state].current_state_indication);//console input output statement
		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 (limit_switch == Close && pilot_lever == UP)//execution of an else if in other state condition
		{
		current_state = GR_UP;
		printf ("\n Current State: %s\n",State_Machine[current_state].current_state_indication);//console input output statement
		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
	{
		Raising_Gear();/end of else statement for an Raising_Gear state
	}
}

EXPECTED OUTPUTS:

*First we have to enter the pilot lever position and also an squat position of an machine

*By seeing the above table its easy to give the switch type and also an type staus of an machine.

*Next we have to enter the limit of an swith status and an pilot lever status as 1and2,after an sec we are able to see the status is in an null state

*If we enter the pilot lever ststus as 1 then the light ststus will turn to an green

*Similarly we have to check the conditions for an different modes or an stste of the machine.

*In the below output attached image we can seee clearly about controlling the retraction and extension of Airplane’s landing gear.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.