Challenge

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

Embedded Live Batch 12

Aim - To Write a code and implement the control of retraction and extension of airplanes landing gear using Finite State Machine.

Program -

  • Main Function (gears.c) -
    /*
     * gears.c
     *
     *  Created on: Oct 15, 2022
     *      Author: shri
     */
    
    #include <stdio.h>
    #include "States.h"   // Pre-Processor Including States Header and standard Input Output
    
    static void(*state_table[])(void) = {Gear_Down, Checking_Before_Takeoff, Raising_Gear, Gear_Up, Checking_Before_Landing, Lowering_Gear};
    
    // Using State Table for the conditions for retraction and extension of landing gears
    
    int main()   // main-function
    {
    	Init_State_Machine(); // Initial State is declared
    	while(1)              // While loop execution with current state in state table
    	{
    		state_table[current_state]();
    	}
    }
  • Header File (States.h) -
    /*
     * States.h
     *
     *  Created on: Oct 24, 2022
     *      Author: shri
     */
    
    #ifndef STATES_H_
    #define STATES_H_
    
    void Init_State_Machine();
    void Gear_Down();
    void Checking_Before_Takeoff();
    void Raising_Gear();
    void Gear_Up();
    void Checking_Before_Landing();
    void Lowering_Gear();
    
    // All the states are declared using void
    
    typedef enum State  // declaring the alternative name as state
    {
    	GEAR_DOWN,
    	CHK_BFR_TKFF,
    	RAISING_GEAR,
    	GEAR_UP,
    	CHK_BFR_LND,
    	LOWERING_GEAR
    
    }State_Type;      // State Type is declared
    
    typedef enum Switch // declaring the alternative name as Switch
    {
    	Open,
    	Close
    
    }Switch_Status;  // Switch Status is declared
    
    typedef enum Pilot_Lever // declaring the alternative name as Pilot_Lever
    {
    	Rising,
    	Falling,
    	UP,
    	Down
    }Pilot_Lever_Status; //  Pilot_Lever_Status is declared
    
    typedef enum Hydraulic_Mechanism // declaring the alternative name as Hydraulic_Mechanism
    {
    	Working,
    	Malfunctioning
    
    }Hydraulic_Mechanism_Status; //  Hydraulic_Mechanism_Status is declared
    
    static volatile Switch_Status squat_switch;                    // Storing Switch_Status as Squat_Switch and Limit Switch in the main memory
    static volatile Switch_Status limit_switch;
    static volatile Pilot_Lever_Status pilot_lever;                // Storing Pilot_Lever_Status as Pilot_lever in the main memory
    static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;  // Storing Hydraulic_Mechanism_Status as hydraulic_mechanism in the main memory
    
    
    State_Type current_state; // Current State will take  State_Type
    
    typedef struct            // structure is defined
    {
    	char* current_state_indication;
    	char* light_status;
    	char* direction_valve_status;
    	char* hydaulic_pump_control_status;
    	char* gas_pressurized_spring_status;         // structure members are declared using the character
    }State_Table;
    
    // State Table declaration
    
    static State_Table State_Machine[6] = {
    
    		        {"GearDown","Green","Down","Enabled",0,0},
    				{"Checking Before Take Off","Green","Down","Enabled",0,0},
    				{"Raising Gear","Red","Up","Enabled","Enabled"},
    				{"Gear Up","Off","Null","Disabled",0,0},
    				{"Checking Before Landing","Red","Down","Enabled",0,0},
    				{"Lowering Gear","Green","Down","Enabled","Enabled"}
    
    
    
    };
    
    #endif /* STATES_H_ */
  • Initial State -
    /*
     * Initial.c
     *
     *  Created on: Oct 24, 2022
     *      Author: shri
     */
    
    #include "States.h"  // Including the header file
    
    void Init_State_Machine()  // Initial State Condition
    {
    	current_state = GEAR_DOWN;  // Current State of the machine
    
    	printf("State Machine is initialized & Program is in Gear Down State & Light Status: %s\n",State_Machine[current_state].light_status);
    
    	// Printing the Initial State and Light Status
    }​
  • Gear Down -
    /*
     * Gear_Down.c
     *
     *  Created on: Oct 24, 2022
     *      Author: shri
     */
    
    #include "States.h"
    #include <stdio.h>     // Pre-Processor Including States Header and standard Input Output
    
    void Gear_Down(void) // gear down function
    {
    	current_state = GEAR_DOWN;
    	printf("\nEnter the Pilot's Lever Position and Squat Switch Status :");
    	fflush(stdout);
    	scanf("%d %d",&pilot_lever,&squat_switch); // printing and scanning Pilot Lever position and sqaut switch
    
    	if(pilot_lever == Rising && squat_switch == Open) // If condition to change the state
    	{
    		current_state = CHK_BFR_TKFF;
    		printf("\nCurrent State: %s \n",State_Machine[current_state].current_state_indication);
    		printf("Light Status : %s \n",State_Machine[current_state].light_status);
    
    		// Printing the necceasry indications of the next state
    	}
    	else
    	{
    		Gear_Down();
    	}
    }
  • Checking Before Takeoff -
    /*
     * Checking_Before_TakingOff.c
     *
     *  Created on: Oct 24, 2022
     *      Author: shri
     */
    
    #include <stdio.h>
    #include "States.h" // Pre-Processor Including States Header and standard Input Output
    
    void Checking_Before_Takeoff()
    {
    	current_state = CHK_BFR_TKFF;
    	printf("\nEnter the Pilot's Lever Position, Squat Switch and Hydraulic Mechanism Status:");
    	fflush(stdout);
    	scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
    
    	// printing and scanning Pilot Lever position, sqaut switch and Hydraulic Mechanism Status
    
    	printf("\nWait for 4 seconds\n"); // Waiting for 4 seconds
    
    	if(pilot_lever == Falling || squat_switch == Close) // If else statements for determining the next state
    	{
    		Gear_Down();
    	}
    	else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)
    	{
    		current_state = RAISING_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\n",State_Machine[current_state].direction_valve_status);
    
    		// Printing the necessary indications of the next state
    	}
    	else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Malfunctioning)
    	{
    		current_state = RAISING_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_valve_status);
    		printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status);
    
    		// Printing the necceasry indications of the next state
    	}
    }


  • Raising Gear -
    /*
     * Rising_Gear.c
     *
     *  Created on: Oct 24, 2022
     *      Author: shri
     */
    
    #include <stdio.h>
    #include "States.h" // Pre-Processor Including States Header and standard Input Output
    
    void Raising_Gear()
    {
    	current_state = RAISING_GEAR;
    	printf("\nEnter the Pilot Lever Status, Limit Switch Status:");
    	fflush(stdout);
    	scanf("%d %d",&pilot_lever,&limit_switch);
    
    	// printing and scanning Pilot Lever position and sqaut switch
    
    	if(pilot_lever == UP && limit_switch == Close) // If else statements for determining the next state
    	{
    		current_state = GEAR_UP;
    		printf("\nCurrent Status :%s\n",State_Machine[current_state].current_state_indication);
    		printf("Light Status :%s\n",State_Machine[current_state].light_status);
    		printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydaulic_pump_control_status);
    
    		// Printing the necceasry indications of the next state
    	}
    	else if(pilot_lever == Falling && limit_switch == Open)
    	{
    		current_state = CHK_BFR_LND;
    		printf('\nCurrent State: %s\n',State_Machine[current_state].current_state_indication);
    		printf("Light Status:%s\n",State_Machine[current_state].light_status);
    		printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydaulic_pump_control_status);
    
    		// Printing the necceasry indications of the next state
    	}
    
    	else
    	{
    		Raising_Gear();
    	}
    }


  • Gear Up -
    /*
     * Gear_Up.c
     *
     *  Created on: Oct 24, 2022
     *      Author: shri
     */
    
    #include <Stdio.h>
    #include "States.h" // Pre-Processor Including States Header and standard Input Output
    
    void Gear_Up()
    {
    	current_state = GEAR_UP;
    	printf("\nEnter the Pilot's Lever Position:");
    	fflush(stdout);
    	scanf("%d",&pilot_lever);
    
    	// Printing and scanning the Pilot Lever Status
    
    	if(pilot_lever == Falling) // if statement to determine the next condition
    	{
    		current_state = CHK_BFR_LND;
    		printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
    		printf("Light Status :%s\n",State_Machine[current_state].light_status);
    		printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydaulic_pump_control_status);
    
    		// Printing the necceasry indications of the next state
    	}
    	else
    	{
    		Gear_Up();
    	}
    }


  • Checking Before Landing -
    /*
     * Check_Before_Landing.c
     *
     *  Created on: Oct 24, 2022
     *      Author: shri
     */
    
    #include <stdio.h>
    #include "States.h" // Pre-Processor Including States Header and standard Input Output
    
    void Checking_Before_Landing()
    {
    	current_state = CHK_BFR_LND;
    	printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:");
    	fflush(stdout);
    	scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
    
    	// Printing and scanning the Pilot Lever and hydraulic mechanism
    
    	if(pilot_lever == Down && hydraulic_mechanism == Working) // If else statements for determining the next condition
    	{
    		current_state = LOWERING_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_valve_status);
    
    		// Printing the necceasry indications of the next state
    	}
    	else if(pilot_lever == Down && hydraulic_mechanism == Malfunctioning)
    	{
    		current_state = LOWERING_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_valve_status);
    		printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
    
    		// Printing the necceasry indications of the next state
    	}
    	else if(pilot_lever == (UP || Rising || Falling))
    	{
    		Checking_Before_Landing();
    	}
    }


  • Lowering Gear -
    /*
     * Lowering_Gear.c
     *
     *  Created on: Oct 24, 2022
     *      Author: shri
     */
    
    #include <stdio.h>
    #include "States.h" // Pre-Processor Including States Header and standard Input Output
    
    void Lowering_Gear()
    {
    	current_state = LOWERING_GEAR;
    	printf("\nEnter the Limit Switch Status, Pilot Lever Status:");
    	fflush(stdout);
    	scanf("%d %d",&limit_switch,&pilot_lever);
    
    	//Printing and Scanning the Limit Switch and Pilot Lever
    
    	if(limit_switch == Open && pilot_lever == Down) // If Else statements to determine the next condition
    		{
    			current_state = GEAR_DOWN;
    			printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
    			printf("Light Status:%s\n",State_Machine[current_state].light_status);
    			printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydaulic_pump_control_status);
    		}
    
    	else if(limit_switch == Close && pilot_lever == Rising)
    	{
    		current_state = CHK_BFR_TKFF;
    		printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
    		printf("Light Status:%s\n",State_Machine[current_state].light_status);
    
    	}
    
    
    	else
    	{
    		Lowering_Gear();
    	}
    }

Theory -

  • Gears -
    An Airplane has three Landing Gears - Nose Gear, Left Gear and Right Gear. There is a hydraulic pump which is exerting pressure to the gears to bring it down or pull it up and that pump is
    electrically driven.
  • 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.

  • Limit Switch Function - Open = Gear Down, Close = Gear Up.

  • Squat Switch Function - Open = Airplane is taking off / landing /airborne, Close = Airplane is grounded and Gears are locked

  • Light Status - OFF = Gear is Up, GREEN - Gear is DOWN, RED = Gear in transition.

  • Direction Valve Function - A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.

  • Direction Valve Status - Down = Gear Down, UP = Raising Gear, Hydraulic Pump Disables = Gear UP.
  • Hydraulic mechanism is monitoring the pressure exerted on the nose gear and to neutralize that pressure its applying a
    pressure on the opposite direction. Hydraulic Control can detect the rising edge and falling edge of pilot’s lever. In case of Hydraulic system failure,there are two gas pressurized springs by which gears can be extended.

Result -



  • State Machine is Initialized and the current state and Light Status is displayed.

  • After Entering the Pilot Lever Position and Squat Switch Status, the State is changed to 'Checking Before Takeoff', Light Status is GREEN.

  • After Entering the Pilot Lever Position, Sqaut Switch Position and Hydraulic Mechanism Status, we enter in 'Raising Gear' State, the Light Status becomes RED.

  • After Entering the Pilot Lever Status and Limit Switch Status, we enter 'Gear Up' state, the Light Status is OFF.

  • After Entering the Pilot Lever Status, we enter 'Checking Before Landing' State, the Light Status is RED.

  • Now we Enter the Pilot Lever Position and Status of Hydraulic Mechanism, After entering their values, we go in 'Lowering Gear' State. The Light Status becomes GREEN.

  • Finally, after we enter the Limit Switch Status and Pilot Lever Status, we enter into 'Gear Down' State and Light Status becomes GREEN.

  • Hence, the Program is Successfully executed
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.