Challenge

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

controlling the retraction and extension of the Airplane’s landing gear can be implemented using Finite State Machine (FSM). FSM is the most efficient algorithm which is a mathematical model of computation.

/*
* main.c
*
* Created on: 12-Dec-2022
* Author: lavanyajarpula715
*/
#include "states.h"
static void(*state_table[])(void)={Gear_Down,Checking_Before_Takeoff,Raising_Gear,Gear_Up,Checking_Before_Landing,Lowering_Gear};

int main()
{
Init_State_Machine();
while(1)
{
state_table[current_state]();

}
}

/*
* intialize_state_of_machine.c
*
* Created on: 12-Dec-2022
* Author: lavanyajarpula715
*/

#include "States.h"
void Init_State_Machine()
{
//system Initialized and its in Init_State_A
current_state = GR_DWN;
printf("\nState Machine is Initialized & Program is in Gear_Down State &Light Status:%s \n",State_Machine[current_state].light_status);
}

/*
* Checking_Before_Landing.c
*
* Created on: 12-Dec-2022
* Author: lavanyajarpula715
*/

#include "states.h"
void Checking_Before_Landing()
{
current_state=CHK_BFR_TKFF;
//printf("\n Current state : %s\n",State_Machine[current_State].indication);
printf("\nEnter the Pilot's Lever Position and Hydraulic Mechanism status:");
fflush(stdout);
scanf("%d%d",&pilot_lever,&hydraulic_mechanism);
if(pilot_lever == DOWN || hydraulic_mechanism == working)
{
current_state=LWRNG_GR;
printf("\nCurrent status : %s\n",State_Machine[current_state].current_state_indication);
printf("\nLight status :%s\n",State_Machine[current_state].light_status);
printf("\nDirection Value status: %s\n\n",State_Machine[current_state].direction_value_status);
}
else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)
{
current_state = LWRNG_GR;
printf("\nCurrent status:%s\n",State_Machine[current_state].current_state_indication);
printf("\nDirection Value Status:%s\n\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);

}
if(pilot_lever == (UP || Raising || Falling))
{
Checking_Before_Landing();

}
}

/*
* Checking_Before_Takeoff.c
*
* Created on: 12-Dec-2022
* Author: lavanyajarpula715
*/


#include "States.h"
void Checking_Before_Takeoff()
{
current_state=CHK_BFR_TKFF;
printf("\nCurrent state:%s\n",State_Machine[current_state].current_state_indication);
printf("\nEnter the Pilot's Lever Position,Squat Switch Status and Hydraulic Machine Status:");
fflush(stdout);
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
printf("\nWait for 3 seconds\n");
if(pilot_lever == Falling || squat_switch == close)

{
Gear_Down();
}

else if(pilot_lever==UP && squat_switch==open && hydraulic_mechanism==working)
{
current_state = RAISING_GR;
printf("\nCurrent status:%s\n",State_Machine[current_state].current_state_indication);
printf("\nLight status:%s\n",State_Machine[current_state].light_status);
printf("\nDirection value status:%s\n",State_Machine[current_state].direction_value_status);

}
else if(pilot_lever==UP && squat_switch==open && hydraulic_mechanism==Malfunctioning)
{
current_state = RAISING_GR;
printf("\nCurrent status:%s\n",State_Machine[current_state].current_state_indication);
printf("\nLight status:%s\n",State_Machine[current_state].light_status);
printf("\nDirection value status:%s\n",State_Machine[current_state].direction_value_status);
printf("\nGas Pressurized spring system status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);


}
}

/*
* Gear_Down.c
*
* Created on: 12-Dec-2022
* Author: lavanyajarpula715
*/


#include "States.h"
void Gear_Down(void)
{
current_state = GR_DWN;
//printf("\n Current state: %s\n",State_Machine[current state].current_state_indication);
printf("\nEnter the Pilot's Lever Position and Squat Switch Status:");
fflush(stdout);
scanf("%d %d", &pilot_lever,&squat_switch);
if(squat_switch == open && pilot_lever == Raising)
{
current_state = CHK_BFR_TKFF;
//printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("Light status:%s\n",State_Machine[current_state].light_status);
}
else
{
Gear_Down();
}
}

/*
* Gear_Up.c
*
* Created on: 12-Dec-2022
* Author: lavanyajarpula715
*/
#include "states.h"
void Gear_Up()
{
current_state = GR_UP;
//printf("\n Current state : %s\n",State_Machine[current_state].current_state_indication);
printf("\nEnter the pilot's Lever status:");
fflush(stdout);
scanf("%d",&pilot_lever);
printf("\nWait for 2secs\n");
if(pilot_lever == Falling)
{
current_state = CHK_BFR_LND;
printf("\nCurrent status: %s\n",State_Machine[current_state].current_state_indication);
printf("\nLight status:%s\n",State_Machine[current_state].light_status);
printf("\nHydraulic Control for Landing Gear status:",State_Machine[current_state].hydraulic_pump_control_status);

}
else
{
Gear_Up();

}
}

/*
* Lowering_Gear.c
*
* Created on: 12-Dec-2022
* Author: lavanyajarpula715
*/

#include "states.h"

void Lowering_Gear()
{
current_state = LWRNG_GR;
printf("\n Current state: %s\n",State_Machine[current_state].current_state_indication);
printf("\nEnter the pilot's Lever Position and limit switch status:");
fflush(stdout);
scanf("%d%d",&pilot_lever,&limit_switch);
if(pilot_lever == Raising)
{
current_state = CHK_BFR_TKFF;
printf("\nCurrent status:%s\n",State_Machine[current_state].current_state_indication);
printf("\nLight status:%s\n",State_Machine[current_state].light_status);

}
if(limit_switch == open)
{
current_state = GR_DWN;
printf("\nCurrent status: %s\n",State_Machine[current_state].current_state_indication);
printf("\nLight status: %s\n",State_Machine[current_state].light_status);
printf("\nHydraulic control for landing Gear status:%s\n\n",State_Machine[current_state].hydraulic_pump_control_status);
}
if(limit_switch == close)
{
Lowering_Gear();
}
}

/*
* Raising_Gear.c
*
* Created on: 12-Dec-2022
* Author: lavanyajarpula715
*/


#include "states.h"

void Raising_Gear()
{
current_state = RAISING_GR;
printf("\n Current state :%s\n",State_Machine[current_state].current_state_indication);
printf("\nEnter the limit switch and pilot's lever status:");
fflush(stdout);
scanf("%d%d",&limit_switch,&pilot_lever);
printf("\nWait for 2secs\n");
if(pilot_lever == Falling && limit_switch == open)
{
current_state = CHK_BFR_LND;
printf("\nCurrent status:%s\n",State_Machine[current_state].current_state_indication);
printf("\nLight status:%s\n",State_Machine[current_state].light_status);
printf("\nHydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

}
else if(limit_switch == close && pilot_lever == UP)
{
current_state = GR_UP;
printf("\nCurrent status:%s\n",State_Machine[current_state].current_state_indication);
printf("\nLight status:%s\n",State_Machine[current_state].light_status);
printf("\nHydraulic Control for landing gear status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
}
else
{
Raising_Gear();

}

/*
* states.h
*
* Created on: 15-Dec-2022
* Author: lavanyajarpula715
*/

#ifndef STATES_H_
#define STATES_H_

#include
/*-----Function----*/
void Init_State_Machine();
void Gear_Down();
void Checking_Before_Takeoff();
void Raising_Gear();
void Gear_Up();
void Checking_Before_Landing();
void Lowering_Gear();

typedef enum State
{
GR_DWN,
CHK_BFR_TKFF,
RAISING_GR,
GR_UP,
CHK_BFR_LND,
LWRNG_GR,
}State_Type;

typedef enum Switch
{
open,
close //Plane is in Ground
}switch_status;


typedef enum Pilot_Lever
{
Raising,
Falling,
UP,
DOWN
}Pilot_lever_status;

typedef enum Hydraulic_Mechanism
{
working,
Malfunctioning
}Hydraulic_Mechanism_Status;
/************input for changing the state*******/

static volatile switch_status squat_switch;
static volatile switch_status limit_switch;
static volatile Pilot_lever_status pilot_lever;
static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;

State_Type current_state;

typedef struct
{
char*current_state_indication;
char*light_status;
char*direction_value_status;
char*hydraulic_pump_control_status;
char*gas_pressurized_spring_status[2];
}State_Table;

static State_Table State_Machine[6] = {{"Gear Down","Green","Down","Enabled",{NULL,NULL}},
{"Checking Before Take Off","Green","Down","Enabled",{NULL,NULL}},
{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"Gear Up","Off","NULL","Disabled",{NULL,NULL}},
{"Checking Before Landing","Red","Down","Enabled",{NULL,NULL}},
{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};

#endif /* STATES_H_ */


}

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.