Challenge

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

/*Project demonstrating the controlling of retraction and extraction of airplane's landing gear by using FSM design technique.

Note: along with the normal working cycle, special cases like aborting take off and aborting landing in some emergency conditions is also considered. */

#include<stdio.h>

void initialisation(void);
void GEAR_DOWN(void);
void CHECK_BEFORE_TAKEOFF(void);
void RAISING_GEAR(void);
void GEAR_UP(void);
void CHECK_BEFORE_LAND(void);
void LOWERING_GEAR(void);

typedef enum
{
Gear_down,
Check_before_takeoff,
Raising_gear,
Gear_up,
Checking_before_landing,
Lowering_gear
}states;

typedef enum
{
opened,
closed
}switches;

typedef enum
{
down,
raising,
up,
falling
}lever;

typedef enum
{
enabled,
disabled
}hydraulic;

typedef enum
{
Green,
Red,
Off
}lights;

typedef struct
{
char * current_status;
char * light_status[3];
char * direction_valve;
char * hydraulic_control;
}airplane;


airplane airindia[6]={
{"Gear_down",{"Green","Red","Off"},"Down","Enabled"},
{"Checking_before_takeoff",{"Green","Red","Off"},"Down","Enabled"},
{"Raising_Gear",{"Green","Red","Off"},"Up","Enabled"},
{"Gear_up",{"Green","Red","Off"},"Up","Disabled"},
{"Checking_before_landing",{"Green","Red","Off"},"Up","Enabled"},
{"Lowering_Gear",{"Green","Red","Off"},"Down","Enabled"},
};

static volatile states current_state;
switches limit_switch,squat_switch;
lever pilot_lever;
hydraulic control_position;
lights lighting_position;

//function pointer array to store function addresses

static void(*function_pointer[])(void)={GEAR_DOWN,CHECK_BEFORE_TAKEOFF,RAISING_GEAR,GEAR_UP,CHECK_BEFORE_LAND,LOWERING_GEAR};

int main()
{
initialisation();
while(1)
{
function_pointer[current_state]();

//calling functions as choosen by the algorithm
}
return 0;
}

void initialisation()
{

//loading initial conditions
current_state=Gear_down;
lighting_position=Green;
printf("\nAIR INDIA Airplane AI 452 is out of parking bay and ready to start it's air trip ");
}

void GEAR_DOWN()
{
//current_state=Gear_down;
printf("\nAI 452 is in landed position and it is at runway");
printf("\nAI 452 current_status is %s, \nlight_status is %s,",airindia[current_state].current_status,airindia[current_state].light_status[lighting_position]);
printf("\ndirection_valve is %s, \nhydraulic_control is %s",airindia[current_state].direction_valve,airindia[current_state].hydraulic_control);

printf("\n\nPlease enter pilot lever status and squat switch status as per below mentioned style");
printf("\n\nfor pilot lever down- 0,rising- 1,up- 2,falling- 3 \nsquat switch opened- 0, closed- 1 :\t ");
fflush(stdout);
scanf("%u %u",&pilot_lever,&squat_switch);
if(pilot_lever==1 && squat_switch==0)
{
current_state=Check_before_takeoff;
lighting_position=Green;
}

}

void CHECK_BEFORE_TAKEOFF()
{
//current_state=Checking_before_takeoff;
printf("\nAI 452 current_status is %s, \nlight_status is %s,",airindia[current_state].current_status,airindia[current_state].light_status[lighting_position]);
printf("\ndirection_valve is %s, \nhydraulic_control is %s",airindia[current_state].direction_valve,airindia[current_state].hydraulic_control);

printf("\n\nPlease enter pilot lever status and squat switch status as per below mentioned style");
printf("\n\nfor pilot lever down- 0,rising- 1,up- 2,falling- 3 \nsquat switch opened- 0, closed- 1 :\t ");
fflush(stdout);
scanf("%u %u",&pilot_lever,&squat_switch);
if(pilot_lever==2 && squat_switch==0)
{
current_state=Raising_gear;
lighting_position=Red;
}

else if(pilot_lever==3 || squat_switch==1)
{
current_state=Gear_down;
lighting_position=Red;
printf("\nAs Squat switch is closed, so take off got canceled and AIR INDIA technical ground staff getting it ready for journey");
}

}

void RAISING_GEAR()
{
//current_state=Raising_Gear;
printf("\nAI 452 current_status is %s, \nlight_status is %s,",airindia[current_state].current_status,airindia[current_state].light_status[lighting_position]);
printf("\ndirection_valve is %s, \nhydraulic_control is %s",airindia[current_state].direction_valve,airindia[current_state].hydraulic_control);

printf("\n\nPlease enter pilot lever status and limit switch status as per below mentioned style");
printf("\n\nfor pilot lever down- 0,rising- 1,up- 2,falling- 3 \nlimit switch opened- 0, closed- 1 :\t ");
fflush(stdout);
scanf("%u %u",&pilot_lever,&limit_switch);
if(pilot_lever==2 && limit_switch==1)
{
current_state=Gear_up;
lighting_position=Off;
}

else if(pilot_lever==3)
{
current_state=Checking_before_landing;
lighting_position=Red;
printf("\nDue to some emergency reason, AI 452 is aborting the journey and preparing to land");
}

}

void GEAR_UP()
{
//current_state=Gear_up;
printf("\n\nAI 452 is airborne");
printf("\nAI 452 current_status is %s, \nlight_status is %s,",airindia[current_state].current_status,airindia[current_state].light_status[lighting_position]);
printf("\ndirection_valve is %s, \nhydraulic_control is %s",airindia[current_state].direction_valve,airindia[current_state].hydraulic_control);

printf("\n\nPlease enter pilot lever status as per below mentioned style");
printf("\nfor pilot lever down- 0,rising- 1,up- 2,falling- 3 :\t ");
fflush(stdout);
scanf("%u",&pilot_lever);
if(pilot_lever==3)
{
current_state=Checking_before_landing;
lighting_position=Red;
}

}

void CHECK_BEFORE_LAND()
{
//current_state=Checking_before_landing;
printf("\n\nAI 452 current_status is %s, \nlight_status is %s,",airindia[current_state].current_status,airindia[current_state].light_status[lighting_position]);
printf("\ndirection_valve is %s, \nhydraulic_control is %s",airindia[current_state].direction_valve,airindia[current_state].hydraulic_control);

printf("\n\nPlease enter pilot lever status as per below mentioned style");
printf("\nfor pilot lever down- 0,rising- 1,up- 2,falling- 3 :\t ");
fflush(stdout);
scanf("%u",&pilot_lever);
if(pilot_lever==0)
{
current_state=Lowering_gear;
lighting_position=Red;
}

}

void LOWERING_GEAR()
{
//current_state=Lowering_gear;
printf("\n\nAI 452 current_status is %s, \nlight_status is %s",airindia[current_state].current_status,airindia[current_state].light_status[lighting_position]);
printf("\ndirection_valve is %s, \nhydraulic_control is %s",airindia[current_state].direction_valve,airindia[current_state].hydraulic_control);

printf("\n\nPlease enter pilot lever status and limit switch status as per below mentioned style");
printf("\n\nfor pilot lever down- 0,rising- 1,up- 2,falling- 3 \nlimit switch opened- 0, closed- 1 :\t ");
fflush(stdout);
scanf("%u %u",&pilot_lever,&limit_switch);
if(limit_switch==0 && pilot_lever==0)
{

current_state=Gear_down;
lighting_position=Green;
}

else if(pilot_lever==1)
{
current_state=Check_before_takeoff;
lighting_position=Red;
printf("\nDue to some issue at runway, AI 452 is aborting the landing, and going for take off");
}

}

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.