Challenge

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

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.

//C-programing to implement airplane_gear

#include<stdio.h>
// create seven functions for process of controlling gear

void initiate_state_machine();
void GearDown();
void CheckingBeforeTakeOff();
void RaisingGear();
void GearUp();
void CheckingBeforeLanding();
void LoweringGear();
static void(*statetable[])(void)={GearDown, CheckingBeforeTakeOff, RaisingGear, GearUp, CheckingBeforeLanding, LoweringGear};

// four enum type structure for comparison and easy way giving inputs
typedef enum state
{
GEAR_DOWN,
CHECKING_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECKING_BEFORE_LANDING,
LOWERING_GEAR,
}state_type;

typedef enum Switch
{
open,
close,
}switch_states;

typedef enum pilot_lever
{
Raising,
Falling,
}pilot_lever;

typedef enum Hydraulic_Control
{
working,
not_working,
}hydraulic_Control;

// Topic Names of enum structure

static volatile switch_states squat_switch;
static volatile switch_states limit_switch;
static volatile pilot_lever p1;
static volatile hydraulic_Control hc;

state_type current_state;

// this structure for different type conditions
typedef struct
{
char *current_state_indicition;
char *signal_light;
char *direction_valve_status;
char *landing_gear_hydraulic_control;
char *Gas_Pressurized_Spring_system_status[2];
}State_Table;

// structure- sate_table and topic name is state_machine
static State_Table state_machine[6]={{"GearDown","Green","Down","Enabled",{NULL,NULL}},
{"CheckingBeforTakeOff","Green","Down","Enabled",{NULL,NULL}},
{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"GearUp","close","Null","Disabled",{NULL,NULL}},
{"CheckingBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}

};
// main function
int main()
{
initiate_state_machine();
while(1)
{
statetable[current_state]();
}
}

void GearDown()
{
current_state=GEAR_DOWN;
printf("Enter the status of pilot's lever and squat switch");
fflush(stdout);
scanf("%d %d",&p1,&squat_switch);
if(p1==Raising && squat_switch==open)
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("current state:%s\n",state_machine[current_state].current_state_indicition);
printf("Light is :%s\n", state_machine[current_state].signal_light);
}
else
{
GearDown();
}
}
void CheckingBeforeTakeOff()
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("Enter the states of pilot's lever and squat switch and hydraulic control:");
fflush(stdout);
scanf("%d %d",&p1,&squat_switch,&hc);
if(p1==Falling && squat_switch==close)
{
GearDown();
}
else if(p1==Raising && squat_switch==open && hc==working)
{
current_state=RAISING_GEAR;
printf("Current State:%s\n",state_machine[current_state].current_state_indicition);
printf("Light is:%s\n",state_machine[current_state].signal_light);
printf("Status of Direction valve:%s\n",state_machine[current_state].direction_valve_status);
}
else if(p1==Raising && squat_switch==open && hc==not_working)
{
current_state=RAISING_GEAR;
printf("Current State:%s\n",state_machine[current_state].current_state_indicition);
printf("Light is:%s\n",state_machine[current_state].signal_light);
printf("Status of Direction valve:%s\n",state_machine[current_state].direction_valve_status);
printf("Status of gas pressurized Spring System:%s\n",state_machine[current_state].Gas_Pressurized_Spring_system_status);
}
}
void RaisingGear()
{
current_state=RAISING_GEAR;
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&p1,&limit_switch);
if(p1==Falling && limit_switch==open)
{
current_state=CHECKING_BEFORE_LANDING;
printf("Current State:%s\n",state_machine[current_state].current_state_indicition);
printf("Light is:%s\n",state_machine[current_state].signal_light);
printf("Landing Gear Hydraulic Control:%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
else if(p1==Raising && limit_switch==close)
{
current_state=GEAR_UP;
printf("Current State:%s\n",state_machine[current_state].current_state_indicition);
printf("Light is:%s\n",state_machine[current_state].signal_light);
printf("Landing Gear Hydraulic Control:%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
else
{
RaisingGear();
}
}
void GearUp()
{
current_state=GEAR_UP;
printf("Enter the status of pilot's lever:");
fflush(stdout);
scanf("%d",&p1);
if(p1==Falling)
{
current_state=CHECKING_BEFORE_LANDING;
printf("Current State:%s\n",state_machine[current_state].current_state_indicition);
printf("Light is:%s\n",state_machine[current_state].signal_light);
printf("Landing Gear Hydraulic Control:%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
else
{
GearUp();
}
}
void CheckingBeforeLanding()
{
current_state=CHECKING_BEFORE_LANDING;
printf("Enter the status of pilot's lever and hydraulic mechanism status:");
fflush(stdout);
scanf("%d %d",&p1,&hc);
if(p1==Falling && hc==working)
{
current_state=LOWERING_GEAR;
printf("Current State:%s\n",state_machine[current_state].current_state_indicition);
printf("Light is:%s\n",state_machine[current_state].signal_light);
printf("Status of Direction valve:%s\n",state_machine[current_state].direction_valve_status);
}
else if(p1==Falling && hc==not_working)
{
current_state=LOWERING_GEAR;
printf("Current State:%s\n",state_machine[current_state].current_state_indicition);
printf("Light is:%s\n",state_machine[current_state].signal_light);
printf("Status of Direction valve:%s\n",state_machine[current_state].direction_valve_status);
printf("Status of gas pressurized Spring System:%s\n",state_machine[current_state].Gas_Pressurized_Spring_system_status);
}
else if(p1==(Raising))
{
CheckingBeforeLanding();
}
}
void LoweringGear(void)
{
current_state=LOWERING_GEAR;
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&p1,&limit_switch);
if(p1==Falling && limit_switch==open)
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("Current State:%s\n",state_machine[current_state].current_state_indicition);
printf("Light is:%s\n",state_machine[current_state].signal_light);
}
else if(p1==Raising && limit_switch==close)
{
current_state=GEAR_DOWN;
printf("Current State:%s\n",state_machine[current_state].current_state_indicition);
printf("Light is:%s\n",state_machine[current_state].signal_light);
printf("Landing Gear Hydraulic Control:%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
if(limit_switch==close)
{
LoweringGear();
}
}
//Initiate_State_Machine
void initiate_state_machine()
{
current_state==GEAR_DOWN;
printf("The Finite State Machine is Initialized and current the program is in""GearDown State & Light is:%s\n",state_machine[current_state].signal_light);
}

The Finite State Machine is Initialized and current the program is inGearDown State & Light is:Green
Enter the status of pilot's lever and squat switch 0 0
current state:CheckingBeforTakeOff
Light is :Green
Enter the states of pilot's lever and squat switch and hydraulic control:0 0
Current State:Raising Gear
Light is:Red
Status of Direction valve:Up
Enter the status of pilot's lever and limit switch:0 1
Current State:GearUp
Light is:close
Landing Gear Hydraulic Control:Disabled
Enter the status of pilot's lever:1
Current State:CheckingBeforeLanding
Light is:Red
Landing Gear Hydraulic Control:Enabled
Enter the status of pilot's lever and hydraulic mechanism status: 1 0
Current State:LoweringGear
Light is:Green
Status of Direction valve:Down
Enter the status of pilot's lever and limit switch:0 1
Current State:GearDown
Light is:Green
Landing Gear Hydraulic Control:Enabled
Enter the status of pilot's lever and limit switch:

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.