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.
Code
#include
#include
typedef enum {
gear_down,
checking_before_take_off,
rising_gear,
gear_up,
checking_before_landing,
lowering_gear
}state_type;
typedef enum {
close,
open
}Switch;
typedef enum {
lowering,
rising
}Lever;
static volatile Switch Squat;
static volatile Lever Pilot;
state_type current_state;
void init_state_machine()
{
current_state=gear_down;
char light[100]="green";
printf("the position of the gear is %s\n",light);
}
void Gear_down()
{
current_state=gear_down;
printf("pilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot,&Squat);
if(Pilot==rising&&Squat==open)
{
char pilot_lever[100]="Rising";
char light[100]="Green";
char squat_switch[100]="Open";
printf("light:%s\n",light);
printf("pilot lever:%s\n", pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=checking_before_take_off;
}
if(Pilot==lowering&&Squat==close){
char light[100]="Red";
char pilot_lever[100]="Lowering";
char squat_switch[100]="Close";
printf("light:%s\n",light);
printf("pilot_lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=gear_down;
}
}
void Checking_Before_take_off(){
current_state=checking_before_take_off;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==rising&&Squat==open)
{
char light[100]="Red";
char pilot_lever[100]="Rising";
char squat_switch[100]="Open";
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=rising_gear;
}
}
void Rising_gear(){
current_state=rising_gear;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==lowering&&Squat==close)
{
char light[100]="Off";
char pilot_lever[100]="Lowering";
char squat_switch[100]="Closed";
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=gear_up;
}
if(Pilot==lowering&&Squat==close){
char light[100]="Red";
char pilot_lever[100]="Lowering";
char squat_switch[100]="Closed";
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=checking_before_landing;
}
}
void Gear_up(){
current_state=gear_up;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==lowering&&Squat==close)
{
char light[100]="Red";
char pilot_lever[100]="Lowering";
char squat_switch[100]="Closed";
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=checking_before_landing;
}
}
void Checking_before_landing(){
current_state=checking_before_landing;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==lowering&&Squat==close)
{
char light[100]="Red";
char pilot_lever[100]="Lowering";
char squat_switch[100]="Closed";
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=lowering_gear;
}
}
void Lowering_gear(){
current_state=lowering_gear;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==rising&&Squat==open)
{
char light[100]="Green";
char pilot_lever[100]="Rising";
char squat_switch[100]="Opened";
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=gear_down;
}
if(Pilot==rising&&Squat==open)
{
char light[100]="Red";
char pilot_lever[100]="Rising";
char squat_switch[100]="Opened";
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=checking_before_take_off;
}
}
static void(*state_table[])(void)={Gear_down,Checking_Before_take_off,Rising_gear,Gear_up,Checking_before_landing,
Lowering_gear,};
//functions
int main()
{
init_state_machine();
while(1){
state_table[current_state]();
}
return 0;
}