Challenge

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

Project

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

Goals -

  • Controlling the direction of Valve.
  • Controlling the retraction and extension of Airplane’s landing gear.

State Diagram -

Code -

#include<stdio.h>

void GearDown();
void CheckingBeforeTakeOFF();
void RisingGear();
void GearUp();
void CheckBeforeLanding();
void LoweringGear();

//Accessing function by an array of function
static void(*statetable[])(void)={GearDown, CheckingBeforeTakeOFF, RisingGear,GearUp,CheckBeforeLanding, LoweringGear};
//system state declaration
typedef enum
{
GEAR_DOWN,
CHECKING_BEFORE_TAKEOFF,
RISING_GEAR,
GEAR_UP,
CHECKING_BEFORE_LANDING,
LOWERING_GEAR

}state_Type;

typedef enum
{
Rising,
Falling

}Pilot_Lever;

typedef enum
{
Open,
Close
}Switch_status;

typedef enum
{
Working,
Notworking
}Hydraulic_mechanism;
//Declaring object name
static volatile Switch_status squat_switch; //static type can be use anywhere in program and volatile values are changeable
static volatile Switch_status Limit_switch;
static volatile Pilot_Lever pilot_Lever;
static volatile Hydraulic_mechanism Hydraulic_mech;
state_Type Current_state;


//state table attributes declaration
typedef struct
{
char* current_state_indication;
char* light;
char* direction_valve_status;
char* landing_gear_hydraulic_control;
char* Gas_Presurized_Spring_system_status[2];

}State_Table;

//state table formation
State_Table State_Machine[6]= {{"GearDown","Green","Down","Enabled",{NULL,NULL}},
{"CheckingBeforeTakeOFF","Green","Down","Enabled",{NULL,NULL}},
{"RisingGear","Red","Up","Enabled",{NULL,NULL}},
{"GearUp","Off","NULL","Disabled",{NULL,NULL}},
{"CheckBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}
};

//Accessing function by an array of function


int main()
{

printf("The Finite State Machine Initialization : Current state is GearDown\n");
while(1)
{
statetable[Current_state]();
}
}

void GearDown()
{
Current_state = GEAR_DOWN;
printf("Enter the Pilot's Lever Position and Squat Switch Status:");
fflush(stdout);
scanf("%d %d",&pilot_Lever,&squat_switch);

if((pilot_Lever==Rising) && (squat_switch==Open))
{
Current_state = CHECKING_BEFORE_TAKEOFF ;
printf("Current state : %s\n",State_Machine[Current_state].current_state_indication);
printf("Light status: %s\n",State_Machine[Current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[Current_state].direction_valve_status);
}
else
{
GearDown();
}
}
//CheckBeforeLanding
void CheckingBeforeTakeOFF()
{
Current_state = CHECKING_BEFORE_TAKEOFF;
printf("Enter the Pilot's Lever Position,Squat Switch Status and hydraulic mechanism status:");
fflush(stdout);
scanf("%d %d %d",&pilot_Lever,&squat_switch,&Hydraulic_mech);

if((pilot_Lever==Falling) || (squat_switch==Close))
{
GearDown(); //calling function
}
else if((pilot_Lever==Rising) && (squat_switch==Open) && (Hydraulic_mech==Working) )
{
Current_state = RISING_GEAR;
printf("Current state : %s\n",State_Machine[Current_state].current_state_indication);
printf("Light status: %s\n",State_Machine[Current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[Current_state].direction_valve_status);
}
else if((pilot_Lever==Rising) && (squat_switch==Open) && (Hydraulic_mech==Notworking ))
{
Current_state = RISING_GEAR;
printf("Current state : %s\n",State_Machine[Current_state].current_state_indication);
printf("Light status: %s\n",State_Machine[Current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[Current_state].direction_valve_status);
}
}
//Rising Gear
void RisingGear()
{
Current_state = RISING_GEAR;
printf("Enter the Pilot's Lever Position and Limit Switch Status:");
fflush(stdout);
scanf("%d %d ",&pilot_Lever,&Limit_switch);
if((pilot_Lever==Falling) && (Limit_switch==Open))
{
Current_state = CHECKING_BEFORE_LANDING;
printf("Current state : %s\n",State_Machine[Current_state].current_state_indication);
printf("Light status: %s\n",State_Machine[Current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[Current_state].direction_valve_status);
}
else if((pilot_Lever==Rising) && (Limit_switch==Close))
{
Current_state = GEAR_UP;
printf("Current state : %s\n",State_Machine[Current_state].current_state_indication);
printf("Light status: %s\n",State_Machine[Current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[Current_state].direction_valve_status);

}
else
{
RisingGear();
}
}
//Gear up
void GearUp()
{
Current_state = GEAR_UP;
printf("Enter the Pilot's Lever Position:");
fflush(stdout);
scanf("%d ",&pilot_Lever);
if(pilot_Lever==(Falling))
{
Current_state = CHECKING_BEFORE_LANDING;
printf("Current state : %s\n",State_Machine[Current_state].current_state_indication);
printf("Light status: %s\n",State_Machine[Current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[Current_state].direction_valve_status);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[Current_state].landing_gear_hydraulic_control);
}
else
{
GearUp();
}
}
//Check Before Landing
void CheckBeforeLanding()
{
Current_state = CHECKING_BEFORE_LANDING;
printf("Enter the Pilot's Lever Position and hydraulic mechanism status:");
fflush(stdout);
scanf("%d %d",&pilot_Lever, &Hydraulic_mech);
if((pilot_Lever==Falling) && (Hydraulic_mech==Working) )
{
Current_state = LOWERING_GEAR;
printf("Current state : %s\n",State_Machine[Current_state].current_state_indication);
printf("Light status: %s\n",State_Machine[Current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[Current_state].direction_valve_status);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[Current_state].landing_gear_hydraulic_control);

}
else if((pilot_Lever==Falling) && (Hydraulic_mech==Notworking ))
{
Current_state = LOWERING_GEAR;
printf("Current state : %s\n",State_Machine[Current_state].current_state_indication);
printf("Light status: %s\n",State_Machine[Current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[Current_state].direction_valve_status);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[Current_state].landing_gear_hydraulic_control);

}
else if(pilot_Lever==( Rising || Falling))
{
CheckBeforeLanding();
}
}
// Lowering Gear
void LoweringGear()
{
Current_state = LOWERING_GEAR;
printf("Enter the Pilot's Lever Position, Limit Switch Status:");
fflush(stdout);
scanf("%d %d ",&pilot_Lever,&Limit_switch);
if((pilot_Lever==Rising) && (Limit_switch==Close))
{
Current_state = CHECKING_BEFORE_TAKEOFF;
printf("Current state : %s\n",State_Machine[Current_state].current_state_indication);
printf("Light status: %s\n",State_Machine[Current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[Current_state].direction_valve_status);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[Current_state].landing_gear_hydraulic_control);

}
else if((pilot_Lever==Falling) && (Limit_switch==Open))
{
Current_state = GEAR_DOWN;
printf("Current state : %s\n",State_Machine[Current_state].current_state_indication);
printf("Light status: %s\n",State_Machine[Current_state].light);
printf("Status of Direction valve:%s\n",State_Machine[Current_state].direction_valve_status);
printf("Landing Gear Hydraulic Control:%s\n",State_Machine[Current_state].landing_gear_hydraulic_control);
}
}

.C file-

file:///C:/Users/dipal/Documents/vehical%20desing/Embedded%20C%20essensial/C%20language/project/proje2/proj2.c

Output -

The Finite State Machine Initialization : Current state is GearDown
Enter the Pilot's Lever Position and Squat Switch Status:0 1
Enter the Pilot's Lever Position and Squat Switch Status:1 0
Enter the Pilot's Lever Position and Squat Switch Status:0 0
Current state : CheckingBeforeTakeOFF
Light status: Green
Status of Direction valve:Down
Enter the Pilot's Lever Position,Squat Switch Status and hydraulic mechanism status:0 0 0
Current state : RisingGear
Light status: Red
Status of Direction valve:Up
Enter the Pilot's Lever Position and Limit Switch Status:0 1
0 1
Current state : GearUp
Light status: Off
Status of Direction valve:NULL
Enter the Pilot's Lever Position:Enter the Pilot's Lever Position:1
Current state : CheckBeforeLanding
Light status: Red
Status of Direction valve:Down
Landing Gear Hydraulic Control:Enabled
Enter the Pilot's Lever Position and hydraulic mechanism status:1 0
Current state : LoweringGear
Light status: Green
Status of Direction valve:Down
Landing Gear Hydraulic Control:Enabled
Enter the Pilot's Lever Position, Limit Switch Status:1 0
Current state : CheckingBeforeTakeOFF
Light status: Green
Status of Direction valve:Down
Landing Gear Hydraulic Control:Enabled
Enter the Pilot's Lever Position,Squat Switch Status and hydraulic mechanism status:

Expected Outcomes -

The student will be gaining Knowledge of Finite State Machine algorithm which is used to achieve control over the retraction and extension of Airplane’s landing gear using the switch and gear states of Airplane.

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.