Challenge

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

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

AIM :

Implement the code for controlling the retraction and extensioin of Airplane's Landing gear.

Introduction :

An airplne has three gears for landing:

  • Nose Gear
  • Left Gear
  • Right Gear

The hydraulic pump are used for exerting pressure to the gears to bring it down or pull it up and that pump is electrically driven.

Limit switches: Every leg of the gear has one limit switch.

Squat switch: only nose gear have squat switch to determine whether the airplan is in ground or not.

Switch state

State of Gears

Limit Switch CLOSED

Gear is UP

Limit Switch OPENED

Gear is DOWN

Switch State

State of Airplane

Squat Switch CLOSED

Airplane is grounded and gears are locked

Squat Switch OPENED

Airplane is taking off/ landing/ airborne

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

Status of Direction Valve

States of landing gear

Direction valve = Down

(Gear Down) (Parked at bay or Landed)

Direction valve = Up

Raising Gear (Taking Off)

Control of hydraulic pump for the landing gear part is disabled

Gear up (Airborne)

Direction valve = down

Lowering Gear (Landing)

Input for the direction valve :

Pilot's Lever State

Direction Valve State

Lever UP

Direction valve = Up

Lever Down

Direction valve = Down

Pilot's Lever State

Light Status

Lever Rising Edge

Red

Lever Falling Edge

Red

Every gear has one light. According to the state of the gear, color of the light is changing.

Landing Gear State

Light Status

Gear is up

OFF

Gear is down

Green

Gear in transit

Red

By incorperating all these constraints we can come to result.

PROGRAMS :

HEADER FILE :

/*
 * States.h
 * Created on: 28-Jan-2023
 *  Author: arjun
 */

#ifndef STATES_H_
#define STATES_H_

/* Declaring all the functions */
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
{
	Gear_down, Check_before_takeoff, Raising_gear, Gear_up, Check_before_landing, lowering_gear
}State_Type;

typedef enum Switch
{
	Open, Close
}Switch_Status;

typedef enum Pilot_Lever
{
	Rising, Falling, Up, Down
}Pilot_Lever_Status;

typedef enum Hydraulic_Mechanism
{
	Working, Malfunctioning
}Hydraulic_Mechanism_Status;

/* For changing the states */
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", "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 /* STATES_H_ */

MAIN C FILE :

/*
 ============================================================================
 Name        : Project2_Aeroplane_landing.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

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

}

INIT_STATE_MACHINE FILE :

/*
 * Init_State_Machine.c
 * Created on: 29-Jan-2023
 * Author: arjun
 */

#include "States.h" // User-defined library function

void Init_State_Machine()
{
	// System Initialized
	current_state = Gear_down;
	printf("The state machine is initialized and is in Gear Down state with the Light status: %s\n", State_Machine[current_state].light_status);
}

GEAR_DOWN FILE :

/*
 * Gear_Down.c
 * Created on: 29-Jan-2023
 * Author: arjun
 */

#include<stdio.h>
#include "States.h"

void Gear_Down(void)
{
	current_state = Gear_down;

	printf("\nEnter the Pilot's lever position and the Squat switch status: ");
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &squat_switch);

	if (pilot_lever == Rising && squat_switch == Open)
	{
		current_state = Check_before_takeoff;
		printf("\nCurrent state: %s\n", State_Machine[current_state].current_state_indication);
		printf("Light status: %s\n", State_Machine[current_state].light_status);
	}

	else
	{
		Gear_Down();
	}
}

CHECKING_BEFORE_TAKEOFF FILE :

/*
 * Checking_Before_Take_Off.c
 * Created on: 29-Jan-2023
 * Author: arjun
 */

#include<stdio.h>
#include "States.h"

void Checking_Before_Takeoff()
{
	current_state = Check_before_takeoff;
	printf("\nEnter the Pilot's 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 = 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: %s\n\n", State_Machine[current_state].direction_valve_status);
	}

	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: %s\n\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]);
	}
}

RAISING_GEAR FILE :

/*
 * Raising_Gear.c
 * Created on: 29-Jan-2023
 * Author: arjun
 */

#include<stdio.h>
#include "States.h"

void Raising_Gear()
{
	current_state = Raising_gear;
	printf("\nEnter the Pilot's lever position and the Limit switch 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 = Check_before_landing;
		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 if (pilot_lever == Up && limit_switch == Close)
	{
		current_state = Gear_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 :

/*
 * Gear_Up.c
 * Created on: 29-Jan-2023
 * Author: arjun
 */

#include<stdio.h>
#include "States.h"

void Gear_Up()
{
	current_state = Gear_up;
	printf("\nEnter the Pilot's lever position: ");
	fflush(stdout);
	scanf("%d", &pilot_lever);

	if (pilot_lever == Falling)
	{
		current_state = Check_before_landing;
		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();
	}
}

CHECKING_BEFORE_LANDING FILE :

/*
 * Checking_Before_Landing.c
 * Created on: 29-Jan-2023
 * Author: arjun
 */

#include<stdio.h>
#include "States.h"

void Checking_Before_Landing()
{
	current_state = Check_before_landing;
	printf("\nEnter the Pilot's lever position and Hydraulic mechanism status: ");
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &hydraulic_mechanism);

	if (pilot_lever == Down && hydraulic_mechanism == Working)
	{
		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: %s\n\n", State_Machine[current_state].direction_valve_status);
	}

	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: %s\n\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 || Rising || Falling))
	{
		Checking_Before_Landing();
	}
}

LOWERING_GEAR FILE :

/*
 * Lowering_Gear.c
 * Created on: 29-Jan-2023
 * Author: arjun
 */

#include<stdio.h>
#include "States.h"

void Lowering_Gear()
{
	current_state = lowering_gear;
	printf("\nEnter the Pilot's lever position and the Limit switch status: ");
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &limit_switch);

	if (pilot_lever == Rising && limit_switch == Close)
	{
		current_state = Check_before_takeoff;
		printf("\nCurrent state: %s\n", State_Machine[current_state].current_state_indication);
		printf("Light status: %s\n", State_Machine[current_state].light_status);
	}

	if (pilot_lever == Down && limit_switch == Open)
	{
		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].hydraulic_pump_control_status);
	}

	else
	{
		Lowering_Gear();
	}
}

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.