Logo
  • Home
  • Equipment
  • Tutorials
  • Calendar
  • TPZ Staff Page
  • (Beta) Tech Ai Support
Fab Lab Website
Fab Lab Website

State Machine for Beyond Possible Robot, Pt. 1

Tags
electronicsarduino
Date
Author
U
Untitled
Documentation Type
Class
Beyond Possible
Class Section
Careers of the future

‣

What is a state machine?

Getting Started

We’re going to modify some code to create a simple state machine to control our robot. This state machine will have two states, “SEARCH” and “FOLLOW”. Right now, only “FOLLOW” is working in the code.

image

Step 1: Download the state machine template and open in Arduino IDE

Download the code here

Step 2: Add a new “SEARCH” state

Under line 41, add an else {} statement to make “SEARCH” our default state.

else {
  state = "SEARCH";
}

Step 3: Add the behavior for the “SEARCH” state

Under line 72, add an else if {} statement to hold the “SEARCH” behavior.

  else if(state == "SEARCH") {
    turnLeft();
  }

Step 4: Test your code

What does your robot do when it doesn’t identify any objects?

Part 2

The Possible Zone