Challenge

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

Answers

Overview of this project

  • This Project is for controling of retraction and extraction of airolan's landing gear. In this project we are simulate retraction and extraction of airplan's landing gear. In this project we also define all states of airplan's landing gear like gear down,check before takeoff, raising gear, gear up, cheack before landing and lowering gear. In this project we define all necessary function and all condition for process next step.

Key Highlights of the project

  • Squat switch is place very important role in airplan landing gear work of squat switch is basically intrrupt some function which not execute when plan as on ground position.
  • Limit switch is for check plan's landing gear is up position or not.
  • Direction valve is to use for lowering and rising of airplan's landing gear.
  • Gas pressurized spring system is working when hydraulic system malfunction.

Deliverablels of this project

  • 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.
  • Learn how to make finite state machine and how to implement this.
  • Lern all main point of Airplan's landing gear.

Main Program

#include<stdio.h>                                                                                      // include header file
#include"state.h"                                                                                      // include user define library

static void(*stateTable[])()={GearDown,CheckingBeforeTakeOFF,RaisingGear,GearUp,                       // initialize function
		                      CheckBeforeLanding,LoweringGear};

int main()                                                                                             // declare main function
{
	Initiate_State_Machine();                                                                          // call initialize state machine function
    while(1)                                                                                           // infinite while loop for continue running code
    {
    	stateTable[current_state]();                                                                   // call function based on current state
    }
}

void GearDown()                                                                                        // define gear down function
{
	current_state=GEAR_DOWN;                                                                           // make current state as gear down
    printf("Enter the status of pilot's lever and squat switch:");                                     // print instruction
    fflush(stdout);
    scanf("%d %d", &pilot_lever, &squat_switch);                                                       // scan input value
    if (pilot_lever==Raising && squat_switch==On)                                                      // check condition based on input value
    {
    	current_state=CHECKING_BEFORE_TAKEOFF;                                                         // change current state
        printf("Current state: %s\n", State_Machine [current_state].current_state_indication);         // print current state
        printf("Light is :%s\n", State_Machine[current_state].light);                                  // print light status
    }
    else
    {
    	GearDown();                                                                                    // if condition not satisfied call gear down function
    }
}

void CheckingBeforeTakeOFF()                                                                           // define CheckingBeforeTakeOFF function
{
	current_state=CHECKING_BEFORE_TAKEOFF;                                                             // change current state
	printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism: ");            // print instruction to input data
	fflush(stdout);
	scanf("%d %d %d", &pilot_lever, &squat_switch, &hydraulic_mechanism);                              // scan input value
	if(pilot_lever==falling && squat_switch==Off)                                                      // check condition for gear down
	{
		GearDown();                                                                                    // call gear down function
	}
	else if(pilot_lever==Raising && squat_switch==On && hydraulic_mechanism== working)                 // check condition for rising gear and hydraulic status
	{
		current_state=RAISING_GEAR;                                                                    // change state
		printf("Current state: %s\n", State_Machine [current_state].current_state_indication);         // print current state
		printf("Light is :%s\n", State_Machine [current_state].light);                                 // print light status
		printf("Status of Direction valve :%s\n",State_Machine [current_state].direction_valve_status);// print direction valve status
	}
	else if(pilot_lever==Raising && squat_switch==On && hydraulic_mechanism== not_working)             // check condition for rising gear and hydraulic status
	{
		current_state=RAISING_GEAR;                                                                    // change state
		printf("Current state: %s\n", State_Machine [current_state].current_state_indication);         // print current state
		printf("Light is :%s\n", State_Machine[current_state].light);                                  // print light status
		printf("Status of Direction valve :%s\n",                                                      // print direction valve status
				State_Machine[current_state].direction_valve_status);
		printf("Status of Gas Pressurised Spring System: %s\n",                                        // print gas presuurized spring status
				State_Machine[current_state].Gas_Pressurized_Spring_system_status[hydraulic_mechanism]);

	}
}
//RaisingGear
void RaisingGear()                                                                                     // define rising gear function
{
	current_state=RAISING_GEAR;                                                                        // change state to rising gear
	printf("Enter the status of pilot's lever and limit switch: ");                                    // print instruction to input data
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &limit_switch);                                                       // scan input data
	if (pilot_lever==falling && limit_switch==On)                                                      // check condition for check before landing
	{
		current_state=CHECK_BEFORE_LANDING;                                                            // change state
		printf("Current state: %s\n", State_Machine [current_state].current_state_indication);         // print current state
		printf("Light is :%s\n", State_Machine[current_state].light);                                  // print light status
		printf("Landing Gear Hydraulic Control:%s\n",                                                  // print landing gear hydraulic control status
				State_Machine[current_state].landing_gear_hydraulic_control);
	}
	else if(pilot_lever==Raising && limit_switch==Off)                                                 // check pilot lever and limit switch
	{
		current_state=GEAR_UP;                                                                         // change state
		printf("Current state: %s\n", State_Machine [current_state].current_state_indication);         // print current state
		printf("Light is :%s\n", State_Machine [current_state].light);                                 // print current light status
		printf("Landing Gear Hydraulic Control:%s\n",                                                  // print landing gear hydraulic control status
				State_Machine[current_state].landing_gear_hydraulic_control);
	}
	else
	{
		RaisingGear();                                                                                 // else call rising gear function again
	}
}
//GearUP
void GearUp ()                                                                                         // define gear up function
{
	current_state=GEAR_UP;                                                                             // change current state
	printf("Enter the status of pilot's lever: ");                                                     // print instruction to input data
	fflush(stdout);
	scanf("%d", &pilot_lever);                                                                         // scan data
	if (pilot_lever==falling)                                                                          // check condition
	{
		current_state=CHECK_BEFORE_LANDING;                                                            // change current state
		printf("Current state: %s\n", State_Machine [current_state].current_state_indication);         // print current status
		printf("Light is :%s\n", State_Machine [current_state].light);                                 // print light status
		printf("Landing Gear Hydraulic Control:%s\n",                                                  // print landig gear hydraulic control status
				State_Machine [current_state].landing_gear_hydraulic_control);
	}
	else
	{
		GearUp();                                                                                      // else call gearup function
	}
}
//CheckBeforeLanding
void CheckBeforeLanding()                                                                              // define checkbeforelanding function
{
	current_state=CHECK_BEFORE_LANDING;                                                                // change current state
	printf("Enter the status of pilot's lever and hydraulic mechanism status: ");                      // print instruction for input data
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &hydraulic_mechanism);                                                // scan input data
	if (pilot_lever==falling && hydraulic_mechanism==working)                                          // check condition for pilot lever and hydraulic mechanism
	{
		current_state=LOWERING_GEAR;                                                                   // change current state
		printf("Current state: %s\n", State_Machine [current_state].current_state_indication);         // print current state
		printf("Light is :%s\n", State_Machine [current_state]. light);                                // print light status
		printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status); // print direction valve status
	}
	else if(pilot_lever==falling && squat_switch==On && hydraulic_mechanism== not_working)             // check condition for pilot lever squat switch and hydraulic mech.
	{
		current_state=LOWERING_GEAR;
		printf("Current state: %s\n", State_Machine[current_state].current_state_indication);          // print current state
		printf("Light is :%s\n", State_Machine [current_state].light);                                 // print current light
		printf("Status of Direction valve :%s\n",State_Machine[current_state].direction_valve_status); // print direction valve status
		printf("Status of Gas Pressurised Spring System: %s\n",                                        // print gas pressurized spring system status
				State_Machine[current_state].Gas_Pressurized_Spring_system_status[hydraulic_mechanism]);
	}
	else if(pilot_lever== (Raising || falling))                                                             // check condition of pilot lever
	{
		CheckBeforeLanding();                                                                          // call function
	}
}
//LoweringGear
void LoweringGear()                                                                                    // define lowering gear function
{
	current_state=LOWERING_GEAR;                                                                       // change state
	printf("Enter the status of pilot's lever and limit switch: ");                                    // print instruction to input data
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &limit_switch);                                                       // scan input data
	if (pilot_lever==Raising && limit_switch==On)                                                      // check condition for pilot lever and limit switch
	{
		current_state=CHECKING_BEFORE_TAKEOFF;                                                         // change current state
		printf("Current state: %s\n", State_Machine [current_state].current_state_indication);         // print current state
		printf("Light is :%s\n", State_Machine[current_state].light);                                  // print light status
	}
	else if(pilot_lever==falling && limit_switch==Off)                                                      // check condition for pilot lever and limit switch
	{
		current_state=GEAR_DOWN;                                                                       // change current state
		printf("Current state: %s\n", State_Machine[current_state].current_state_indication);          // print current state
		printf("Light is :%s\n", State_Machine [current_state].light);                                 // print light status
		printf("Landing Gear Hydraulic Control: %s\n",                                                 // print landing gear hydraulic control status
				State_Machine[current_state].landing_gear_hydraulic_control);
	}
	else if(limit_switch==Off)                                                                         // check condition for limit switch
	{
		LoweringGear();                                                                                // call lowering gear function
	}
}

void Initiate_State_Machine()                                                                          // define intialize state machine function
{
	current_state=GEAR_DOWN;                                                                           // change current state
	printf("The Finite State Machine is Initialized and current the program is in "                    // print light status
			"Gear Down & Light is : %s\n",State_Machine [current_state].light);
}

Library File For This Program

#ifndef FSM_H_
#define FSM_H_

#include<stdio.h>                                                               // include header file

void Initiate_State_Machine();                                                  // initialize initial state machine function
void GearDown();                                                                // initialize geardown function
void CheckingBeforeTakeOFF();                                                   // initialize checkingbeforetackoff function
void RaisingGear();                                                             // initialize risinggear function
void GearUp();                                                                  // initialize gearup function
void CheckBeforeLanding();                                                      // initialize checkbeforelanding function
void LoweringGear();                                                            // initialize loweringgear function

typedef enum State                                                              // initialize enum function for state type
{
    GEAR_DOWN,                                                                  // state type gear down
    CHECKING_BEFORE_TAKEOFF,                                                    // state type checking before takeoff
	RAISING_GEAR,                                                           // state type rising gear
    GEAR_UP,                                                                    // state type gear up
    CHECK_BEFORE_LANDING,                                                       // state type check before landing
    LOWERING_GEAR,                                                              // state type lowering gear
}State_Type;                                                                    // change enum function name

typedef enum Switch                                                             // initialize enum function for switch status
{
    On,                                                                         // switch status on means plane on air
    Off                                                                         // switch status off mean plan is on ground
}Switch_Status;                                                                 // change enum function name

typedef enum pilot_lever                                                        // initialize enum function for pilot lever status
{
    Raising,                                                                    // rising status
    falling                                                                     // falling status
}Pilot_Lever_Status;                                                            // change enum function name using typedef

typedef enum hydraulic_mechanism                                                // initialize enum function for hydraulic mechanism
{
	working,                                                                // status working mean hydraulic mechanism is ok
	not_working                                                             // status not working mean hydraulic mechanism is malfunction
}Hydraulic_Mechanism_Status;                                                    // change enum function name using typedef

static volatile Switch_Status squat_switch;                                     // assign variable for squat switch
static volatile Switch_Status limit_switch;                                     // assign variable for limit switch
static volatile Pilot_Lever_Status pilot_lever;                                 // assign variable for pilot lever
static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;                 // assign variable for hydraulic mechanism

State_Type current_state;                                                       // define current state

typedef struct                                                                  // initialize structure for state table data
{
	char* current_state_indication;                                         // initialize current state indication
	char* light;                                                            // initialize light
	char* direction_valve_status;                                           // initialize direction valve status
	char* landing_gear_hydraulic_control;                                   // initialize landing gear hydraulic control
	char* Gas_Pressurized_Spring_system_status[2];                          // initialize gas pressurized spring system
}State_Table;                                                                   // change structure name using typedef

static State_Table State_Machine[6]= {                                          // make state table
		{"GearDown","Green","Down","Enabled",{NULL,NULL}},
		{"CheckingBeforeTakeOFF","Green","Down","Enabled",{NULL,NULL}},
		{"RaisingGear","Red","Up","Enabled",{"Disabled","Enabled"}},
		{"GearUp","Off","Null","Disabled",{NULL,NULL}},
		{"CheckBeforeLanding","Red","Down","Enabled",{NULL, NULL}},
		{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}
};

#endif /* FSM_H_ */

Output Of This Program

Output with Hydraulic Control Malfunction

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.