Challenge

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

/*
* airplane.c
*
* Created on: 25-Jul-2022
* Author: Rajkanna
*/
#include<stdio.h>
//Different States in Airplane
typedef enum states
{
GEAR_DWN,
TAKE_OFF,
RAISING_GEAR,
GEAR_UP,
LANDING,
LOWERING_GEAR
}State_Type;
//Different LED Status
typedef enum colour
{
OFF,
RED,
GREEN
}Light_State;

//Variable Declaration
State_Type current_state;
Light_State Light;
static volatile int Pilot_Lever;
static volatile int Squat_sw;
static volatile int Limit_sw;
static volatile int Direction_valve;
//Initialization Function
void Inint_State_machine()
{
//Make Current State of Airplane as Gear Down
current_state=GEAR_DWN;
printf("State Machine is initialized & Airplane is in Gear Down State\n");
}

void Gear_Down(void)
{
//Print the Current State
printf("\nGear Down State");
//get the pilot lever position
printf("\nEnter the State of 1. Pilot Lever Raising 2.Pilot Lever Falling 3. Pilot Lever Up 4.Pilot Lever Down 5.None");
fflush(stdout);
scanf("%d",&Pilot_Lever);
//Read the squat switch position
printf("6.Squat Switch Close 7.Squat Switch Open 8.None");
fflush(stdout);
scanf("%d",&Squat_sw);
//Based on the input switch the current state of airplane
if((Pilot_Lever==1)&&(Squat_sw==7))
{
//Make Current State of Airplane as Take OFF
current_state=TAKE_OFF;
Light=GREEN;
printf("\nPilot Lever Up & Squat Switch Open");
printf("\nLight Status GREEN:%d",GREEN);
}
else
{
//Make Current State of Airplane as Gear Down
current_state=GEAR_DWN;
}
}
void Gear_Up(void)
{
printf("\nGear Up State");
//get the pilot lever position
printf("\nEnter the State of 1. Pilot Lever Raising 2.Pilot Lever Falling 3. Pilot Lever Up 4.Pilot Lever Down 5.None");
fflush(stdout);
scanf("%d",&Pilot_Lever);
//Based on the input switch the current state of airplane
if(Pilot_Lever==2)
{
//Make Current State of Airplane as Landing
current_state=LANDING;
Light=RED;
printf("\nPilot Lever Falling");
printf("\nLanding Gear Control Enabled");
printf("\nLight Status RED:%d",RED);
}
else
{
//Make Current State of Airplane as Gear Up
current_state=GEAR_UP;
}
}
void Raising_Gear(void)
{
printf("\nRaising Gear State");
//get the pilot lever position
printf("\nEnter the State of 1. Pilot Lever Raising 2.Pilot Lever Falling 3. Pilot Lever Up 4.Pilot Lever Down 5.None");
fflush(stdout);
scanf("%d",&Pilot_Lever);
//Read the limit switch position
printf("9.Limit Switch Close 10.Limit Switch Open 11.None");
fflush(stdout);
scanf("%d",&Limit_sw);
//Based on the input switch the current state of airplane
if(Pilot_Lever==2)
{
//Make Current State of Airplane as Landing
current_state=LANDING;
Light=RED;
printf("\nPilot Lever Falling");
printf("\nLight Status RED:%d",RED);
}
else if(Limit_sw==9)
{
//Make Current State of Airplane as Gear Up
current_state= GEAR_UP;
Light=OFF;
printf("\nLimit Switch Closed");
printf("\nControl for Landing Gear Disabled");
printf("\nLight Status OFF:%d",OFF);
}
else
{ //Make Current State of Airplane as Raising Gear
current_state=RAISING_GEAR;
}
}
void Lowering_Gear(void)
{
printf("\nLowering Gear State");
//get the pilot lever position
printf("\nEnter the State of 1. Pilot Lever Raising 2.Pilot Lever Falling 3. Pilot Lever Up 4.Pilot Lever Down 5.None");
fflush(stdout);
scanf("%d",&Pilot_Lever);
//Read the limit switch position
printf("9.Limit Switch Close 10.Limit Switch Open 11.None");
fflush(stdout);
scanf("%d",&Limit_sw);
//Based on the input switch the current state of airplane
if(Pilot_Lever==1)
{
//Make Current State of Airplane as Take OFF
current_state=TAKE_OFF;
Light=RED;
printf("\nPilot Lever Raising");
printf("Light Status RED:%d",RED);
}
else if(Limit_sw==10)
{
//Make Current State of Airplane as Gear Down
current_state= GEAR_DWN;
Light=GREEN;
printf("\nLimit Switch Open");
printf("\nLight Status Green:%d",GREEN);
}
else
{ //Make Current State of Airplane as Lowering Gear
current_state=LOWERING_GEAR;
}
}
void Check_Takeoff(void)
{
printf("\nTake Off State");
//get the pilot lever position
printf("\nEnter the State of 1. Pilot Lever Raising 2.Pilot Lever Falling 3. Pilot Lever Up 4.Pilot Lever Down 5.None");
fflush(stdout);
scanf("%d",&Pilot_Lever);
//Read the squat switch position
printf("6.Squat Switch Close 7.Squat Switch Open 8.None");
fflush(stdout);
scanf("%d",&Squat_sw);
//Based on the input switch the current state of airplane
if((Pilot_Lever==2)||(Squat_sw==6))
{
//Make Current State of Airplane as Gear Down
current_state=GEAR_DWN;
Light=RED;
printf("Light Status RED:%d",RED);
}
else if((Pilot_Lever==3))
{
//Make Current State of Airplane as Raising Gear
current_state= RAISING_GEAR;
Light=RED;
printf("\nPilot Lever Up & Direction Valve Up");
printf("\nDelay For 3 Second");
printf("\nLight Status RED:%d",RED);
}
else
{
//Make Current State of Airplane as Take Off
current_state=TAKE_OFF;
}
}
void Check_Landing(void)
{
printf("\nLanding State");
//get the pilot lever position
printf("\nEnter the State of 1. Pilot Lever Raising 2.Pilot Lever Falling 3. Pilot Lever Up 4.Pilot Lever Down 5.None");
fflush(stdout);
scanf("%d",&Pilot_Lever);
//Based on the input switch the current state of airplane
if(Pilot_Lever==4)
{
//Make Current State of Airplane as Lowering Gear
current_state=LOWERING_GEAR;
printf("\nPilot Lever Down & Direction Valve Down");
}
else
{
//Make Current State of Airplane as Landing
current_state=LANDING;
}
}
int main()
{
//Call Initialize Function
Inint_State_machine();
while(1)
{
switch(current_state)
{
case 0:
Gear_Down(); //Call Gear Down Function
break;
case 1:
Check_Takeoff();//Call Takeoff function
break;
case 2:
Raising_Gear();//Call Raising Gear Function
break;
case 3:
Gear_Up(); //Call Gear Up Function
break;
case 4:
Check_Landing();//Call Landing Function
break;
case 5:
Lowering_Gear();//Call Lowering Gear Function
break;
}
}
}

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.