Challenge

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

Project - 2 :)

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

Some questions are very important to answer before getting into the source code , they are as follows :

  • What is Landing Gear ?

Ans - Landing gear is the undercarriage of an aircraft that is used for takeoff or landing . It is the principal support of the airplane when parked, taxiing, taking off, or landing.

Diagram of Landing Gear in Aircraft :

  • How finite state machine models can help in understanding and coding the controlling of aeroplane's landing gear retraction and expansion ?

Ans - Finite State Machine Models are behavioural models that helps in generating output with the help of some input and also transitioning of a state from one to the other . State Diagrams and State Tables can make the work more easy and hence makes the programmer more confident about the concept related to the respective machine here the aeroplane's landing gear & on the basis of it can code better & makes other understand the backdrop under which things related to machines arre happening .

Goal of the project :

  1. Controlling the direction of Valve.
  2. Controlling the retraction and extension of Airplane’s landing gear

Expected Output :

To apply 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.

Source Code :

#include 

// Functions Declaration
void Start_State_Machine();
void GearDown();
void CheckingBeforeTakeOFF();
void RaisingGear();
void GearUp();
void CheckBeforeLanding();
void LoweringGear();

//Pointer to array function 
// Static -- Makes the function accesible throughout the program 
// Void ---  Holds address of any type and can be typecasted to any type. 
static void(*statetable[])(void) = {GearDown, CheckingBeforeTakeOFF, RaisingGear, GearUp, 
CheckBeforeLanding, LoweringGear};

typedef enum State{
	Gear_Down,
	Checking_Before_Takeoff,
	Raising_Gear,
	Gear_Up,
	Check_Before_Landing,
	Lowering_Gear
}State_Type;

typedef enum Switch{
	on,
	off
}Switch_status;

typedef enum pilot_lever{
	Raising,
	Falling
}pilot_lever;

typedef enum hydraulic_mechanism{
	working,
	not_working
}hydraulic_mechanism;

// User-defined data-types declaration 
// Violatile -- Tells the compiler that these variables can change their value anytime in the prog.
static volatile Switch_status squat_switch;
static volatile Switch_status limit_switch;
static volatile pilot_lever p;
static volatile hydraulic_mechanism h;

State_Type current_state;

typedef struct{
	char* current_state_indication;
	char* light;
	char* direction_valve_status;
    char* landing_gear_hydraulic_control;
	char* GPSS_status[2];
}State_Table;


static State_Table State_Machine[6]={
        {"GearDown","Yellow","Down","Enabled",{NULL,NULL}},
		{"CheckingBeforeTakeOFF","Yellow","Down","Enabled",{NULL,NULL}},
		{"RaisingGear","Red","Up","Enabled",{NULL,NULL}},
		{"GearUp","Off","NULL","Disabled",{NULL,NULL}},
		{"CheckBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
		{"LoweringGear","Yellow","Down","Enabled",{"Disabled","Enabled"}}
};


// Gear down mechanism 
void GearDown(void){

    current_state = Gear_Down;
	printf("\nEnter the status of pilot's lever & squat switch : ");
    // To clear the buffer
	fflush(stdout);      

    scanf("%d %d",&p,&squat_switch);

	if(p==Raising && squat_switch==on){

		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);
	}
	else{
		GearDown();
	}
}

//CheckingBeforeTakeOFF
void CheckingBeforeTakeOFF(void){

	current_state = Checking_Before_Takeoff;
	printf("\nEnter the status of pilot's lever and squat switch and hydraulic mechanism : ");
	fflush(stdout);

	scanf("%d %d",&p,&squat_switch,&h);

	if(p==Falling && squat_switch==off){
		GearDown();
	}
	else if(p ==Raising && squat_switch==on && h==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);
	}
	else if(p == Raising && squat_switch==on && h ==not_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].GPSS_status);
	}
}

//Raising Gear mechanism
void RaisingGear(void){

	current_state=Raising_Gear ;
	printf("\nEnter the status of pilot's lever and limit switch : ");
	fflush(stdout);

	scanf("%d %d",&p,&limit_switch);

	if(p==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);
	}
	else if(p ==Raising && limit_switch==off){

		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);
	}
	else{

		RaisingGear();
	}
}

//Gear Up mechanism  
void GearUp(void){

	current_state=Gear_Up;
	printf("\nEnter the status of pilot's lever : ");
	fflush(stdout);
	scanf("%d",&p);
	if(p ==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);
}
	else{

		GearUp();
	}

}

//CheckBeforeLanding
void CheckBeforeLanding(void)
{
	current_state=Check_Before_Landing;
	printf("\nEnter the status of pilot's lever and hydraulic mechanism status :");
	fflush(stdout);

	scanf("%d %d",&p,&h);

	if(p ==Falling && h ==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);
	}
	else if(p ==Falling && h ==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].GPSS_status);
	}
	else if(p ==(Raising)){

		CheckBeforeLanding();
	}
}

//Lowering Gear mechanism.
void LoweringGear(void){

	    current_state=Lowering_Gear;
		printf("\nEnter the status of pilot's lever and limit switch : ");
		fflush(stdout);

		scanf("%d %d",&p,&limit_switch);

		if(p == Falling &&limit_switch==on){

			current_state=Checking_Before_Takeoff;
			printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);
			printf("Light is: %s\n",State_Machine[current_state].light);
		}
		else if(p ==Raising && 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);
		}
		if(limit_switch==off){

			LoweringGear();
		}

    }

//Initiate_State_Machine
void Start_State_Machine(){
    
	current_state = Gear_Down;
	printf("\nAeroplane's Landing Gear is Intialized and current the program is in GearDown State & Light is: %s\n",State_Machine[current_state].light);
}


// Driver Code 
int main(){
    Start_State_Machine();

    while(1){
        statetable[current_state]();
    }
    
    return 0 ;
}

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.