Challenge

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

Project 2:

Implement the code for controlling the retraction and extensioin of Airplane's Landing gear

Introduction :

An airplne has three gears for landing:

  • Nose Gear
  • Left Gear
  • Right Gear

The hydraulic pump are used for 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.

Squat switch: only nose gear have squat switch to determine whether the airplan is in ground or not.

Switch state State of Gears
Limit Switch CLOSED Gear is UP
Limit Switch OPENED Gear is DOWN
Switch State State of Airplane
Squat Switch CLOSED Airplane is grounded and gears are locked
Squat Switch OPENED Airplane is taking off/ landing/ airborne

A direction valve is controlled by software to allow the hydraulic pressure to either raise or lower the landing gear

Status of Direction Valve States of landing gear
Direction valve = Down (Gear Down) (Parked at bay or Landed)
Direction valve = Up Raising Gear (Taking Off)
Control of hydraulic pump for the landing gear part is disabled Gear up (Airborne)
Direction valve = down Lowering Gear (Landing)

Input for the direction valve :

Pilot's Lever State Direction Valve State
Lever UP Direction valve = Up
Lever Down Direction valve = Down
Pilot's Lever State Light Status
Lever Rising Edge Red
Lever Falling Edge Red

Every gear has one light. According to the state of the gear, color of the light is changing.

Landing Gear State Light Status

Gear is up

OFF
Gear is down Green
Gear in transit Red

By incorperating all these constraints we can come to result as shown below.

Program:

main.c

#include                   //Pre-Processor
#include "States.h"                 //headerfile been called fro the program execution

static void (*state_table[])(void) = {Gear_Down, Checking_Before_Takeoff, Raising_Gear,   //Different functions are described here.
         Gear_Up, Checking_Before_Landing, Lowering_Gear};
int main()                         //Main function
{
 Init_State_Machine();             //Function calling
 while(1)                          //While loop to execute different functions
 {
  state_table[current_state]();
 }
}

states.h:

void Init_State_Machine();          /*Function declaration */
void Gear_Down();
void Checking_Before_Takeoff();
void Raising_Gear();
void Gear_Up();
void Checking_Before_Landing();
void Lowering_Gear();

typedef enum State                  //Typedef enum is called to change the name for simplicity
{

 GR_DWN,                             //Enum states are declared.
 CHK_BFR_TKFF,
 RSING_GR,
 GR_UP,
 CHK_BFR_LND,
 LWRNG_GR

}State_Type;

typedef enum Switch                  //Enum switch (squat+limit) status are declared
{

 Open,
 Close//Plane is in ground

}Switch_Status;

typedef enum Pilot_Lever            //typedef enum pilot lever status are ben declared.
{

 Rising,
 Falling,
 UP,
 DOWN

}Pilot_Lever_Status;                 //typedef enum can be called as Pilot_Lever_Status

typedef enum Hydraulic_Mechanism     //Typedef enum hydraulic mechanism status are declared here
{

 Working,
 Malfunctioning

}Hydraulic_Mechanism_Status;

/* -----input for changing the State----- */
static volatile Switch_Status squat_switch;                       //The switch status is provided with squat switch name.
static volatile Switch_Status limit_switch;                       //The switcch_Status can be called as limit_switch
static volatile Pilot_Lever_Status pilot_lever;                   //Pilot_Lever_Status as pilot_lever
static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;   //Hydraulic_Mechanism_Status as hydraulic_mechanism


State_Type current_state;                                         //State_Type renamed to current_state.

typedef struct                                                    //Structure declaration
{
 char* current_state_indication;                                  /* Declaration of different constraints as char* data-type.
 char* light_status;
 char* direction_valve_status;
 char* hydraulic_pump_control_status;
 char* gas_pressurized_spring_status[2];
}State_Table;                                                      //assessed using State_Table.

static State_Table State_Machine[6] = {                            //Different options for different functions are mentioned in static_Machine[6
  {"GearDown","Green","Down","Enabled",0,0},
  {"Checking Before Take Off","Green","Down","Enabled",0,0},
  {"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
  {"Gear Up","Off","Null","Disabled",0,0},
  {"Checking Before Landing","Red","Down","Enabled",0,0},
  {"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};


init_state_machine.c:

#include "States.h"                                                                                //user defined header files

void Init_State_Machine()                                                                          //Function definiton
{
	 current_state = GR_DWN;                                                                       //System Initialized and its in State_A
    printf("\nState Machine is initialized & Program is in Gear_Down State & Light Status : %s\n"  //To print the output of init function
   ,State_Machine[current_state].light_status);
}

Gear_Up.c

#include "States.h"
#include

void Gear_Up()                       //Function definition
{
 current_state = GR_UP;              //changing the current state to gear up.
  //printf("Current State : %s\n",State_Machine[current_state].current_state_indication);
  printf("\nEnter the Pilot's Lever Position:");  //To tell the user to e nter the position
  fflush(stdout);                    //Clearing the cache files
  scanf("%d",&pilot_lever);          //To scan the values
  if(pilot_lever == Falling)         //To check the condition
  {
   current_state = CHK_BFR_LND;      //The  current status is changed to checking before landing
   printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);   //To print the values
   printf("Light Status:%s\n",State_Machine[current_state].light_status);
   printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
  }
  else
  {
   Gear_Up();                       //To call the function again
  }
}

Lowering Gear.c :

#include "States.h"            
#include               
void Lowering_Gear()             //Function definition
{
 current_state = LWRNG_GR;       //Current state is changed to lowering the gear.
 //printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
 printf("\nEnter the Limit Switch Status,Pilots Leaver Status::");   //To tell user to enter the input
 fflush(stdout);                                                     //For clearing cache
 scanf("%d %d",&limit_switch,&pilot_lever);                          //To scan the value from console
 if( limit_switch == Close && pilot_lever == Rising )                //To check the condition
  {
  current_state = CHK_BFR_TKFF;                                      //current state changed to check before takeoff if the condition is satisfied
  printf("\nCurrent State : %s\n",State_Machine[current_state].current_s tate_indication);  //To print the output
  printf("Light Status:%s\n",State_Machine[current_state].light_status);
  }
 if(limit_switch == Open && pilot_lever == DOWN)                     //To check the condition with user input data
 {
  current_state = GR_DWN;                                            //Changing the state to gear down
  printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);   //To print he output
  printf("Light Status:%s\n",State_Machine[current_state].light_status);
  printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
 }

 else
 {
  Lowering_Gear();                                                  //it no condition is satisfied, then function is called again
 }
}

Gear_down.c :

#include "States.h"
#include

void Gear_Down(void)                                    //Functioin definition
{
 current_state = GR_DWN;                                //Current state changed to gear down
 //printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);  
 printf("\nEnter the Pilot's Lever Position and Squat Switch Status:");   //To tell user to enter data
 fflush(stdout);                                                          //Clearing the  cache files
 scanf("%d %d",&pilot_lever,&squat_switch);                               //To scan the values.
 if(pilot_lever == Rising && squat_switch == Open)                        //Checking the condition with input values
 {
  current_state = CHK_BFR_TKFF;                                           //If the condition is satisfied, the current state is changed to check before takeoff
  printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);   //To print he data
  printf("Light Status:%s\n",State_Machine[current_state].light_status);                 
 }
 else
 {
  Gear_Down();                                                           //The same function is called again if the input is not relevant.
 }

}

Raising Gear.c:

#include "States.h"
#include
 
void Raising_Gear()                                                  //Function definition
{
 current_state = RSING_GR;                                          //Current state changed to rising gear.
 //printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
 printf("\nEnter the Limit Switch Status,Pilots Leaver Status:");   //To tell user to enter the input values
 fflush(stdout);                                                    //Clear cache
 scanf("%d %d",&limit_switch,&pilot_lever);                         //To scan the values
 printf("\nWait for 1 sec\n");
 if(pilot_lever == Falling && limit_switch == Open)                 //To check the condition with input values.
 {
  current_state = CHK_BFR_LND;                                      //The current state is changed to check before landing
  printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication); //To print the output
  printf("Light Status:%s\n",State_Machine[current_state].light_status);
  printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);

 }
 else if(limit_switch == Close && pilot_lever == UP)               //To check the condition 
 {
  current_state = GR_UP;
  printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);   //To print the values
  printf("Light Status:%s\n",State_Machine[current_state].light_status);
  printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
 }

 else
 {
  Raising_Gear();                                                 //To call the function again if the conditions are not satisfied.
 }
}

Checking_Before_Takeoff.c :

#include "States.h"
#include

void Checking_Before_Takeoff()                                                                      //Function definition
{
 current_state = CHK_BFR_TKFF;                                                                      //current state is changed to checking before takeoff
 //printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
  printf("\nEnter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:"); //To tell user to enter the input
  fflush(stdout);                                                                                   //For clearing the cache
  scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);                                //To scan the input values from the console
  printf("\nWait for 2 secs\n");
  if(pilot_lever == Falling || squat_switch == Close)                                               //To check the condition
  {
   Gear_Down();                                                                                     //function geardown() called.
  }

  else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)             //To check the condition
  {
   current_state = RSING_GR;
   printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);         //To print he values
   printf("Light Status:%s\n",State_Machine[current_state].light_status);
   printf("Direction Valve Status:%s\n\n",State_Machine[current_state].direction_valve_status);
  }

  else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Malfunctioning)      //To check the conditions
  {
   current_state = RSING_GR;                                                                       //Changing the state to rising the gear
   printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);         //To print hte output
   printf("Light Status:%s\n",State_Machine[current_state].light_status);
   printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_valve_status);
   printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
  }
}

Checking_Before_Landing.c :

#include "States.h"                //User defined header files.
#include                  //Pre-processor for standard IO operations
void Checking_Before_Landing()     //Function definiton
{
 current_state = CHK_BFR_LND;      //current state is changed to checking before landing
  //printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
  printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:");             //To tell user to input the options
  fflush(stdout);                                                                              //Clearing the cache files
  scanf("%d %d",&pilot_lever,&hydraulic_mechanism);                                            //To scan the input values
  if(pilot_lever == DOWN && hydraulic_mechanism == Working)                                    //user entered condition are checked. If the condition satisfires, the loop get executed.
  {
   current_state = LWRNG_GR;                                                                   //Changes current state to lowering gear.
   printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);     //The output gets printed.
   printf("Light Status:%s\n",State_Machine[current_state].light_status);
   printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_valve_status);
  }
  else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)                        //It checks the condition with the input
  {
   current_state = LWRNG_GR;                                                                   //Changes the current state to lowering gear.
   printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);     //the output gets printed inidicating the states.
   printf("Light Status:%s\n",State_Machine[current_state].light_status);
   printf("Direction Valve Status:%s\n",State_Machine[current_state].direction_valve_status);
   printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
  }

   if(pilot_lever == (UP || Rising || Falling))                                                //To check the pilot lever is UP or Rising or Falling. if any condition satisfies , the function is called again
  {
    Checking_Before_Landing();
  }

}

Output :

Conclusion :

Sussessfully implemented the code for controlling the retraction and extension of airplane's landing gear.

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.

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.