Challenge

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

/*
* Project Name: AirplaneLandingGear.c
* Created on 17-10-2022
* Author: NOORUL AMEEN S M
*/
#include<stdio.h> /* Pre processor */

typedef enum
{
PARKING, TAKE_OFF, LANDING /* Declaration of STAGES of FLIGHT POSITION */
}State_type;

State_type current_state;
static int UPDOWN_SS;
static int REVLimit_switch;
static int FWDLimit_switch;

/* FLIGHT IN INITIAL STAGE */
void Initialize_state()
{
current_state = PARKING;
REVLimit_switch = 0;
FWDLimit_switch = 1;
}

/* LAMP TEST TO CHECK WORKING CONDITIONS OF ALL FIELD INSTRUMENTS BEFORE TAKEOFF - FROM COCKPIT*/
int LampTest(int L_switch)
{
int Lamp = L_switch;
if (Lamp == 1)
{
printf("\n RETRACTION Lamp ON and OFF \n");
printf("\n EXTENSION Lamp ON and OFF \n");
printf("\n MOTOR CONDITION Lamp ON and OFF \n");
}
}

/* FLIGHT IN PARKING / TAXI POSITION */
void PARKING_fun()
{
int L_switch;
int a;
printf("\nSTAGE:1 - FLIGHT IN PARKING POSITION \n");
printf("\nPress Lamp Test button: 1 for Test \n");
scanf("%d", &L_switch);
LampTest(L_switch);
printf("\n -------------------------------------- \n");

if(REVLimit_switch == 0 && FWDLimit_switch == 1)
{
printf("\nEXTENSION Lamp ON \n");
printf("\nRETRACTION Lamp OFF \n");
}

while(1)
{
printf("\nRETRACTION / EXTENSION SELECTOR SWITCH: 0 - EXTENSION / 1 - RETRACTION / 2 FOR TAKEOFF \n");
scanf("%d", &UPDOWN_SS);
if (UPDOWN_SS == 1)
{
printf("ERROR ! CAN NOT RETRACTION - FLIGHT IN PARKING / TAXI POSITION \n");
}
else if(UPDOWN_SS == 0)
{
printf("ERROR ! CAN NOT EXTENSION - LANDING GEAR ALREADY IN POSITION \n");
}
else if(UPDOWN_SS == 2)
break;
}
current_state = TAKE_OFF;
}

/* FLIGHT IN TAKEOFF / FLYING POSITION */
void TAKE_OFF_fun()
{
int a = 1;
int Speed_SNR;
printf("\nSTAGE:2 - FLIGHT IN TAKEOFF AND FLYING POSITION \n");
printf("\n -------------------------------------- \n");
printf("\nEXTENSION Lamp ON \n");
printf("\nRETRACTION Lamp OFF \n");

while(a)
{
printf("\nFLIGHT SPEED SENSOR: 1 - HIGH / 0 - LOW \n");
scanf("%d", &Speed_SNR);
printf("\nRETRACTION / EXTENSION SELECTOR SWITCH: 0 - EXTENSION / 1 - RETRACTION \n");
scanf("%d", &UPDOWN_SS);
if(Speed_SNR == 1 && UPDOWN_SS == 0)
{
printf("ERROR ! CAN NOT EXTENSION - FLIGHT IN HIGH ALTITUDE AND LANDING GEAR ALREADY IN POSITION \n");
}
if(Speed_SNR == 0)
{
if(UPDOWN_SS == 1)
{
printf("ERROR ! CAN NOT RETRACTION - FLIGHT NOT REACHED REQUIRED ALTITUDE \n");
}
else if(UPDOWN_SS == 0)
{
printf("ERROR ! CAN NOT EXTENSION - LANDING GEAR ALREADY IN POSITION \n");
}
}
else if(Speed_SNR == 1 && UPDOWN_SS == 1)
{
printf("\nFLIGHT REACHED REQUIRED ALTITUDE AND RETRACTING OF LANDING GEAR \n");
printf("\nLANDING GEAR MOTOR ROTATE REVERSE TILL REV LIMIT SWITCH SENSE \n");
REVLimit_switch = 1;
FWDLimit_switch = 0;
a = 0;
}
}
current_state = LANDING;
}

/* FLIGHT IN LANDING POSITION */
void LANDING_fun()
{
int a = 1;
int Speed_SNR;
printf("\nSTAGE:3 - FLIGHT IN LANDING POSITION\n");
printf("\n -------------------------------------- \n");

if(REVLimit_switch == 1 && FWDLimit_switch == 0)
{
printf("\nEXTENSION Lamp OFF \n");
printf("\nRETRACTION Lamp ON \n");
}

while(a)
{
printf("\nFLIGHT SPEED SENSOR: 1 - HIGH / 0 - LOW \n");
scanf("%d", &Speed_SNR);

printf("\nRETRACTION / EXTENSION SELECTOR SWITCH: 0 - EXTENSION / 1 - RETRACTION \n");
scanf("%d", &UPDOWN_SS);
if(Speed_SNR == 0 && UPDOWN_SS == 1)
{
printf("\nERROR ! CAN NOT RETRACTION - LANDING GEAR ALREADY IN POSITION \n");
}
if(Speed_SNR == 1)
{
if(UPDOWN_SS == 1)
{
printf("\nERROR ! CAN NOT RETRACTION - FLIGHT IN HIGH ALTITUDE AND LANDING GEAR ALREADY IN POSITION \n");
}
else if(UPDOWN_SS == 0)
{
printf("\nERROR ! CAN NOT EXTENSION - FLIGHT IN HIGH ALTITUDE \n");
}
}
else if(Speed_SNR == 0 && UPDOWN_SS == 0)
{
printf("\nFLIGHT REACHED LOW ALTITUDE AND EXTENSION OF LANDING GEAR \n");
printf("\nLANDING GEAR MOTOR ROTATE FORWARD TILL FWD LIMIT SWITCH SENSE \n");
REVLimit_switch = 0;
FWDLimit_switch = 1;
a = 0;
}
}
current_state = PARKING;
}

static void (*state_table[])(void) = {PARKING_fun, TAKE_OFF_fun, LANDING_fun};

int main() /* MAIN FUNTION */
{
Initialize_state();
while(1)
{
state_table[current_state]();
}
}
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.