All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
1. AIM: To control 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. CODE: #include <stdio.h> // Functions Declarationvoid Start_State_Machine();void…
Kotesh Mogudala
updated on 10 Jan 2023
1.
AIM:
To control 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.
CODE:
#include <stdio.h>
// Functions Declaration
void Start_State_Machine();
void GearDown();
void CheckingBeforeTakeOFF();
void RaisingGear();
void GearUp();
void CheckBeforeLanding();
void LoweringGear();
//Pointer to array function
// Static -- Makes the function accesible throughout the program
// Void --- Holds address of any type and can be typecasted to any type.
static void(*statetable[])(void) = {GearDown, CheckingBeforeTakeOFF, RaisingGear, GearUp,
CheckBeforeLanding, LoweringGear};
typedef enum State{
Gear_Down,
Checking_Before_Takeoff,
Raising_Gear,
Gear_Up,
Check_Before_Landing,
Lowering_Gear
}State_Type;
typedef enum Switch{
on,
off
}Switch_status;
typedef enum pilot_lever{
Raising,
Falling
}pilot_lever;
typedef enum hydraulic_mechanism{
working,
not_working
}hydraulic_mechanism;
// User-defined data-types declaration
// Violatile -- Tells the compiler that these variables can change their value anytime in the prog.
static volatile Switch_status squat_switch;
static volatile Switch_status limit_switch;
static volatile pilot_lever p;
static volatile hydraulic_mechanism h;
State_Type current_state;
typedef struct{
char* current_state_indication;
char* light;
char* direction_valve_status;
char* landing_gear_hydraulic_control;
char* GPSS_status[2];
}State_Table;
static State_Table State_Machine[6]={
{"GearDown","Yellow","Down","Enabled",{NULL,NULL}},
{"CheckingBeforeTakeOFF","Yellow","Down","Enabled",{NULL,NULL}},
{"RaisingGear","Red","Up","Enabled",{NULL,NULL}},
{"GearUp","Off","NULL","Disabled",{NULL,NULL}},
{"CheckBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
{"LoweringGear","Yellow","Down","Enabled",{"Disabled","Enabled"}}
};
// Gear down mechanism
void GearDown(void){
current_state = Gear_Down;
printf("\nEnter the status of pilot's lever & squat switch : ");
// To clear the buffer
fflush(stdout);
scanf("%d %d",&p,&squat_switch);
if(p==Raising && squat_switch==on){
current_state=Checking_Before_Takeoff;
printf("Current state: %s\n",State_Machine[current_state].current_state_indication);
printf("Light is :%s\n", State_Machine[current_state].light);
}
else{
GearDown();
}
}
//CheckingBeforeTakeOFF
void CheckingBeforeTakeOFF(void){
current_state = Checking_Before_Takeoff;
printf("\nEnter the status of pilot's lever and squat switch and hydraulic mechanism : ");
fflush(stdout);
scanf("%d %d",&p,&squat_switch,&h);
if(p==Falling && squat_switch==off){
GearDown();
}
else if(p ==Raising && squat_switch==on && h==working){
current_state=Raising_Gear;
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light is: %s\n",State_Machine[current_state].light);
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status);
}
else if(p == Raising && squat_switch==on && h ==not_working){
current_state=Raising_Gear;
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light is: %s\n",State_Machine[current_state].light);
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status);
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].GPSS_status);
}
}
//Raising Gear mechanism
void RaisingGear(void){
current_state=Raising_Gear ;
printf("\nEnter the status of pilot's lever and limit switch : ");
fflush(stdout);
scanf("%d %d",&p,&limit_switch);
if(p==Falling && limit_switch==on){
current_state=Check_Before_Landing ;
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light is: %s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else if(p ==Raising && limit_switch==off){
current_state=Gear_Up ;
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light is: %s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else{
RaisingGear();
}
}
//Gear Up mechanism
void GearUp(void){
current_state=Gear_Up;
printf("\nEnter the status of pilot's lever : ");
fflush(stdout);
scanf("%d",&p);
if(p ==Falling){
current_state = Check_Before_Landing;
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light is: %s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else{
GearUp();
}
}
//CheckBeforeLanding
void CheckBeforeLanding(void)
{
current_state=Check_Before_Landing;
printf("\nEnter the status of pilot's lever and hydraulic mechanism status :");
fflush(stdout);
scanf("%d %d",&p,&h);
if(p ==Falling && h ==working){
current_state = Lowering_Gear;
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light is: %s\n",State_Machine[current_state].light);
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status);
}
else if(p ==Falling && h ==not_working){
current_state = Lowering_Gear;
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light is: %s\n",State_Machine[current_state].light);
printf("Status of Direction valve: %s\n",State_Machine[current_state].direction_valve_status);
printf("Status of gas pressurised Spring System: %s\n",State_Machine[current_state].GPSS_status);
}
else if(p ==(Raising)){
CheckBeforeLanding();
}
}
//Lowering Gear mechanism.
void LoweringGear(void){
current_state=Lowering_Gear;
printf("\nEnter the status of pilot's lever and limit switch : ");
fflush(stdout);
scanf("%d %d",&p,&limit_switch);
if(p == Falling &&limit_switch==on){
current_state=Checking_Before_Takeoff;
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light is: %s\n",State_Machine[current_state].light);
}
else if(p ==Raising && limit_switch==off){
current_state=Gear_Down;
printf("Current State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light is: %s\n",State_Machine[current_state].light);
printf("Landing Gear Hydraulic Control: %s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
if(limit_switch==off){
LoweringGear();
}
}
//Initiate_State_Machine
void Start_State_Machine(){
current_state = Gear_Down;
printf("\nAeroplane's Landing Gear is Intialized and current the program is in GearDown State & Light is: %s\n",State_Machine[current_state].light);
}
// Driver Code
int main(){
Start_State_Machine();
while(1){
statetable[current_state]();
}
return 0 ;
}
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 2
a) Max. heat generation of the battery pack is Heat generation (Wh) = *R*t.I = 0.896 AmpsR = 2m Ωt = 120 secs = 0.03333 hoursHeat generation (W sec) = *0.002*120 =…
24 May 2024 01:04 PM IST
Project 1
1. Design a battery pack for a car roughly 150 Kw with 120 V. Use 3500 mAh 3.6V nominal NMC chemistry cell.a. Design the battery pack configuration. b. Draw the BMS topology for this battery pack.a) Given, we have…
24 May 2024 12:40 PM IST
Project 1 - Controlling a DC motor using PWM and monitoring its Running status
Live Batch (Preeti Mallikarjun):
01 Aug 2023 12:31 PM IST
Project 3
Live Batch ( Preeti Mallikarjun ):
22 May 2023 11:26 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.