Challenge

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

PROJECT 2:

Overview of the Project: (5 to 6 lines)

In this project, controlling the retraction and extension of Airplane’s landing gear can be implemented using Finite State Machine (FSM). FSM is the most efficient algorithm which is mathematical model of computation.

Goals ( 2 to 3 points)

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

Key Highlights of the Project: (4 to 5 points)

A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.

Deliverables of this project: (4 to 5 points)

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.

Expected Outcomes: (4 to 5 points)

The student will be getting 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.

Explanation:

In the airplane has gear for landing

1. right gear

2. left gear

3. nose gear

LIMIT SWITCH:

In the airplane every leg of gear has one limit switch. nose gear has one extra squat switch to dertermine the airplane is ground or not.

limit switch status Gear state
closed UP
open DOWN
Airplane state squat switch state
Airplane is ground and gear are lock close
airplane is taking landing open

Direction of valve:

pilot lever state valve direction
UP direction valve = up
DOWN direction valve = down
pilot lever state Light status
lever falling red
lever rising red

CODE:

State file:

#ifndef STATES_H_
#define STATES_H_


#include<stdio.h>

// function //

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 Switch
{

open,
close /// 2

}Switch_status;

typedef enum Pilot_Lever
{
Raising,
Falling, // 1
UP,
DOWN

}Pilot_Lever_Status;

typedef enum Hydraulic_Mechanism
{

Working, // 3
Malfunctioning

}Hydraulic_Mechanism_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_indication;
char* light_status;
char* direction_valve_status;
char* hydraulic_pump_control_status;
char* Gas_pressurized_spring_status[2];

}State_Table;

static State_Table State_Machine[6] =
{
{"Gear Down","Green","Down","Enable",{NULL,NULL}},
{"CheckingBeforeTakeOff","Green","Down","Enable",{NULL,NULL}},
{"RaisingGear","Red","Up","Enable",{"Disable","Enable"}},
{"GearUp","Off","Null","Disable",{NULL,NULL}},
{"CheckingBeforeLanding","Red","Down","Enable",{NULL,NULL}},
{"LoweringGear","Green","Down","Enable",{"Disable","Enable"}}
};

#endif /* STATES_H_ */

Main file:

#include "states.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]();
}
}

Initial state machine file:

#include "states.h"

void Init_State_Machine()

{

current_state = GR_DWN;
printf("\nState Machine is initialized & program is in gear_down state &light status: %s\n",
State_Machine[current_state].light_status);
}

Check before takeoff:

#include "states.h"

void Checking_Before_Takeoff()
{
current_state=CHK_BFR_TKFF;

printf(" Enter the pilot lever position squat switch status and hydraulic mechanism status: ");
fflush(stdout);
scanf("%d %d %d", &pilot_lever, &squat_switch, &hydraulic_mechanism);
printf("\nWait for 2 sec\n");
if(pilot_lever ==Falling && squat_switch == close)
{
Gear_Down();
}
else if (pilot_lever == UP && squat_switch == open && hydraulic_mechanism == Working)
{
current_state = RSING_GR;
printf("Current state : %s\n", State_Machine[current_state].current_state_indication);
printf("light : %s\n",State_Machine[current_state].light_status);
printf("direction valve status: %s\n", State_Machine[current_state].direction_valve_status);
}
else if (pilot_lever == UP && squat_switch == open && hydraulic_mechanism == Malfunctioning)
{
current_state = RSING_GR;
printf("Current state :%s \n",State_Machine[current_state].current_state_indication);
printf("light : %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);
}
}

Raising gear file:

#include "states.h"

void Raising_Gear()
{
current_state = RSING_GR;

printf("\nEnter the limit switch status,pilot lever status:");
fflush(stdout);
scanf("%d %d",&pilot_lever, &limit_switch);
printf("\nWait for 1 sec\n");
if(pilot_lever == Falling && limit_switch == open)
{
current_state = CHK_BFR_LND;
printf("Current 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].hydraulic_pump_control_status);

}
else if (limit_switch == close && pilot_lever == UP)
{
current_state = GR_UP;
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].hydraulic_pump_control_status);

}
else
{
Raising_Gear();
}
}

Gear up file:

#include "states.h"

void Gear_Up()

{
current_state = GR_UP;

printf("enter the pilot lever position: ");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Falling)
{
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].hydraulic_pump_control_status);

}
else
{
Gear_Up();
}
}

Gear down file:

void Gear_Down(void)
{
current_state = GR_DWN;

printf("\nEnter the pilot lever position and squat switch status: ");
fflush(stdout);
scanf("%d %d",&pilot_lever, &squat_switch);
if(pilot_lever == Raising && squat_switch == open)
{
current_state = CHK_BFR_TKFF;
printf("\nCurrent state : %s\n",State_Machine[current_state].current_state_indication);
printf("light is : %s\n", State_Machine[current_state].light_status);

}
else
{
Gear_Down();
}

}

Lowring gear file:

#include "states.h"

void Lowering_Gear()
{
current_state = LWRNG_GR;

printf("Enter the limit switch status,pilot leaver status:");
fflush(stdout);
scanf("%d %d", &limit_switch, &pilot_lever);
if(pilot_lever == Raising)
{
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);
}
if (limit_switch == open)
{
current_state = GR_DWN;
printf("Current 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].hydraulic_pump_control_status);

}
if(limit_switch == close)
{
Lowering_Gear();
}
}

Check before landing:

#include "states.h"

void Checking__Before_Landing()
{
current_state = CHK_BFR_LND;

printf(" Enter the pilot 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("Current state : %s\n",State_Machine[current_state].current_state_indication);
printf("light is :%s\n",State_Machine[current_state].light_status);
printf("direction valve status: %s\n",State_Machine[current_state].direction_valve_status);
}
else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)
{
current_state = LWRNG_GR;
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]);

}
if(pilot_lever == (UP || Raising || Falling))
{
Checking__Before_Landing();
}
}

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.