Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
AIM: Implement the Code for controlling the retraction and
extension of Airplane’s landing gear.
Description of Project:
Actually an airplane has 3 gears for landing :
• Nose Gear
• Left Gear
• Right Gear
There is a hydraulic pump which is exerting pressure to the
gears to bring it down or pull it up and that pump is
electrically driven.
Limit switches:
Every leg of the gear has one limit switch.Nose gear has
one extra Squat Switch to determine whether the airplane
is in ground or not.



Consider this cases:
• There is a possibility that the plane is about to take off and
an emergency comes where pilot has to abort the take off.
• When taking off,to ensure that its right time to raising the
gear,check for at least 4 seconds that squat switch is open.
• When the airplane is parked at the bay and nose gear is
down,then the nose gear is always experiencing a pressure
on it due to airplane weight,weight of luggage and weight
of passengers boarding on the airplane.Hydraulic
mechanism is monitoring the pressure exerted on the
nose gear and to neutralize that pressure its applying a
pressure on the opposite direction.
• Hydraulic Control can detect the rising edge and falling
edge of pilot’s lever.
• In case of Hydraulic system failure,there are two gas
pressurized springs by which gears can be extended.
• The case of failure of Squat Switch is ignored.


Main Code:
/* to go from gear down to checking state we need to press 1
to go from checking state to gear down we need to press 0
to go from checking state to rising gear we need to press 2
to go from rising gear to gear up we need to give limit switch 1
to go from rising state to checking before landing we need to give limit_switch=0
to go from gear_up to checking state we need to give pilot_lever=3
to go from checking state to lowering gear we need to give pilot_lever=4
from lowering gear to checking before landing pilot lever=1
from lowering gear to gear up limit switch =0 */
#include<stdio.h> //header file (standard input & Output)
#include<stdlib.h> //header file
#include <unistd.h> //used for time delay
void m (); //function
typedef enum
{
gear_down,
checking_before_take_off,
raising_gear,
ear_up,
checking_before_landing,
lowering_gear
}
gear; //Enumerated data type
typedef enum
{
off,
green,
red
} light; //Enumerated data type
typedef enum
{
valve_up,
valve_down
} valve; //Enumerated data type
typedef struct
{
gear output;
gear next_state[6];
int time;
light l[3];
char *a[10];
} State; //Enumerated data type
State state_[6] = {
{gear_down, {gear_down, checking_before_take_off}, 3, {off, green, red},
{"gear down", "checking before take off", "airplane is on ground", "green",
"red"}},
{checking_before_take_off, {gear_down, raising_gear}, 3, {off, green, red},
{"gear down", "checking before take off", "raising_gear", "red"}},
{raising_gear, {gear_up, checking_before_landing}, 3, {off, green, red},
{"checking before take off", "gear up", "off"}},
{gear_up, {checking_before_landing}, 3, {off, green, red},
{"checking before landing", "gear up", "red"}},
{checking_before_landing, {lowering_gear}, 3, {off, green, red},
{"checking before landing", "lowering_gear", "gear up", "red"}},
{lowering_gear, {gear_up, checking_before_take_off}, 3, {off, green, red},
{"gear up", "checking before take off", "lowering_gear", "red"}},
};
//FSM (finite state machine)
int squat_switch, current_state, pilot_lever, pilot_lever_up, limit_switch,
pilot_lever_falling, pilot_lever_down;
//global variable
int main ()
{
while (1)
{
printf ("squat switch=");
scanf ("%d", &squat_switch);
if (0 == squat_switch) //plane is on ground squat switch off
{
printf ("\nlight=(%d)%s\n", state_[0].l[1], state_[0].a[3]);
printf ("\n%s", state_[0].a[0]);
printf ("\n%s\n", state_[0].a[2]);
current_state = state_[0].next_state[0];
continue;
} //condition to be in ground till squat switch is not closed
else if (1 == squat_switch) //plane is taking off or landing or airborn
{
printf("\npilot lever for checking before take off or stay at ground=");
scanf ("%d", &pilot_lever);
if (1 == pilot_lever && 1 == squat_switch) //condition to change state from down to rising
{
{
printf ("%s\n", state_[0].a[1]);
printf ("\nlight=(%d)%s\n", state_[0].l[2], state_[0].a[4]);
sleep(3); //time delay
printf ("delay=%d\n", state_[0].time);
current_state = checking_before_take_off;
} //state has been changed
printf("pilot lever condtion for rising gear or gear down status =");
scanf ("%d", &pilot_lever);
if (2 == pilot_lever && 1 == squat_switch) //condition to change state 2 for lever up
{
printf ("\n%s", state_[1].a[2]);
printf ("\nlight=(%d)%s\n", state_[1].l[2], state_[1].a[3]);
current_state = raising_gear;
printf("\nlimit_switch to go at gear up or gear down before landing=");
scanf ("%d", &limit_switch);
if (1 == limit_switch) //condition to change state from rising to gear up
{
{
printf ("\n%s", state_[2].a[1]);
printf ("\nlight=(%d)%s\n", state_[2].l[0],
state_[2].a[2]);
printf ("control for landing gear disabled");
current_state = gear_up;
//3 for falling
}
printf ("\npilot lever before landing condition=");
scanf ("%d", &pilot_lever);
if (pilot_lever == 3) //condition to change state from gear up to check before landing
{
printf ("\n%s", state_[3].a[0]);
printf ("\nlight=(%d)%s\n", state_[3].l[2],
state_[3].a[2]);
current_state = checking_before_landing;
// 4 for down
}
}
else if (1 == limit_switch || 0 == limit_switch) //condition to change state from rising to check before landing
{
printf ("\n%s", state_[3].a[0]);
printf ("\nlight=(%d)%s\n", state_[3].l[1],
state_[3].a[3]);
current_state = checking_before_landing;
// 4 for down
}
printf ("\npilot_lever before lowering gear condition="); //4 for landing
scanf ("%d", &pilot_lever);
if (4 == pilot_lever) //condition to change state from check before landing to lowering gear
{
printf ("\n%s\n", state_[4].a[1]);
printf ("\nlight=(%d)%s\n", state_[4].l[1],
state_[4].a[3]);
current_state = lowering_gear;
//0 for open
}
printf ("limit switch ");
scanf ("%d", &limit_switch);
printf ("pilot_lever");
scanf ("%d", &pilot_lever);
if (0 == limit_switch || 0==pilot_lever) //condition to change state from lowering gear to gear down state
{
printf ("\nlight=(%d)%s\n", state_[0].l[1],
state_[0].a[3]);
printf ("\n%s", state_[0].a[0]);
printf ("\n%s\n", state_[0].a[2]);
current_state = state_[0].next_state[0];
continue;
}
if (1 == pilot_lever || 1 == limit_switch)
{
m (); //called function
continue;
}
}
}
}
}
}
void
m () //called function
{
while(1)
{
squat_switch = 1;
printf ("pilot lever condtion for rising gear or gear down status =");
scanf ("%d", &pilot_lever);
if (2 == pilot_lever && 1 == squat_switch) //condition to change state 2 for lever up
{
printf ("\nlight=(%d)%s\n", state_[1].l[2], state_[1].a[3]);
printf ("\n%s", state_[1].a[2]);
current_state = raising_gear;
printf ("\nlimit_switch to go at gear up or gear down before landing=");
scanf ("%d", &limit_switch);
if (1 == limit_switch) //condition to change state from rising to gear up
{
{
printf ("\n%s", state_[2].a[1]);
printf ("\nlight=(%d)%s\n", state_[2].l[1], state_[2].a[3]);
printf ("control for landing gear disabled");
current_state = gear_up;
printf ("control for for landing gear are disabled");;
//3 for falling
}
printf ("\npilot lever checking before landing condition=");
scanf ("%d", &pilot_lever);
if (pilot_lever == 3) //condition to change state from gear upm to check before landing
{
printf ("\n%s", state_[3].a[0]);
printf ("\nlight=(%d)%s\n", state_[3].l[1], state_[3].a[3]);
current_state = checking_before_landing;
// 4 for down
}
}
else if (1 == limit_switch || 0 == limit_switch) //condition to change state from rising to check before landing
{
printf ("\n%s", state_[3].a[0]);
printf ("\nlight=(%d)%s\n", state_[3].l[1], state_[3].a[3]);
current_state = checking_before_landing;
// 4 for down
}
printf ("\npilot_lever before lowering gear condition="); //4 for landing
scanf ("%d", &pilot_lever);
if (4 == pilot_lever) //condition to change state from check before landing to lowering gear
{
printf ("\n%s", state_[4].a[1]);
printf ("\nlight=(%d)%s\n", state_[4].l[1], state_[4].a[3]);
current_state = lowering_gear;
//0 for open
}
printf ("limit switch ");
scanf ("%d", &limit_switch);
printf("pilot lever");
scanf("%d",&pilot_lever);
if (0 == limit_switch || 0== pilot_lever) //condition to change state from lowering gear to gear down state
{
printf ("\nlight=(%d)%s\n", state_[0].l[1], state_[0].a[3]);
printf ("\n%s", state_[0].a[0]);
printf ("\n%s\n", state_[0].a[2]);
current_state = state_[0].next_state[0];
break;
}
}
}
}
OUTPUT 1
squat switch=0
light=(1)green
gear down
airplane is on ground

OUTPUT 2
squat switch=1
pilot lever for checking before take off or stay at ground=1
checking before take off
light=(2)red
delay=3
pilot lever condtion for rising gear or gear down status =2
raising_gear
light=(2)red
limit_switch to go at gear up or gear down before landing=1
gear up
light=(0)off
control for landing gear disabled
pilot lever before landing condition=3
checking before landing
light=(2)red
pilot_lever before lowering gear condition=4
lowering_gear
light=(1)red
limit switch 1
pilot_lever 0
light=(1)green
gear down
airplane is on ground

