Challenge

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

code//

/*

* project_3.c

*

* Created on: 17-Jul-2023

* Author: GOURAV SANKADIA

* Email:[email protected]

* contact:9933283512

*/

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

void geardown();

void checkbeforelanding();

void raisinggear();

void gearup();

void checkbeforetakeoff();

void lowergear();

void initiate();

typedef enum states

{

gear_down=0,

check_before_takeoff=1,

raising_gear=2,

gear_up=3,

check_before_landing=4,

lower_gear=5

}state_type;

//define switch states for limit switch and squat switch

typedef enum switch_state

{

switch_off=0,

switch_on=1

}switch_s;

//define states for pilots lever system

typedef enum lever

{

falling_lever=0,

rising_lever=1

}lever;

//define states for hydraulic mechanism

typedef enum hydraulic

{

idle_condition,

working_condition

}hydraulic;

static volatile switch_s limit;

static volatile switch_s squat_sw;

static volatile lever pilot_lever;

static volatile hydraulic hyd_mech;

state_type current_state;

//define state table for function of airplane gear system

typedef struct

{

char* indicate_current_state;//indicate curent status of gears

char* light;//green or red light for indication of gear states

char* direction_valve_status;//status of hydraulic valve

char* hydraulic_control;

char* spring_gas_pressure_status[2];

}state_table;

state_table state_machine[6] =

{

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

{"check before take off","green","down","enabled",{"disabled","enabled"}},

{"raising gear","red","up","enabled",{"NULL","NULL"}},

{"Gear up","off","NULL","disabled",{"NULL","NULL"}},

{"check before landing","red","down","enabled",{"NULL","NULL"}},

{"landing gear","green","down","enabled",{"disabled","enabled"}}

};

static volatile switch_s limit;

static volatile switch_s squat_sw;

static volatile lever pilot_lever;

static volatile hydraulic hyd_mech;

state_type current_state;

//defining statetype

//creating function for gear down

void geardown()

{

current_state=gear_down;

printf("state: gear down\n");

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

fflush(stdout);

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

if(pilot_lever== rising_lever&&squat_sw== switch_on)

{

current_state=check_before_takeoff;

printf("state:check before take off");

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

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

}

else

{

geardown();

}

}

//creation fuction to check before take off

void checkbeforetakeoff()

{

current_state=check_before_takeoff;

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

fflush(stdout);

scanf("%d%d%d",&pilot_lever,&squat_sw,&hyd_mech);

// printf("enter status of squat switch:\n");

// fflush(stdout);

// scanf("%d",&squat_sw);

// printf("enter status of hydraulic mechanism:\n");

// fflush(stdout);

// scanf("%d",&hyd_mech);

if(pilot_lever==falling_lever && squat_sw== switch_off)

{

geardown();

}

else if(pilot_lever==rising_lever && squat_sw==switch_on && hyd_mech==working_condition)

{

current_state=raising_gear;

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

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

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

}

else if(pilot_lever==rising_lever && squat_sw==switch_on && hyd_mech==idle_condition)

{

current_state=raising_gear;

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

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

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

printf("status of gas spring system: %s: \n", state_machine[current_state].spring_gas_pressure_status[hyd_mech]);

}

}

//create function for raising gear

void raisinggear()

{

current_state=raising_gear;

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

fflush(stdout);

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

if(pilot_lever==falling_lever && limit ==switch_on)

{

current_state=gear_up;

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

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

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

}

else if(pilot_lever==rising_lever && limit ==switch_off)

{

current_state=gear_up;

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

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

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

}

else

{

raisinggear();

}

}

//create function for gear up

void gearup()

{

{

current_state=gear_up;

printf("enter the status of pilot's lever : \n");

fflush(stdout);

scanf(" %d",&pilot_lever);

if(pilot_lever== falling_lever )

{

current_state=check_before_landing;

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

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

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

}

else

{

gearup();

}

}

}

//create function to check before landing

void checkbeforelanding()

{

current_state= check_before_landing;

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

fflush(stdout);

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

if(pilot_lever==falling_lever&&hyd_mech==working_condition)

{

current_state=lower_gear;

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

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

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

}

else if(pilot_lever==falling_lever && squat_sw==switch_on && hyd_mech==idle_condition)

{

current_state=lower_gear;

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

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

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

printf("status of gas spring system: %s: \n", state_machine[current_state].spring_gas_pressure_status[hyd_mech]);

}

if(pilot_lever==(rising_lever||falling_lever))

{

checkbeforelanding();

}

}

//create function foe lowering gaers

void lowergear()

{

current_state=lower_gear;

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

fflush(stdout);

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

if(pilot_lever==rising_lever && limit ==switch_on)

{

current_state=check_before_takeoff;

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

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

}

else if(pilot_lever==rising_lever && limit ==switch_off)

{

current_state=gear_down;

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

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

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

}

if(limit==switch_off)

{

lowergear();

}

}

//create function to initialise the system

//void initiate()

//{

// current_state=lower_gear;

// printf("system is initiated %s ", state_machine[current_state].light);

//}

//static void(*state_Table[])(void)={geardown,checkbeforetakeoff,raisinggear,gearup,checkbeforelanding,lowergear};

int main()

{

current_state=gear_down;

printf("system is initiated %s ", state_machine[current_state].light);

while(1)

{

switch(current_state)

{

case 0:geardown();

break;

case 1:checkbeforetakeoff();

break;

case 2:raisinggear();

break;

case 3:gearup();

break;

case 4:checkbeforelanding();

break;

case 5:lowergear();

break;

}

}

}

//please find output in the attachment

regards

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.