Simvik

Garage door controller

Write the transition function of a garage door, including the obstacle safety reversal. An easy embedded C problem (State machines), run and graded in the…

easy · State machines · fsm · safety

A garage door has one button, a limit switch at the top (EV_TOP), one at the bottom (EV_BOTTOM), and a light-beam obstacle sensor.

door_next(state, event) returns the next state:

StateEventNext
CLOSEDbuttonOPENING
OPENINGtop limitOPEN
OPENINGbuttonCLOSING (reverse)
OPENbuttonCLOSING
CLOSINGbottom limitCLOSED
CLOSINGbuttonOPENING (reverse)
CLOSINGobstacleOPENING (safety)

Every other event leaves the state unchanged.

Starter code

door_t door_next(door_t state, door_event_t event) {
  return state;
}

Example tests

Open and close

run("BTBD");

Expected output:

OPENING OPEN CLOSING CLOSED

An obstacle while closing

run("BTBO");

Expected output:

OPENING OPEN CLOSING OPENING

Learn it first

More State machines problems