Challenge

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

AIM :

To show the implementation of retraction and extension function of Airplane’s landing gear using Finite State Machine (FSM)

GOALS:

  • Controlling the direction of Valve.
  • Controlling the retraction and extension of Airplane’s landing gear.
  • indicating stages by different light signals.
  • proper checking of gears before landing and take off.

GEARS:

Usually the airplane consists of three gears for smooth landing and take off

1.Nose gear.

2.Left gear.

3.Right gear.

SWITCHES:
Each gear consists of seperate limit switches and additionally nose gear will have a squat switch to check whether is lane is in ground or not.

HYDRALIC PUMP:

It exerting pressure to the gears to bring it down or pull it up and that pump is electrically driven.

STATE DIAGRAM:


STATE TABLE:

PROGRAM :

INPUT:

MAIN.C

#include <stdio.h> //header
#include "sub.h"

static void (*state_table[])(void) = {Gear_Down,Checking_Before_Takeoff,Raising_Gear,Gear_Up,Checking_Before_Landing,Lowering_Gear};
int main()
{
Init_State_Machine();
while(1)
{
state_table[current_state]();
}
}

SUB.C

#include "sub.h" // header
#include <stdio.h>

void Init_State_Machine()
{
printf("\n Light_Status : %s\n",State_Machine[current_state].light_Status);
printf("\n Current State is%s\n",State_Machine[current_state].current_state);
}

void Gear_Down(void)
{
current_state = GR_DWN;
printf("\n Enter the position of Pilot's Lever 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);
printf("Light Status:%s\n",State_Machine[current_state].light_Status);

}
else
{
printf("\n returning to gear down state");
Gear_Down();
}
}


void Checking_Before_Takeoff()
{
current_state = CHK_BFR_TKFF;
printf("\n Enter the position of Pilot's Lever,Squat Switch Status, Hydraulic Mechanism Status :");
fflush(stdout);
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
printf("\n Wait for 2 secs\n");
if (pilot_lever == UP && squat_switch == Open )
{
fflush(stdout);
if(hydraulic_mechanism == Working)
{
current_state = RSING_GR;
printf("\n Current State: %s\n",State_Machine[current_state].current_state);
printf("Light Status:%s\n",State_Machine[current_state].light_Status);
printf("Direction Value Status:%s\n\n",State_Machine[current_state].direction_value_status);
}
else if ( hydraulic_mechanism == Malfunctioning)
{
printf("Light Status:%s\n",State_Machine[current_state].light_Status);
printf("Direction Value Status:%s\n",State_Machine[current_state].direction_value_status);
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
}
else if(pilot_lever == Falling || squat_switch == Close)
{
printf("\n returning to gear down");
Gear_Down();
}
}


void Raising_Gear()
{
current_state = RSING_GR;
printf("\n Enter the Limit Switch Status, Pilot's Lever Position :");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
printf("\nWait for 1 sec\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);
printf ("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);
printf ("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
{
printf("\n returning to raising gear ");
Raising_Gear();
}
}


void Gear_Up()
{
current_state = GR_UP;
printf("\n Enter the Pilot's 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);
printf("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
{
printf("\n returning to gear up");
Gear_Up();
}
}


void Checking_Before_Landing()
{
current_state = CHK_BFR_LND;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state);
printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
if(pilot_lever == DOWN && hydraulic_mechanism == Working)
{
current_state = LWRNG_GR;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state);
printf("Light Status:%s\n",State_Machine[current_state].light_Status);
printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_value_status);
}
else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)
{
current_state = LWRNG_GR;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state);
printf("Light Status:%s\n",State_Machine[current_state].light_Status);
printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_value_status);
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}

else if(pilot_lever == (UP || Rising || Falling))
{
printf("\n returning to Checking_Before_Landing ");
Checking_Before_Landing();
}

}


void Lowering_Gear()
{
current_state = LWRNG_GR;
printf("\n Enter the Limit_Switch Status,Pilot_Lever Status ::");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if( limit_switch == Close && pilot_lever == Rising)

{
current_state = CHK_BFR_TKFF;
printf("\n Current State: %s\n",State_Machine[current_state].current_state);
printf("Light Status:%s\n",State_Machine[current_state].light_Status);
}
else if(limit_switch == Open && pilot_lever == DOWN)
{
current_state = GR_DWN;
printf ("\n Current State: %s\n",State_Machine[current_state].current_state);
printf ("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
{
printf("\n returning to lower gear");
Lowering_Gear();
}
}

SUB.H

#ifndef SUB_H_
#define SUB_H_


#include <stdio.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();

typedef enum State
{

GR_DWN,
CHK_BFR_TKFF,
RSING_GR,
GR_UP,
CHK_BFR_LND,
LWRNG_GR
}State_Type;

typedef enum Hydraulic_Mechanism
{
Working=0,
Malfunctioning=1
}Hydraulic_Mechanism_Status;

typedef enum Switch
{
Open=0,
Close=1
}Switch_Status;

typedef enum Pilot_Lever
{
Rising=0,
Falling=1,
UP=2,
DOWN=3
}Pilot_Lever_Status;


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
{
char* current_state;
char* light_Status;
char* direction_value_status;
char* hydraulic_pump_control_status;
char* gas_pressurized_spring_status[2];
}State_Table;

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",{"Disabled","Enabled"}},
{"Gear Up","Off","Null","Disabled",0,0},
{"Checking Before Landing","Red","Down","Enabled",0,0},
{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};


#endif /* SUB_H_ */



OUTPUT:

Light_Status : Green

Current State isGearDown

Enter the Pilot's Lever Position and Squat Switch Status:0 0

Current State:Checking Before Take Off
Light Status:Green

Enter the Pilot's Lever Position,Squat Switch Status, Hydraulic Mechanism Status :2 0 1

Wait for 2 secs
Light Status:Green
Direction Value Status:Down
Gas Pressurized Spring System Status:(null)

Enter the position of Pilot's Lever ,Squat Switch Status, Hydraulic Mechanism Status :2 0 0

Wait for 2 secs

Current State: Raising Gear
Light Status:Red
Direction Value Status:Up


Enter the Limit Switch Status, Pilot's Lever Position :1 0

Wait for 1 sec

Enter the Limit Switch Status, Pilot's Lever Position :1 2

Wait for 1 sec

Current State: Gear Up
Light Status:Off
Hydraulic Control for Landing Gear Status:Disabled

Enter the Pilot's Lever Position:1

Current State:Checking Before Landing
Light Status:Red
Hydraulic Control for Landing Gear Status:Enabled

Current State : Checking Before Landing

Enter the position of Pilot's Lever and Status of Hydraulic Mechanism:3 0

Current State : Lowering Gear
Light Status:Green
Direction Valve Status:Down

Enter the Limit_Switch Status,Pilot_Lever Status ::0 3

Current State: GearDown
Light Status:Green

IMAGE FOR REFERENCE :





RESULT :
Using fsm the c program for retraction and extension of Airplane’s landing gear using the switch and gear states of Airplane was generated successfully and acquired the expected results.

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.