Challenge

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

Controlling the Retraction and extension of Airplane’s landing gear can be implemented using Finite State Machine (FSM).

////// CODE////

#include<stdio.h>//Preprocessor section
void Geardown();// Global declaration of function
void checkingbeforeTakeoff();
void RaisingGear();
void Gearup();
void CheckingbeforeLanding();
void LoweringGear(void);
void Init_state_Machine();
typedef enum state
{
GEARDOWN,
CHECKINGBEFORETAKEOFF,
RAISINGGEAR,
GEARUP,
CHECKINGBEFORELANDING,
LOWERINGGEAR,
}state_type;// Enumerated data type of state_type
typedef enum switch_case
{
on,
off,
}Switch_state;// Enumerated data type of Switcch_state
typedef enum piolot_lever
{
raising,
falling,
}Piolot_lever;//Enumerated data type of Piolot_lever
typedef enum hydraulic_mechanism
{
running,
pause,
}Hydraulic_mechanism;//Enumerated data type of Hydraulic_mechanism
static volatile Piolot_lever piolot_lever ;// input for changing the state
static volatile Switch_state limit_switch;
static volatile Switch_state squat_switch;
static volatile Hydraulic_mechanism hydraulic_mechanism;
state_type current_state;
// State Table attributes declaration
typedef struct
{
char* current_state_indication;
char* light;
char* hydraulic_lever__landing_gear;
char* direction_valve_status;
int time;
char* Gas_pressure_fluid_flow[2];
}State;
// State Table formation
State state_Machine[6]=
{
{"GEARDOWN","Green","Enable","Down",4,{NULL,NULL}},
{"CHECKINGBEFORETAKEOFF","Green","Enabled","Down",3,{NULL,NULL}},
{"RAISINGGEAR","Red","Enable","Up",0,{"Disable","Enable"}},
{"GEARUP","Off","disable","NULL",0,{NULL,NULL}},
{"CHECKINGBEFORELANDING","Red","Enable","DOWN",4,{NULL,NULL}},
{"LOWERINGGEAR","Green","Enable","DOWN",0,{"Disable","Enable"}}
};
void Geardown(void)
{
current_state=GEARDOWN;
printf("\n Enter the status of piolot's lever and squat switch:");
fflush(stdout);
scanf("%u",&piolot_lever);
scanf("%u",&squat_switch);
if((piolot_lever==raising )&& (squat_switch==on))
{
current_state=CHECKINGBEFORETAKEOFF;
printf("\n current status:%s",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Status of Direction Valve is:%s",state_Machine[current_state].direction_valve_status);
printf("\n Time :%d",state_Machine[current_state].time);
}
}
void checkingbeforeTakeoff(void)
{
current_state=CHECKINGBEFORETAKEOFF;
printf("\n Enter the status of piolot's lever and hydraulic mechanism:");
fflush(stdout);
scanf("%u %u",&piolot_lever,&hydraulic_mechanism);
if((piolot_lever==falling) &&( squat_switch==off))
{
Geardown();
}
else if(piolot_lever==raising&&squat_switch==on&&hydraulic_mechanism==running)
{

current_state=RAISINGGEAR;
printf("\n current status:%s\n ",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Status of Direction Valve is:%s",state_Machine[current_state].direction_valve_status);
printf("\n Hydraulic mechanism is:%s",state_Machine[current_state].hydraulic_lever__landing_gear);
printf("\n Time :%d",state_Machine[current_state].time);
}
else if((piolot_lever==raising)&&(squat_switch==on)&&(hydraulic_mechanism==pause))
{
current_state=RAISINGGEAR;
printf("\n current status:%s",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Status of Direction Valve is:%s",state_Machine[current_state].direction_valve_status);
printf("\n Hydraulic mechanism is:%s",state_Machine[current_state].hydraulic_lever__landing_gear);
printf("\n Gas_pressured and fluid flow:%p",state_Machine[current_state].Gas_pressure_fluid_flow);
printf("\n Time :%d",state_Machine[current_state].time);
}
}
void RaisingGear(void)
{
current_state=RAISINGGEAR;
printf("\n Enter the status of piolot's lever and limit switch :");
fflush(stdout);
scanf("%u %u",&piolot_lever,&limit_switch);
if(piolot_lever==falling&&squat_switch==on)
{
current_state=CHECKINGBEFORELANDING;
printf("\n current status:%s",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Status of Direction Valve is:%s",state_Machine[current_state].direction_valve_status);
printf("\n Hydraulic mechanism is:%s",state_Machine[current_state].hydraulic_lever__landing_gear);
printf("\n Gas_pressured and fluid flow:%p",state_Machine[current_state].Gas_pressure_fluid_flow);
printf("\n Time :%d",state_Machine[current_state].time);
}
else if(piolot_lever==raising&&limit_switch==off)
{
current_state=GEARUP;
printf("\n current status:%s",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Status of Direction Valve is:%s",state_Machine[current_state].direction_valve_status);
printf("\n Hydraulic mechanism is:%s",state_Machine[current_state].hydraulic_lever__landing_gear);
printf("\n Gas_pressured and fluid flow:%p",state_Machine[current_state].Gas_pressure_fluid_flow);
printf("\n Time :%d",state_Machine[current_state].time);
}
else
{
RaisingGear();
}
}
void Gearup(void)
{
current_state=GEARUP;
printf("\n Enter the status of piolot's lever and limit switch :");
fflush(stdout);
scanf("%u",&piolot_lever);
if(piolot_lever==falling)
{
current_state=CHECKINGBEFORELANDING;
printf("\n current status:%s",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Status of Direction Valve is:%s",state_Machine[current_state].direction_valve_status);
printf("\n Gas_pressured and fluid flow:%p",state_Machine[current_state].Gas_pressure_fluid_flow);
printf("\n Time :%d",state_Machine[current_state].time);
}
else
{
Gearup();
}
}
void CheckingbeforeLanding(void)
{
current_state=CHECKINGBEFORELANDING;
printf("\n Enter the status of piolot's lever and hydraulic mechanism:");
fflush(stdout);
scanf("%u %u",&piolot_lever,&hydraulic_mechanism);
if(piolot_lever==falling&&hydraulic_mechanism==running)
{
current_state=LOWERINGGEAR;
printf("\n current status:%s",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Status of Direction Valve is:%s",state_Machine[current_state].direction_valve_status);
printf("\n Hydraulic mechanism is:%s",state_Machine[current_state].hydraulic_lever__landing_gear);
printf("\n Gas_pressured and fluid flow:%p",state_Machine[current_state].Gas_pressure_fluid_flow);
printf("\n Time :%d",state_Machine[current_state].time);
}
else if((piolot_lever==falling)&&(hydraulic_mechanism==pause&&limit_switch==off))
{
current_state=CHECKINGBEFORELANDING;
printf("\n current status:%s",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Status of Direction Valve is:%s",state_Machine[current_state].direction_valve_status);
printf("\n Gas_pressured and fluid flow:%p",state_Machine[current_state].Gas_pressure_fluid_flow);
printf("\n Time :%d",state_Machine[current_state].time);
}
else
{
CheckingbeforeLanding();
}
}
void LoweringGear(void)
{
current_state=LOWERINGGEAR;
printf("\n Enter the status of piolot's lever and limit switch:");
fflush(stdout);
scanf("%u %u",&piolot_lever,&limit_switch);
if(piolot_lever==raising&&squat_switch==off)
{
current_state=CHECKINGBEFORELANDING;
printf("\n current status:%s",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Status of Direction Valve is:%s",state_Machine[current_state].direction_valve_status);
printf("\n Time :%d",state_Machine[current_state].time);
}
if(piolot_lever==raising&&squat_switch==off)
{
current_state=GEARDOWN;
printf("\n current status:%s",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Time :%d",state_Machine[current_state].time);
}
else
{
LoweringGear();
}
}
void Init_state_Machine()
{
current_state=GEARDOWN;
printf("\n current status:%s",state_Machine[current_state].current_state_indication);
printf("\n Light is:%s",state_Machine[current_state].light);
printf("\n Time :%d",state_Machine[current_state].time);
}

static void( *StateTable[])(void)={Geardown,CheckingbeforeLanding,Gearup,CheckingbeforeLanding,LoweringGear};
int main()// Main function start from here
{
Init_state_Machine();
while(1)
{
StateTable[current_state]();
}
}

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.