Challenge

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

AIM :- Write a C for program controlling the retraction and extension of Airplane landing gear and this can be implement using finite state machine concept.

Theory :-

Actually an airplane has 3 gears for landing :

  • Nose Gear
  • Left Gear
  • Right Gear

There is a hydraulic pump which is exerting pressure to the ears to bring it down or pull it up and that pump is electrically driven.

Limit switches:

Every leg of the gear has one limit switch .Nose gear has one extra Squat Switch to determine whether the airplane is in ground or not.

State Diagram :-

C CODE :-

#include  // Pre Processor Directives

typedef enum State // Defining enum for various state of aircraft
{
	GR_DWN,
	CHK_BFR_TKFF,
	RSING_GR,
	GR_UP,
	CHK_BFR_LND,
	LWRNG_GR,

}State_Type;

typedef enum Switch  // Defining enum for squat switch status of aircraft
{
	open,
	close

}Switch_Status;

typedef enum Pilot_Lever // Defining enum for pilot lever position
{
	Rising,
	Falling,
	Up,
	Down

}Pilot_Lever_Status;

typedef enum Hydraulic_Mechanism
{
	//Working = UP,
	//Malfunctioning = DOWN
	Malfunctioning,
	Working
}Hydraulic_Mechanism_Status;

// Creating variables of enums
static volatile Switch_Status squat_switch;
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 // defining structure that contains pointer of char data type
{
	char *current_state_indication;
	char *light_status;
	char *direction_valve_status;
	char *hydraulic_pump_control_status;
	char *gas_pressurized_spring_status[2];

}State_Table;

// creating array of structures for state table
static State_Table State_Machine[6]={
		{"Gear Down","Green","Down","Enabled",{NULL,NULL}},
		{"Checking Before Take Off","Green","Down","Enabled",{NULL,NULL}},
		{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
		{"Gear Up","Off","Null","Disabled",{NULL,NULL}},
		{"Checking Before Landing","Red","Down","Enabled",{NULL,NULL}},
		{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};

// creating functions for the state of aircraft
void Gear_Down(void)
{
	printf("\n In Gear Down State");
	current_state = GR_DWN;
	printf("\n Enter the pilot lever position and Squat Switch Status :- ");
	fflush(stdout);
	scanf("%d %d",&pilot_lever,&squat_switch);
	if((pilot_lever == Rising) && (squat_switch == open))
	{
		current_state = CHK_BFR_TKFF;
		printf("\n current state: %s \n", State_Machine[current_state].current_state_indication);
		printf("\n Light Status:%s \n",State_Machine[current_state].light_status);
	}
	else
	{
		Gear_Down();
	}
}

void Checking_Before_Takeoff()
{
	current_state = CHK_BFR_TKFF;
	printf("\n Enter the pilots Lever Position and Squat Switch Status and Hydraulic Mechanism Status: ");
	fflush(stdout);
	scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
	printf("\n Wait for 3 seconds \n");
	if(pilot_lever == Falling || squat_switch == close)
	{
		Gear_Down();
	}
	else if (pilot_lever == Up && squat_switch == open && hydraulic_mechanism == Working)
	{
		current_state = RSING_GR;
		printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
		printf("\n Light Status:%s \n",State_Machine[current_state].light_status);
		printf("Direction Valve Status:%s \n", State_Machine[current_state].direction_valve_status);
	}
	else if(pilot_lever == Up && squat_switch == open && hydraulic_mechanism == Malfunctioning)
	{
		current_state = RSING_GR;
		printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
		printf("\n Light Status:%s \n",State_Machine[current_state].light_status);
		printf("Direction Valve Status:%s \n", State_Machine[current_state].direction_valve_status);
		printf("Gas Pressurized Spring System Status:%s \n", State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
	}
}

void Raising_Gear()
{
	current_state = RSING_GR;
	printf("\n Enter the limit switch status and pilot_lever Status: ");
	fflush(stdout);
	scanf("%d %d", &limit_switch, &pilot_lever);
	printf("\n Wait for 1 seconds \n");
	if(pilot_lever == Falling && limit_switch == open)
	{
		current_state = CHK_BFR_LND;
		printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
		printf("\n 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)
	{
		current_state = GR_UP;
		printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
		printf("\n 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();
	}
}

void Gear_up()
{
	current_state = GR_UP;
	printf("\n Enter the pilots Lever Position: ");
	fflush(stdout);
	scanf("%d",&pilot_lever);
	if(pilot_lever == Falling)
	{
		current_state = CHK_BFR_LND;
		printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
		printf("\n 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
	{
		Gear_up();
	}
}

void Checking_Before_Landing()
{
	current_state = CHK_BFR_LND;
	printf("\n Enter the pilots Lever Position and Hydraulic Mechanism Status: ");
	fflush(stdout);
	scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
	if(pilot_lever == Down && hydraulic_mechanism == Working)
	{
		current_state = LWRNG_GR;
		printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
		printf("\n Light Status:%s \n",State_Machine[current_state].light_status);
		printf("Direction Valve Status:%s \n", State_Machine[current_state].direction_valve_status);
	}
	else if(pilot_lever == Down && hydraulic_mechanism == Malfunctioning)
	{
		current_state = LWRNG_GR;
		printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
		printf("\n Light Status:%s \n",State_Machine[current_state].light_status);
		printf("Direction Valve Status:%s \n", State_Machine[current_state].direction_valve_status);
		printf("Gas Pressurized Spring System Status:%s \n", State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
	}
	if(pilot_lever == (Up || Rising || Falling))
	{
		Checking_Before_Landing();
	}
}

void Lowering_Gear()
{
	current_state = LWRNG_GR;
	printf("\n Enter the pilots Lever Position and Limit Switch Status: ");
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &limit_switch);
	if(pilot_lever == Rising)
	{
		current_state = CHK_BFR_TKFF;
		printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
		printf("\n Light Status:%s \n",State_Machine[current_state].light_status);
	}
	if (pilot_lever == Down && limit_switch == open)
	{
		current_state = GR_DWN;
		printf("\n current_state: %s \n", State_Machine[current_state].current_state_indication);
		printf("\n 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);
	}
	if(limit_switch == close)
	{
		Lowering_Gear();
	}
}

// creating function for initial state of the aircraft
void Init_State_Machine()
{
	current_state = GR_DWN; // by default we are initially considering gear down state
	printf("State Machine is Initialized and Program is in Gear Down state & Light Status is: Green\n");
}

int main()
{
	Init_State_Machine(); // calling initial state function
	while(1)
	{
		switch(current_state) // creating switch case to enter in a particular state
		{
		case 0: Gear_Down();
		break;
		case 1:Checking_Before_Takeoff();
		break;
		case 2:Raising_Gear();
		break;
		case 3: Gear_up ();
		break;
		case 4:Checking_Before_Landing();
		break;
		case 5: Lowering_Gear();
		break;
		default:break;
		}
	}
}

OUTPUT :-

  • Outputs using highlighters and underlines

CONCLUSION :- We had created a C program using finite state machine(FSM) concept that works successfully for  program controlling the retraction and extension of Airplane 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.