Challenge

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

project 2

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.

Header file

/*
* LandingGear.h
*
* Created on: Feb 10, 2023
* Author: RINSHID PK
*/

#ifndef LANDINGGEAR_H_
#define LANDINGGEAR_H_


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void Initiate_FSM(void);
void Gear_Dowm(void);
void Checkin_Befor_Takeoff(void);
void Raising_Gear(void);
void Gear_Up(void);
void Checking_Before_Landing(void);
void Lowering_Gear(void);

typedef enum
{
GearDown,
CheckinBeforeTakeoff,
RaisingGear,
GearUp,
CheckingBeforeLanding,
LoweringGear
}state_types;

typedef enum
{
up , //direction valve up
down, //direction valve down
raising,
falling
}pilotslever_state;

typedef enum
{
closed ,
opened

}switch_state;

state_types current_state;
pilotslever_state pilots_lever;
switch_state squat_switch;
switch_state limit_switch;

typedef enum
{
DirectionValve_down, //gear down-parked at bay/landed or lowering gear-landing
DirectionValve_up, //raising gear-taking off
Control_diabled ,//gear up-airborne
Control_enable
}directionvalve_status;

typedef enum
{
off, //gear is up
green, //gear is down
red //gear is raising or lowering
}light_status;

typedef struct
{
char* current_state_indication;
char* output_valve;
char* output_light;
int delay;
}state_table;

static state_table state_machine[6] = {
{"Gear Down","Direction Valve down","green",1},
{"Checkin Before Takeoff","Direction Valve down","green",3},
{"RaisingGear","Direction Valve up","red",1},
{"Gear Up","Control diabled","off",1},
{"Checking Before Landing","Control enable","red",3},
{"Lowering Gear","Direction Valve down","green",1},


};


#endif /* LANDINGGEAR_H_ */

source file

/*
* LandingGear.c
*
* Created on: Feb 10, 2023
* Author: RINSHID PK
*/

#include"LandingGear.h"
void Gear_Dowm(void)
{
current_state = GearDown;
printf("\n enter the status of pilot's_lever and squat_switch : ");
fflush(stdout);
scanf("%d %d",&pilots_lever,&squat_switch);
if (pilots_lever==raising && squat_switch==opened)
{
current_state = CheckinBeforeTakeoff;
printf("\n current state :%s\n",state_machine[current_state].current_state_indication);
printf("light : %s \n %s \n wait :%d sec",state_machine[current_state].output_light,state_machine[current_state].output_valve,state_machine[current_state].delay);
Checkin_Befor_Takeoff();
}
else
{
Gear_Dowm();
}
}
void Checkin_Befor_Takeoff(void)
{
current_state = CheckinBeforeTakeoff;
printf("\n enter the status of pilot's_lever and squat_switch : ");
fflush(stdout);
scanf("%d %d",&pilots_lever,&squat_switch);
printf("\n Checkin Before Takeoff .... \n wait %d sec ",state_machine[current_state].delay);
if (pilots_lever==up && squat_switch==opened)
{
current_state = RaisingGear;
printf("\n current state :%s\n",state_machine[current_state].current_state_indication);
printf("light : %s \n %s \n wait :%d sec",state_machine[current_state].output_light,state_machine[current_state].output_valve,state_machine[current_state].delay);
Raising_Gear();
}
else if(pilots_lever==falling || squat_switch==closed)
{
current_state = GearDown;
printf("\n current state :%s\n",state_machine[current_state].current_state_indication);
printf("light : %s \n %s \n wait :%d sec",state_machine[current_state].output_light,state_machine[current_state].output_valve,state_machine[current_state].delay);
Gear_Dowm();
}
else
{
Checkin_Befor_Takeoff();
}
}
void Raising_Gear(void)
{
current_state = RaisingGear;
printf("\n enter the status of pilot's_lever and limit_switch : ");
fflush(stdout);
scanf("%d %d",&pilots_lever,&limit_switch);
if (pilots_lever==falling )
{
current_state = CheckingBeforeLanding;
printf("\n current state :%s\n",state_machine[current_state].current_state_indication);
printf("light : %s \n %s \n wait :%d sec",state_machine[current_state].output_light,state_machine[current_state].output_valve,state_machine[current_state].delay);
Checking_Before_Landing();
}
else if(pilots_lever==up && limit_switch==closed)
{
current_state = GearUp;
printf("\n current state :%s\n",state_machine[current_state].current_state_indication);
printf("light : %s \n %s \n wait :%d sec",state_machine[current_state].output_light,state_machine[current_state].output_valve,state_machine[current_state].delay);
Gear_Up();
}
else
{
Raising_Gear();
}
}
void Gear_Up(void)
{
current_state = GearUp;
printf("\n enter the status of pilot's_lever: ");
fflush(stdout);
scanf("%d",&pilots_lever);
if (pilots_lever==falling )
{
current_state = CheckingBeforeLanding;
printf("\n current state :%s\n",state_machine[current_state].current_state_indication);
printf("light : %s \n %s \n wait :%d sec",state_machine[current_state].output_light,state_machine[current_state].output_valve,state_machine[current_state].delay);
Checking_Before_Landing();
}
else
{
Gear_Up();
}
}
void Checking_Before_Landing(void)
{
current_state = CheckinBeforeTakeoff;
printf("\n enter the status of pilot's_lever : ");
fflush(stdout);
scanf("%d",&pilots_lever);
if (pilots_lever==down)
{
current_state = LoweringGear;
printf("\n current state :%s\n",state_machine[current_state].current_state_indication);
printf("light : %s \n %s \n wait :%d sec",state_machine[current_state].output_light,state_machine[current_state].output_valve,state_machine[current_state].delay);
Lowering_Gear();
}
else
{
Checking_Before_Landing();
}
}
void Lowering_Gear(void)
{
current_state = LoweringGear;
printf("\n enter the status of pilot's_lever and limit_switch : ");
fflush(stdout);
scanf("%d %d",&pilots_lever,&limit_switch);
if (pilots_lever==raising )
{
current_state = CheckinBeforeTakeoff;
printf("\n current state :%s\n",state_machine[current_state].current_state_indication);
printf("light : %s \n %s \n wait :%d sec",state_machine[current_state].output_light,state_machine[current_state].output_valve,state_machine[current_state].delay);
Checkin_Befor_Takeoff();
}
else if(pilots_lever==down && limit_switch==opened)
{
current_state = GearDown;
printf("\n current state :%s\n",state_machine[current_state].current_state_indication);
printf("light : %s \n %s \n wait :%d sec",state_machine[current_state].output_light,state_machine[current_state].output_valve,state_machine[current_state].delay);
Gear_Dowm();
}
else
{
Lowering_Gear();
}
}
void Initiate_system()
{
current_state = GearDown;
printf("\n airplane parked at bay \n");
printf("current state :%s\n",state_machine[current_state].current_state_indication);
printf("light : %s \n %s \n ",state_machine[current_state].output_light,state_machine[current_state].output_valve);
Gear_Dowm();
}

main.c file

#include"LandingGear.h"

int main()
{
while(1)
Initiate_system();

}

main file

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.