Challenge

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

Project (2):- Implementing the code for retraction and extension of the planes landing gear.

Overview:-

The retraction and extension of planes landing gear mainly done by the pilot lever, with the help of electrically

hydraulically operated mechanism. This type of landing gear is used to increase the performance of plane like

airspeed, higher climb capability by reducing the drag forces. Here we made a warning system using c code

that shows the pilot that whether the gear is up or in down condition, the light status, direction of the valve

status and position of the hydraulic control pump. it gives the plane an additional security.

Goals:-

  • To provide the easy landing and takeoff mechanism to the pilot
  • Smooth working of hydraulic systems
  • Effecient control of direction valve
  • Easy understanding of current state of the gear position

Key Highlights:-

  • Light status shows the state of gear, either it is UP or in DOWN condition,and in transit state also.
  • Light status also shows the pilot lever position either it is RAISING or FALLING.
  • Squat switch tells the state of plane either it is grounded or it is airbourne.
  • A direction valve is evolved which allows the hydraulic pressure to either raise or lower the landing gear.

Deliverables:-

  • The code implemented for the retraction and extension of landing gear is done using FSM algorithm.
  • Every Gear has one light that tells the position of Gear.
  • Every leg of the Gear has one limit switch which tells that gear is UP or DOWN.
  • Here finite state machine algorithm gives the knowledge of various states of switch and gears.

Outcomes:-

Here we learn that how Finite State Machine algorithm works for the Retraction and extension of the planes

landing gear, like if landing gear is in down or up position than how the hydraulic pump exerts the hydraulic

pressure on the landing gear and what's the pilot lever status. here we also learns that how a plane landing

gear works. and what are the benefits of Finite State Machine algorithm.

Code Implementation:-

/*
 ============================================================================
 Name        : main1.c
 Author      : Ramlochan
 Version     :
 Copyright   : Your copyright notice
 Description : Project for Airplane landing Gear Mechanism
 ============================================================================
 */
#include "States.h"		// User defined header file is included
						// Various return type fun is initialized and assigned to static variable to fetch the assigned data from anywhere
static void (*state_table[])(void)={Gear_Down, Pre_Takeoff,Raising_Gear, Gear_Up, Pre_Landing,Lowering_Gear};
int main()				// Main function is assigned
{
	Fnite_State_Machine();// Finite_State_Machine return type function is called
	while(1)			  // while loop is used for iteration purpose to call the fun various times that is assigned
	{
		state_table[current_state]();
	}
}
/*
 * states.h
 *
 *  Created on: 28-Apr-2022
 *      Author: Ramlochan
 */
#ifndef STATES_H_								// Defining the header file States.h
#define STATES_H_
#include<stdio.h>								// including header file for standard input output

void Fnite_State_Machine();						// Various return type function is being created like Finite_state_machine
void Gear_Down();								// Gear_Down return type fun is declared
void Pre_Takeoff();								// Pre_Takeoff is declared
void Raising_Gear();							// Raising Gear type function is declared
void Gear_Up();									// Gear up is declared
void Pre_Landing();								// Pre_Landing return type function is declared
void Lowering_Gear();							// Lowering Gear return type function is declared

typedef enum State								// Enumerated data type State is defined which consists of various integer data type which shows itself a position
{
	GR_DWN,										// GR_DWN is declared
	PRE_TAKEOFF,								// Pre_takeoff is declared
	RAISING_GR,									// RAISING_GR is declared
	GR_UP,										// GR_UP data type is declared
	PRE_LANDING,								// Pre_landing data type is declared
	LOWERING_GR									// Lowering_gear data type is declared
}State_Type;									// here State type enumerated data type is declared
typedef enum Switch								// Again Enumerated data type Switch is defined which has two condition Open and Close
{
	Open,
	Close
}Switch_Status;									// Switch status enumerated data type is declared
typedef enum Pilot_Lever						// Enumerated data type Pilot_lever is defined which has four condition like Raising,Falling,Up,and Down
{
	Raising,
	Falling,
	UP,
	DOWN
}Pilot_Lever_Status;							// Pilot_lever_status data type is created
typedef enum Hydraulic_Mechanism				// Enumerated data type hydraulic machine is created which have two condition working and malfunctioning
{
	Working,
	Malfunctioning
}Hydraulic_Mechanism_Status;					// Hydraulic Mechanism status data type is declared
static volatile Switch_Status squat_switch;		// Static and Volatile both the type of variable is declared here we used static to fetch it from all instances
static volatile Switch_Status limit_switch;		// we made it volatile to use for read and write to various times from main memory
static volatile Pilot_Lever_Status pilot_lever;
static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;
State_Type current_state;
typedef struct									// here we define various data type variable using typedef struct command
{
	char* current_state_indication;				// character type variable current state indication is declared
	char* light_status;
	char* direction_Valve_status;
	char* hydraulic_pump_control_status;
	char* gas_pressurized_spring_status[2];
}State_Table;									// state table is declared

static State_Table State_Machine[6]=			// Here we again assign variables of static type for fetching from all instances for various purpose
{
		{"GearDown","Green","Down","Enabled",0,0},
		{"Pre Takeoff","Green","Down","Enabled",0,0},
		{"Raising_Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
		{"Gear Up","off","Null","Disabled",0,0},
		{"Pre Landing","Red","Down","Enabled",0,0},
		{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
#endif     // STATE_H_ is terminated

/*
 * Finite_State_Machine.c
 *
 *  Created on: 28-Apr-2022
 *      Author: Ramlochan
 */

#include "States.h"                                       // user defined header file is included

void Fnite_State_Machine()			                      // return type function Finite_State_Machine is created
{
	current_state = GR_DWN;								  // it shows that current state is in GEAR DOWN condition
	printf("\nState Machine is initialized & Program is in Gear Down State & Light Status :%s\n",State_Machine[current_state].light_status);
}	//printing the given message that State machine is initialized and tells the light status.


/*
 * Gear_Down.c
 *
 *  Created on: 28-Apr-2022
 *      Author: Ramlochan
 */
#include"States.h"									// included the user defined header file States.h
#include<stdio.h>									// included the header file stdio.h for standard input and output

void Gear_Down(void)								// Return type fun Gear_Down is called for execution
{
	current_state = GR_DWN;							// showing the current position that is Gear Down
	printf("\nEnter the Pilot lever Position and Squat Switch Status :"); // Printing message to enter pilot lever position and squat switch position
	fflush(stdout);									// clearing the cache memory
	scanf("%d %d",&pilot_lever,&squat_switch);		// Reading the input provided by the user and assigning it to respective variable
	if(pilot_lever == Raising && squat_switch == Open)// if statement is used to compare the given condition
	{
		current_state = PRE_TAKEOFF;				// assigning the current state if 'if' condition is true
		printf("\n Current State : %s\n",State_Machine[current_state].current_state_indication);// printing the current state indication
		printf("\nLight Status :%s\n",State_Machine[current_state].light_status);// printing the light status of plane
	}
	else											// else is used to check the false condition of 'If'
	{
		Gear_Down();								// return to Gear Down fun
	}
}

/*
 * Pre_Takeoff.c
 *
 *  Created on: 28-Apr-2022
 *      Author: Ramlochan
 */

#include"States.h"												// included the user defined header file States.h
#include<stdio.h>												// included the header file for standard input and output

void Pre_Takeoff()												// Return type fun Pre_Takeoff is called
{
	current_state = PRE_TAKEOFF;								// check the current status that is Pre_takeoff
	printf("\nEnter the Pilot's lever Position, Squat Switch Status and Hydraulic Mechanism Status :");// Printing the given message asking for user input
	fflush(stdout);												// clearing cache memory
	scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism); // Scanning the user input given for pilot lever,squat switch & hydraulic mechanism
	printf("\n Wait for two seconds\n");						// print the message that wait for two second
	if (pilot_lever == Falling || squat_switch == Close)		// if statement is used to check the given condition if its true than return to given condition
	{
		Gear_Down();											// return to Gear Down fun
	}
	else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)// else if check the other provided condition if its true than it get executed
	{
		current_state = RAISING_GR;								// check current state
		printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);// printing current state indication
		printf("Light Status :%s\n",State_Machine[current_state].light_status);// printing the light status of Plane
		printf("Direction Valve Status :%s\n\n",State_Machine[current_state].direction_Valve_status);// printing the direction valve status of plane
	}
	else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Malfunctioning) // again else if is used to check another condition
	{
		printf("Light Status :%s\n",State_Machine[current_state].light_status);// if else if condition is true than printing the light status
		printf("Direction Valve Status :%s\n",State_Machine[current_state].direction_Valve_status);// printing the Direction valve status
		printf("Gas pressurized Spring System Status :%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
	}															// printing the Gas pressurized spring system status
}

/*
 * Raising_Gear.c
 *
 *  Created on: 28-Apr-2022
 *      Author: Ramlochan
 */

#include"States.h"													// included the user defined Header file states.h

void Raising_Gear()													// Return type function Raising Gear is called
{
	current_state = RAISING_GR;										// showing the current state position that is Raising Gear
	printf("\nEnter the Limit Switch Status, Pilots lever Status :");// printing input for limit switch status and pilot lever status
	fflush(stdout);													// clearing the cache memory
	scanf("%d %d",&limit_switch,&pilot_lever);						// scanning the input given by the user
	printf("\nWait for a second\n");								// printing message to wait for a second
	if(pilot_lever == Falling && limit_switch == Open)				// if statement is used to check the given condition
	{
		current_state = PRE_LANDING;								// if statement is true than current state goes to pre_landing position
		printf("\ncurrent_state : %s\n",State_Machine[current_state].current_state_indication);	// printing the current state indication
		printf("Light Status :%s\n",State_Machine[current_state].light_status);// Printing Light status
		printf("Hydraulic Control for Landing Gear Status :%s\n",State_Machine[current_state].hydraulic_pump_control_status);// Printing hydraulic pump control status
	}
	else if(limit_switch == Close && pilot_lever == UP)				// else if used to check another condition
	{
		current_state = GR_UP;										// it shows current state that Gear UP
		printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);	// print the current state indication
		printf("Light Status :%s\n",State_Machine[current_state].light_status);// print light status
		printf("Hydraulic Control for Landing Gear Status :%s\n",State_Machine[current_state].hydraulic_pump_control_status);//printing hydraulic pump control status
	}
	else															// checking  the false condition of if and else if
	{
		Raising_Gear;												// return to Raising Gear
	}
}


/*
 * Gear_Up.c
 *
 *  Created on: 28-Apr-2022
 *      Author: Ramlochan
 */
#include"States.h"												// included user defined header file states.h

void Gear_Up()													// return type fun Gear_Up is initialized
{
	current_state = GR_UP;										// fetch the current state that is Gear Up
	printf("\nEnter the Pilot's Lever Position :");				// Asking pilot lever position from user
	fflush(stdout);												// clearing cache memory
	scanf("%d",&pilot_lever);									// scanning the pilot lever status given by the user
	if(pilot_lever == Falling)									// if condition is used to compare the given statement if its true then update the current state
	{
		current_state = PRE_LANDING;							// updating the current state
		printf("\nCurrent_State : %s\n",State_Machine[current_state].current_state_indication);// print current state indication
		printf("Light Status :%s\n",State_Machine[current_state].light_status);// printing light status
		printf("Hydraulic Control for Landing Gear Status :%s\n",State_Machine[current_state].hydraulic_pump_control_status);// print hydraulic pump current status
	}
	else														// used to print the false condition of if statement
	{
		Gear_Up;												// reach to again Gear Up condition
	}
}


/*
 * Pre_Landing.c
 *
 *  Created on: 28-Apr-2022
 *      Author: Ramlochan
 */
#include"States.h"															// included the user defined header file states.h

void Pre_Landing()															// return type function Pre_Landing is called
{
	current_state = PRE_LANDING;											// shows that current state is Pre_Landing
	printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism :");// Printing the message to enter the input for pilot lever and status of hydraulic
	fflush(stdout);															// cleaning the cache memory
	scanf("%d %d",&pilot_lever,&hydraulic_mechanism);						// reading the input given by the user
	if(pilot_lever == DOWN && hydraulic_mechanism == Working)				// if keyword is used to compare the given condition to the user input and if its true, than
	{
		current_state = LOWERING_GR;										// current state updated that is Lowering Gear
		printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);// printing the current state indication
		printf("\Light Status:%s\n",State_Machine[current_state].light_status);// printing the light status of the plane
		printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_Valve_status);// printing the direction valve status
	}
	else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)	// else if is used to check the other condition of the given input and printing the state
	{
		current_state = LOWERING_GR;										// it update the current state that is Lowering Gear
		printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);// print the current state indication value
		printf("Light Status:%s\n",State_Machine[current_state].light_status);// printing the light status of the of the plane
		printf("Direction Valve Status: %s\n",State_Machine[current_state].direction_Valve_status);// printing the direction valve status
		printf("Gas Pressurized Spring System Status :%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
	}		    															// printing the gas pressurized spring status
	else (pilot_lever == (UP || Raising || Falling));						// else return to false condition of 'if'
	{
		Pre_Landing();														// return to Pre_Landing condition
	}
}
/*
 * Lowering_Gear.c
 *
 *  Created on: 28-Apr-2022
 *      Author: Ramlochan
 */

#include"States.h"											// included Header file States.h which is user defined

void Lowering_Gear()										// Return type function Lowering Gear is being called
{
	current_state == LOWERING_GR;							// Showing the current state that is lowering Gear
	printf("\nEnter the Limit Switch status and Pilot lever Status:");// Printing the message to enter the limit switch status and pilot lever position
	fflush(stdout);											// clearing cache memory
	scanf("%d %d",&limit_switch,&pilot_lever);				// Reading the input provided by the user for limit switch and pilot lever
	if(limit_switch == Close && pilot_lever == Raising)		// if keyword is used to compare the given input by the user
	{
		current_state = PRE_TAKEOFF;						// if condition is true than current state updated as Pre_Takeoff
		printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);// printing the current state indication
		printf("Light Status: %s\n",State_Machine[current_state].light_status);// printing the light status of the plane
	}
	if(limit_switch == Open && pilot_lever == DOWN)			// again if keyword is used to compare the another condition,if its true then print the given condition
	{
		current_state = GR_DWN;								// current state is updated as Gear down
		printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);// Again printing the current state indication
		printf("Light status :%s\n",State_Machine[current_state].light_status);// Printing the light status of the plane
		printf("Hydraulic Control for Landing Gear Status :%s\n",State_Machine[current_state].hydraulic_pump_control_status);//printing hydraulic pump control status
	}
	else													// else condition is used to check the false condition of 'if'
	{
		Lowering_Gear();									// return to Lowering Gear
	}
}

Output:-

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.