Build a dynamic state machine to drive an autonomous robot