Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
AIM: To implement the code for controlling the retraction and extension of Airplane's landing gear.
Theory:
Description of the Hardware:
- 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.
A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.
Every gear has one light. According to the state of the gear, color of light is changing.
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
Reference Document Link:
https://drive.google.com/file/d/1adQGqMrHBH6qYZmweNQTSr-rtf6coPr5/view
Code:
/*
* P2_control_airkraft_landing_gear.c
*
* Created on: 08-Aug-2022
* Author: prave
*/
/*To implement the code for controlling the retraction and
extension of Airplane's landing gear.*/
#include "P2_control_airkraft_landing_gear.h"
static void(*state_Cycle[])(void)={gearDown, checkingbeforeTakeoff, raisingGear, gearUp, checkingbeforeLanding, loweringGear};
/*main function*/
int main()
{
initiate_State_Machine();
while(1)
{
state_Cycle[current_state]();
}
}
/*Initiating the state machine*/
void initiate_State_Machine(void)
{
current_state = gear_Down;
printf("Present state of landing gear is gear_Down.\nand light is %s\n\n",state_machine[current_state].light);
}
void gearDown(void)
{
current_state = gear_Down;
printf("\nEnter 0 for raising of pilot's lever\n");
printf("Enter 1 to Open squat switch\n");
printf("Enter the status of pilots lever and squat switch: ");
int x,y;
fflush(stdout);
scanf("%d %d",&x,&y);
pilot_lever_state = x;squat_switch = y;
if(pilot_lever_state == raising_lever && squat_switch == Open)
{
current_state = checking_before_Takeoff;
printf("\nPresent state of landing gear: %s\n",state_machine[current_state].current_state_indication);
printf("Present state of light: %s\n",state_machine[current_state].light);
}
else
{
current_state = gear_Down;
}
}
void checkingbeforeTakeoff(void)
{
current_state = checking_before_Takeoff;
printf("\nEnter 1 for lever up or 2 for falling lever of pilot's lever.\n");
printf("Enter 0 to close or 1 to stay open squat_switch. \n");
printf("Enter the status of pilot lever and squat switch: ");
int x,y;
fflush(stdout);
scanf("%d %d",&x,&y);
pilot_lever_state = x;squat_switch = y;
if(pilot_lever_state == lever_up && squat_switch == Open)
{
current_state = raising_Gear;
printf("\nPresent state of landing gear: %s",state_machine[current_state].current_state_indication);
printf("\nPresent state of Direction value: %s",state_machine[current_state].direction_valve);
printf("\nPresent state of light: %s\n",state_machine[current_state].light);
}
else if(pilot_lever_state == falling_lever && squat_switch == Close)
{
current_state = gear_Down;
printf("\nPresent state of landing gear: %s",state_machine[current_state].current_state_indication);
printf("\nPresent state of light: %s\n",state_machine[current_state].light);
}
else
{
current_state = checking_before_Takeoff;
}
}
void raisingGear(void)
{
current_state = raising_Gear;
printf("\nEnter 2 for falling or 0 stay same the pilot's lever\n");
printf("Enter 0 to close or 1 to open the limit_switch\n");
printf("Enter the pilot lever state and limit switch: ");
int x,z;
fflush(stdout);
scanf("%d %d",&x,&z);
pilot_lever_state = x;limit_switch = z;
if(pilot_lever_state == falling_lever && limit_switch == Open)
{
current_state = checking_before_Landing;
printf("\nPresent state of landing gear: %s",state_machine[current_state].current_state_indication);
printf("\nPresent state of light: %s\n",state_machine[current_state].light);
}
else if(limit_switch == Close && pilot_lever_state == raising_lever)
{
current_state = gear_Up;
printf("\nPresent state of landing gear: %s",state_machine[current_state].current_state_indication);
printf("\nPresent state of light: %s",state_machine[current_state].light);
printf("\nControl for landing gear: %s\n",state_machine[current_state].Control_landing_gear);
}
else
{
current_state = raising_Gear;
}
}
void gearUp(void)
{
current_state = gear_Up;
printf("\nEnter 2 for falling the pilot's lever\n");
printf("Enter the pilot's lever state: ");
int x;
fflush(stdout);
scanf("%d",&x);
pilot_lever_state = x;
if(pilot_lever_state == falling_lever)
{
current_state = checking_before_Landing;
printf("\nPresent state of landing gear: %s\n",state_machine[current_state].current_state_indication);
printf("Present state of light: %s\n",state_machine[current_state].light);
printf("Control for landing gear: %s\n",state_machine[current_state].Control_landing_gear);
}
else
{
current_state = gear_Up;
}
}
void checkingbeforeLanding(void)
{
current_state = checking_before_Landing;
printf("\nEnter 3 for falling the pilot's lever\n");
printf("Enter the pilot's lever state: ");
int x;
fflush(stdout);
scanf("%d",&x);
pilot_lever_state = x;
if(pilot_lever_state == lever_down)
{
current_state = lowering_Gear;
printf("\nPresent state of landing gear:%s",state_machine[current_state].current_state_indication);
printf("\nPresent state of Direction value: %s\n",state_machine[current_state].direction_valve);
}
else
{
current_state = checking_before_Landing;
}
}
void loweringGear(void)
{
current_state = lowering_Gear;
printf("\nEnter 0 for raising_lever or 3 for stay lever_down the pilot's lever.\n");
printf("Enter 0 to close or 1 to open the limit_switch.\n");
printf("Enter the pilot lever state and limit switch: ");
int x,z;
fflush(stdout);
scanf("%d %d",&x,&z);
pilot_lever_state = x;limit_switch = z;
if(pilot_lever_state == raising_lever && limit_switch == Close)
{
current_state = checking_before_Takeoff;
printf("\nPresent state of landing gear: %s",state_machine[current_state].current_state_indication);
printf("\nPresent state of light: %s\n",state_machine[current_state].light);
}
else if(limit_switch == Open && pilot_lever_state == lever_down)
{
current_state = gear_Down;
printf("\nPresent state of landing gear: %s",state_machine[current_state].current_state_indication);
printf("\nPresent state of light: %s\n",state_machine[current_state].light);
}
else
{
current_state = lowering_Gear;
}
}
/*
* P2_control_airkraft_landing_gear.h
*
* Created on: 09-Aug-2022
* Author: prave
*/
#ifndef P2_CONTROL_AIRKRAFT_LANDING_GEAR_H_
#define P2_CONTROL_AIRKRAFT_LANDING_GEAR_H_
#include <stdio.h>//Preprocessor section
typedef enum
{
Close, Open
}switch_status;
switch_status squat_switch;
switch_status limit_switch;
typedef enum
{
raising_lever,
lever_up,
falling_lever,
lever_down
}pilot_lever_states;
pilot_lever_states pilot_lever_state;
typedef enum
{
gear_Down,
checking_before_Takeoff,
raising_Gear,
gear_Up,
checking_before_Landing,
lowering_Gear
}states;
states current_state;
/*Structure declaration*/
typedef struct
{
char *Control_landing_gear;
char *direction_valve;
char *light;
char *current_state_indication;
}state_Table;
/*Here defined the state table*/
state_Table state_machine[6]={
{"enabled", "Down", "GREEN", "gear_down"},
{"enabled", "Up", "RED", "checking_before_Takeoff_Delay_3s"},
{"enabled", "Up", "RED", "raising_gear"},
{"disabled","Up", "OFF", "gear_up"},
{"enabled", "Up", "RED", "checking_before_landing"},
{"enabled", "Down", "GREEN", "lowering_gear"},
};
/*Function declaration sections*/
void initiate_State_Machine(void);
void gearDown(void);
void checkingbeforeTakeoff(void);
void raisingGear(void);
void gearUp(void);
void checkingbeforeLanding(void);
void loweringGear(void);
#endif /* P2_CONTROL_AIRKRAFT_LANDING_GEAR_H_ */
Screenshot of Output (onlinegdb.com):

Screenshot of Output (STM32):

Conclusion:
Hence written and implemented the Code for controlling the retraction and extension of Airplane’s landing gear using given instructions. Obtained requried output.