Rewrite state machine, adding timeouts to handle broken motor/sensor. See README for more elaboration.