Challenge

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

FINITE STATE MACHINE:

Nowadays many applications either small or complex use the finite state machine (FSM).A finite state machine in C is one of the popular design patterns for the embedded system.A finite state machine makes the development easy and smooth.There are a lot of devices which use event base states, like coffee machine, vending machine, POS devices, door lock system etc.

A finite state machine can have multiple states.It can switch from one state to another state on the basis of internal or extrenal input.This input could be timer expiry signal, hardware or software interrupt etc., in the finite state machine the procedure to change one state to another state is called transition.

For example, I am considering an ATM machine and creating its sample state machine in C . The state of the ATM machine could be changed through the coming events.I have mentioned below the sample states of the ATM machine.

The sample states of the ATM machine are:

  • idle state
  • card inserted state
  • pin entered state
  • option selected state
  • amount eneterd state

Initially, the ATM machine would be in the idle state.When a user inserts the card then it change thier state and processes the card after the card processing, ATM again changes thier state and ask the user to enter the pin number.When the user entered the PIN , then its asks for choice and after that change the state and ask to enter the amount and dispatch the entered amount .

This project explains:

In this project , finite state machine is used to manage the retraction and extension of an airplane's landing gear (FSM).The most efficient algorithm is the FSM , which is a mathematical processing model.

Actually an airplane has 3 gears for landing:Nose gear, left gear,Right gear.There is an electrically powered hydraullic pump that applies pressure to the gears to bring it down to pull it up.

There is a limit switch on each leg of the gear.One extra squat switch is installed in the nose gear to assess whether the plane is on the ground or not.

Program:

#idndef FSM_H_

#define FSM_H_

#include<stdio.h>

void initiate_state_machine();

void geardown();

void checkingbeforetakeoff();

void raisinggear();

void gearup();

void checkbeforelanding();

void loweringgear();

typedef enum state

{

GEAR_DOWN,

CHECKING_BEFORE_TAKEOFF,

RAISING_GEAR,

GEAR_UP,

CHECK_BEFORE_LANDING,

LOWERING_GEAR,

}state_type;

typedef enum switch

{

on,

off //plane is on ground//

}switch_status;

typedef enum pilot_lever

{

raising,

falling

}pilot_lever;

typedef enum hydraulic_mechanism

{

working, not working

}hydraullic_mechanism;

static volatile switch_status squat_switch;

static volatile switch_status limit_switch;

static volatile Pilot_lever pilot_lever;

static volatile Hydraulic_mechanism hydraulic_mechanism;

state_type current_state;

typedef struct

{

char* current_state_indication;

char* light;

char* direction_valve_status;

char* gas_pressurized_spring_system_status[2];

char* landing_gear_hydraulic_control;

}state_table;

static state_table;

state_machine[6]=

{

{"geardown","green","down","enabled",{NULL,NULL}},

{"checkingbeforetakeoff","green","down","enabled",{NULL,NULL}},

{"raisinggear","red","up","enabled",{"disabled,"enabled"}}

{"gearup","off","null","disabled",{NULL,NULL}},

{"checkingbeforelanding","red","down","enabled",{NULL,NULL}},

{"loweringgear","green","down""enabled",{disabled","enabled"}}

};

#endif //FSM_H_//

main program:

#include<stdio.h>

#include<conio.h>

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

int main()

{initiate_state_machine();

while(1)

{

statetable[current_state]();

}

}

//GEAR DOWN//

void geardown(void)

{

current_state=GEAR_DOWN;

printf("enter the status of pilot's lever and squat switch:");

fflush(stdout);

scanf("%d%d,&pilot_lever,&squat_switch);

if(pilot_lever==raising &&sqaut_switch==on)

{

current_state=CHECK_BEFORE_TAKEOFF;

printf("current state:%s\n",state_machine[current_state].current_state_indication);

printf("light is:%s\n",state_machine[current_state].light;

}

else

{

geardown();

}

}

}

//checkingbeforetakeoff//

void checkingbeforetakeoff(void)

{

current_state=CHECKING_BEFORE_TAKEOFF;

printf("enter the status of pilot's lever and squat switch and hydraulic mechanism:');

fflush(stdout);

scanf("%d%d",&pilot_lever,&squat_switch,&hydraulic_mechanism);

if(pilot_lever==falling && squat_switch==off)

{

geardown();

}

elseif(pilot_lever ==raising &&squat_Switch ==on &&hydraulic_mechanism==working)

{

current_state=RAISING_GEAR;

printf("current state:%s\n",state_machine[current_state].current_state_indication);

printf(light is:%s\n",state_machine[current_state].light);

printf("status of direction valve :%s\n",state_machine[current_state].direction_valve_status);

}

else if(pilot_lever==raising && squat_switch==on && hydraulic_mechanism==not working)

{

current_state=RAISING_GEAR;

printf("current state:%s\n',state_machine[current.state].current_state_indication);

printf("light is :%s\n",state_machine[current_state].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);

}

}

//RAISING GEAR//

void raisinggear(void)

{

current_state=RAISING_GEAR;

printf("enter the status of pilot's lever and limit switch:");

fflush(stdout)

scanf("%d%d",&pilot_lever,&limit_switch==on)

{

current_state=CHECK_BEFORE_LANDING;

printf("current state :%s\n",state_machine[current_state].current_state_indication);

printf("light is :%s\n",state_machine[current_state].light);

printf("landing gear hydraulic control:%s\n",state_machine[current_state-.landing_gear_hydraulic_control);

}

else if(pilot_lever==raising && limit_switch==off)

{

current_state=GEAR_UP;

printf("current state is :%s\n",state_machine9current_state].current_state_indication);

printf("light is:%s\n",state_machine[current_state].light);

printf("landing gear hydraulic control:%s\n",state_machine[current_state].landing_gear_hydraulic_contro;);

}

else

{

raisinggear();

}

}

//GEAR UP//

void gearup(void)

{

current_state=GEAR_UP;

printf("enter the status of the pilot lever:");

fflush(Stdout);

scanf("%d",&pilot_lever);

if(pilot_fever==falling)

{

current_state=CHECK_BEFORE_LANDING;

printf("current state:%s\n",state_machine[current_state].current_state_indication);

printf("light is :%s\n", state_machine[current_state].light);

printf("landing gear hydraulic control :%s\n",state_machine[current_state].landing_gear_hydraulic_control);

}

else

{

hearup();

}

}

//CHECK BEFORE LANDING//

void checkbeforelanding(void)

{

current_state=CHECK_BEFORE_LANDING;

printf("enter the status of pilot's lever and hydraulic mechanism status:");

fflush(stdout);

scanf("%d%d",&pilot_lever,&hydralic_mechanism);

if(pilot_lever==falling && hydraulic_mechanism==working)

{

current_state=LOWERING_GEAR;

printf("current state :%s\n",state_machine[current_state].current_state_indication);

printf("light is :%s\n",state_machine[current_state].light);

printf("status of direction valve :%s\n",state_machine[current_state].direction_valve_status);

}

state_machine[current_state].direction_valve_status);

}

else if(pilot_lever==falling && squat_switch==on && hydraulic_mechanism==not working)

{

current_state=LOWERING_GEAR;

printf("current state:%s\n",state_machine[current_state].current_state_indication");

printf("light is :%s\n",state_machine[current_state].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);

}

if(pilot_lever==(raising || falling)

{

checkbeforelanding();

}

}

//LOWERING GEAR//

void loweringgear(void)

{

current_state=LOWERING_GEAR;

printf("enter the status of pilot's lever and limit switch:");

fflush(stdout);

scanf("%d%d",&pilot_lever,&limit_switch);

if(pilot_lever==raising && limit_switch==on)

{

current_state=CHECK_BEFORE_TAKEOFF;

printf("current state:%s\n",state_machine[current_state].current_state_indication);

print("light is :%s\n, state_machine[current_state].light);

}

if(pilot_lever==raising && limit_switch==off)

{

current_state=GEAR_DOWN;

printf("current state:%s\n",state_machine[current_state].current_state_indication);

printf("light is:%s\n",state_machine[current_state].light);

printf("landing gear hydraulic control :%s\n",state_machine[current_state].landing_gear_hydraulic_control);

}

if(limit_switch==off)

{

loweringgear();

}

}

void initiate_state_machine()

{

current_state=GEAR_DOWN;

printf("the finite state machine is initialized and the current the program is in""geardown state &light is :%s\n",state_machine[current_state].light);

}

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.