Challenge

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

/*

Aurthor: kishore

Date: 02-01-2025

*/

//FSM program

#include <stdio.h>

// Define states

typedef enum {

RETRACTED,

EXTENDING,

EXTENDED,

RETRACTING

} GearState;

// Define switch positions

typedef enum {

SWITCH_NEUTRAL,

SWITCH_UP,

SWITCH_DOWN

} SwitchState;

// Function prototypes

void handleState(GearState *currentState, SwitchState switchPosition);

int main() {

GearState currentState = RETRACTED;

SwitchState switchPosition = SWITCH_NEUTRAL;

// Example sequence of switch positions

SwitchState switchSequence[] = {SWITCH_DOWN, SWITCH_NEUTRAL, SWITCH_UP, SWITCH_NEUTRAL};

int sequenceLength = sizeof(switchSequence) / sizeof(switchSequence[0]);

for (int i = 0; i < sequenceLength; ++i) {

switchPosition = switchSequence[i];

handleState(&currentState, switchPosition);

}

return 0;

}

void handleState(GearState *currentState, SwitchState switchPosition) {

switch (*currentState) {

case RETRACTED:

if (switchPosition == SWITCH_DOWN) {

*currentState = EXTENDING;

printf("Transitioning to EXTENDING state.\n");

}

break;

case EXTENDING:

if (switchPosition == SWITCH_NEUTRAL) {

*currentState = EXTENDED;

printf("Transitioning to EXTENDED state.\n");

}

break;

case EXTENDED:

if (switchPosition == SWITCH_UP) {

*currentState = RETRACTING;

printf("Transitioning to RETRACTING state.\n");

}

break;

case RETRACTING:

if (switchPosition == SWITCH_NEUTRAL) {

*currentState = RETRACTED;

printf("Transitioning to RETRACTED state.\n");

}

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.