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 of the Project :

The aim of the Project is to control the retraction and extension of Airplane’s landing gear,with the help of switch and gear by the use of FSM model.

Goal of the Project :

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

Project Code:

#include<stdio.h>
void geardown();
void checkingbeforetakeoff();
void raisinggear();
void gearup();
void checkbeforelanding();
void loweringgear();

typedef enum /*six different states in airplane landing gear so we take as
enum datatype*/
{
GEAR_DOWN,
CHECKING_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECK_BEFORE_LANDING,
LOWERING_GEAR
}State_type;

typedef enum //two states of switch to be controlled while landing
{
ON,
OFF
}Switch;


typedef enum //pilot lever position as enum data type
{
RAISING,
FALLING,
UP,
DOWN
}Pilot_lever;

typedef enum //hydraulic mechanism operation while landing
{
WORKING,
NOT_WORKING
}Hydraulic_mechanism;

static volatile Switch squat,limit; /*squat and limit switch are variable name
taken as static volatile because the value can
change anywhere in the program*/
static volatile Pilot_lever handle;
static volatile Hydraulic_mechanism piston;
State_type current_state; /*current state is a variable that represent the
initial state while landing*/

typedef struct //current state values are taken as character array
{
char* current_state;
char* light;
char* direction_valve;
char* hydraulic_control;

}States;

//array of function pointer with six states to call the function

static void(*state_type[])(void)={geardown,checkingbeforetakeoff,raisinggear,
gearup,checkbeforelanding,loweringgear};

static States state_machine[6]={
{"Gear_down","Green","Down","Enabled"},
{"Checking_before_takeoff", "Green","Down","Enabled"},
{"Raising_Gear","Red","Up","Enabled"},
{"Gear_up","Off","Null","Disabled"},
{"Checking_before_landing","Red","Down","Enabled"},
{"Lowering_Gear","Green","Down","Enabled"}

};// the are the 4 different values of structure

int main()
{
current_state = GEAR_DOWN;
while(1)
{
state_type[current_state](); //calling the current state

}
return 0;
}


void geardown() //definition for geardown
{
current_state = GEAR_DOWN;
printf("\n Enter the pilot_lever and squat switch value");
fflush(stdout);
scanf(" %d%d",&handle,&squat); /*asking user to enter the two values for pilot
lever and switch*/
if(handle==RAISING && squat==ON)
{
current_state = CHECKING_BEFORE_TAKEOFF;
printf("\n %s%s%s%s",state_machine[current_state].current_state,
state_machine[current_state].light,
state_machine[current_state].direction_valve,
state_machine[current_state].hydraulic_control);/*printing
the values of checking before takeoff*/
}
else
geardown();

}

void checkingbeforetakeoff() //definition for checking before takeoff
{
current_state = CHECKING_BEFORE_TAKEOFF;
printf("\n Enter the pilot lever and squat switch value");
fflush(stdout);
scanf("\n %d%d%d",&handle,&squat,&piston);
if(handle==FALLING && squat==ON)
{
current_state= GEAR_DOWN;
printf("\n %s%s%s%s",state_machine[current_state].current_state,
state_machine[current_state].light,
state_machine[current_state].direction_valve,
state_machine[current_state].hydraulic_control);
}
if(handle==UP && piston==WORKING)
{
current_state = RAISING_GEAR;
printf("\n %s%s%s%s",state_machine[current_state].current_state,
state_machine[current_state].light,
state_machine[current_state].direction_valve,
state_machine[current_state].hydraulic_control);
}

else
checkingbeforetakeoff();

}

void raisinggear() //definition for raising gear
{
current_state = RAISING_GEAR;
printf("\n Enter the pilot lever and limit switch value");
fflush(stdout);
scanf("\n %d%d",&handle,&limit);
if(handle==FALLING)
{
current_state= CHECK_BEFORE_LANDING;
printf("\n %s%s%s%s",state_machine[current_state].current_state,
state_machine[current_state].light,
state_machine[current_state].direction_valve,
state_machine[current_state].hydraulic_control);
}
if(limit==ON)
{
current_state = GEAR_UP;
printf("\n %s%s%s%s",state_machine[current_state].current_state,
state_machine[current_state].light,
state_machine[current_state].direction_valve,
state_machine[current_state].hydraulic_control);
}
}

void gearup() //definition for gear up
{
current_state= GEAR_UP;
printf("\n Enter the pilot lever value");
fflush(stdout);
scanf("\n %d",&handle);
if(handle==FALLING)
{
current_state = CHECK_BEFORE_LANDING;
}
else
gearup();

}


void checkbeforelanding() //definition for check before landing
{
current_state = CHECK_BEFORE_LANDING;
printf("\n Enter the pilot lever and hydraulic value");
fflush(stdout);
scanf("\n %d%d",&handle,&piston);
if(handle==DOWN || piston == NOT_WORKING)
current_state = LOWERING_GEAR;
else
checkbeforelanding();
}
void loweringgear() //definition for lowering gear
{
current_state=LOWERING_GEAR;
printf("\n Enter the limit switch and pilot lever value");
fflush(stdout);
scanf("\n %d%d",&limit,&handle);
if(limit==ON)
current_state= GEAR_DOWN;
if(handle==RAISING)
current_state= CHECKING_BEFORE_TAKEOFF;
else
loweringgear();
}

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.