Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Overview of the Project: (5 to 6 lines)
In this project, controlling 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.
Goals ( 2 to 3 points)
- Controlling the direction of Valve.
- Controlling the retraction and extension of Airplane’s landing gear.
Key Highlights of the Project: (4 to 5 points)
A direction valve is controlled by the software to allow the hydraulic pressure to either raise or lower the landing gear.
Deliverables of this project: (4 to 5 points)
Implementing the control for the retraction and extension of Airplane’s landing gear using the Finite state machine with the knowledge of various states of switch and gear.
Expected Outcomes: (4 to 5 points)
The student will be getting the Knowledge of Finite State Machine algorithm which is used to achieve the control over the retraction and extension of Airplane’s landing gear using the switch and gear states of Airplane.
ANS:-
- Step by step implementation:
- Firstly we open the STM32Cubel software and create a folder 'Project2' and then launch this software.
- After this we go to the 'File' option and go to 'new' option and then click on c/c++ project -> click on C++ Managed Build then click on next, -> click on Mingw gcc and create project name 'Project' then click on 'FINISH'.
- after create project name then we right click on project name and click on 'new' then go to 'Source file' option and click on and create source file name 'main.c', Now we start our program.
- PROGRAM:
#include<stdio.h>
#include<stdlib.h> //header file
void m (); //function
typedef enum
{
gear_down,
checking_before_take_off,
raising_gear,
gear_up,
checking_before_landing,
lowering_gear
} gear; //Enumerated data type
typedef enum
{
off,
green,
red
} light; //Enumerated data type
typedef enum
{
valve_up,
valve_down
} valve; //Enumerated data type
typedef struct
{
gear output;
gear next_state[6];
int time;
light l[3];
char *a[10];
} State; //Enumerated data type
State state_[6] = {
{gear_down, {gear_down, checking_before_take_off}, 3, {off, green, red},
{"gear down", "checking before take off", "airplan is on ground", "green",
"red"}},
{checking_before_take_off, {gear_down, raising_gear}, 3, {off, green, red},
{"gear down", "checking before take off", "raising_gear", "red"}},
{raising_gear, {gear_up, checking_before_landing}, 3, {off, green, red},
{"checking before take off", "gear up", "off"}},
{gear_up, {checking_before_landing}, 3, {off, green, red},
{"checking before landing", "gear up", "red"}},
{checking_before_landing, {lowering_gear}, 3, {off, green, red},
{"checking before landing", "lowering_gear", "gear up", "red"}},
{lowering_gear, {gear_up, checking_before_take_off}, 3, {off, green, red},
{"gear up", "checking before take off", "lowering_gear", "red"}},
};
//FSM (finite state machine
int squat_switch, current_state, pilot_lever, pilot_lever_up, limit_switch,
pilot_lever_falling, pilot_lever_down;
//global variable
int main ()
{
while (1)
{
printf ("squat switch=");
fflush(stdout);
scanf ("%d", &squat_switch);
if (0 == squat_switch) //plane is on ground squat switch off
{
printf ("\nlight=(%d)%s\n", state_[0].l[1], state_[0].a[3]);
printf ("\n%s", state_[0].a[0]);
printf ("\n%s\n", state_[0].a[2]);
current_state = state_[0].next_state[0];
continue;
} //condition to be in ground till squat switch is not closed
else if (1 == squat_switch) //plane is taking off or landing or airborn
{
printf
("\npilot lever for checking before take off or stay at ground=");
fflush(stdout);
scanf ("%d", &pilot_lever);
if (1 == pilot_lever && 1 == squat_switch) //condition to change state from down to rising
{
{
printf ("%s\n", state_[0].a[1]);
printf ("\nlight=(%d)%s\n", state_[0].l[2], state_[0].a[4]);
printf ("delay=%d\n", state_[0].time);
current_state = checking_before_take_off;
} //state has been changed
printf
("pilot lever condtion for rising gear or gear down status =");
fflush(stdout);
scanf ("%d", &pilot_lever);
if (2 == pilot_lever && 1 == squat_switch) //condition to change state 2 for lever up
{
printf ("\n%s", state_[1].a[2]);
printf ("\nlight=(%d)%s\n", state_[1].l[2], state_[1].a[3]);
current_state = raising_gear;
printf("\nlimit_switch to go at gear up or gear down before landing=");
fflush(stdout);
scanf ("%d", &limit_switch);
if (1 == limit_switch) //condition to change state from rising to gear up
{
{
printf("\n%s", state_[2].a[1]);
printf("\nlight=(%d)%s\n", state_[2].l[0],
state_[2].a[2]);
printf ("control for landing gear disabled");
current_state = gear_up;
//3 for falling
}
printf("\npilot lever before landing condition=");
fflush(stdout);
scanf ("%d", &pilot_lever);
if (pilot_lever == 3) //condition to change state from gear up to check before landing
{
printf("\n%s", state_[3].a[0]);
printf("\nlight=(%d)%s\n", state_[3].l[2],
state_[3].a[2]);
current_state = checking_before_landing;
// 4 for down
}
}
else if (1 == limit_switch || 0 == limit_switch) //condition to change state from rising to check before landing
{
printf("\n%s", state_[3].a[0]);
printf("\nlight=(%d)%s\n", state_[3].l[1],
state_[3].a[3]);
current_state = checking_before_landing;
// 4 for down
}
printf("\npilot_lever before lowering gear condition="); //4 for landing
fflush(stdout);
scanf("%d", &pilot_lever);
if (4 == pilot_lever) //condition to change state from check before landing to lowering gear
{
printf("\n%s\n", state_[4].a[1]);
printf("\nlight=(%d)%s\n", state_[4].l[1],
state_[4].a[3]);
current_state = lowering_gear;
//0 for open
}
printf("limit switch ");
fflush(stdout);
scanf("%d", &limit_switch);
printf("pilot_lever");
fflush(stdout);
scanf("%d", &pilot_lever);
if (0 == limit_switch || 0==pilot_lever) //condition to change state from lowering gear to gear down state
{
printf("\nlight=(%d)%s\n", state_[0].l[1],
state_[0].a[3]);
printf("\n%s", state_[0].a[0]);
printf("\n%s\n", state_[0].a[2]);
current_state = state_[0].next_state[0];
continue;
}
if (1 == pilot_lever || 1 == limit_switch)
{
m (); //called function
continue;
}
}
}
}
}
}
void
m () //called function
{
while(1)
{
squat_switch = 1;
printf ("pilot lever condtion for rising gear or gear down status =");
fflush(stdout);
scanf ("%d", &pilot_lever);
if (2 == pilot_lever && 1 == squat_switch) //condition to change state 2 for lever up
{
printf ("\nlight=(%d)%s\n", state_[1].l[2], state_[1].a[3]);
printf ("\n%s", state_[1].a[2]);
current_state = raising_gear;
printf ("\nlimit_switch to go at gear up or gear down before landing=");
fflush(stdout);
scanf ("%d", &limit_switch);
if (1 == limit_switch) //condition to change state from rising to gear up
{
{
printf ("\n%s", state_[2].a[1]);
printf ("\nlight=(%d)%s\n", state_[2].l[1], state_[2].a[3]);
printf ("control for landing gear disabled");
current_state = gear_up;
printf ("control for for landing gear are disabled");;
//3 for falling
}
printf ("\npilot lever checking before landing condition=");
fflush(stdout);
scanf ("%d", &pilot_lever);
if (pilot_lever == 3) //condition to change state from gear upm to check before landing
{
printf ("\n%s", state_[3].a[0]);
printf ("\nlight=(%d)%s\n", state_[3].l[1], state_[3].a[3]);
current_state = checking_before_landing;
// 4 for down
}
}
else if (1 == limit_switch || 0 == limit_switch) //condition to change state from rising to check before landing
{
printf ("\n%s", state_[3].a[0]);
printf ("\n light=(%d)%s\n", state_[3].l[1], state_[3].a[3]);
current_state = checking_before_landing;
// 4 for down
}
printf ("\npilot_lever before lowering gear condition="); //4 for landing
fflush(stdout);
scanf ("%d", &pilot_lever);
if (4 == pilot_lever) //condition to change state from check before landing to lowering gear
{
printf ("\n%s", state_[4].a[1]);
printf ("\n light=(%d)%s\n", state_[4].l[1], state_[4].a[3]);
current_state = lowering_gear;
//0 for open
}
printf ("limit switch ");
fflush(stdout);
scanf ("%d", &limit_switch);
printf("pilot lever");
fflush(stdout);
scanf("%d",&pilot_lever);
if (0 == limit_switch || 0== pilot_lever) //condition to change state from lowering gear to gear down state
{
printf ("\nlight=(%d)%s\n", state_[0].l[1], state_[0].a[3]);
printf ("\n%s", state_[0].a[0]);
printf ("\n%s\n", state_[0].a[2]);
current_state = state_[0].next_state[0];
break;
}
}
}
}
4. after complete our program then right click on 'main.c' and go to the click on 'build selected files(s)' then we right click on name of the project 'Project' and then click on 'build project' option, then your project 'binaries' created.
5. then run this program as a 'Local c/c++ Application' and Result shown Below;
- Result:

