KevsRobots Learning Platform
56% Percent Complete
By Kevin McAleer, 5 Minutes
BurgerBot uses differential drive - a system where two wheels are controlled independently to create movement. By varying the speed and direction of each motor, you can make the robot move forward, backward, and turn.
How it works:
What it does: Activates both motors in the forward direction to propel the robot ahead.
The code:
from burgerbot import Burgerbot
import time
bot = Burgerbot()
# Move forward for 2 seconds
bot.forward(2)
bot.stop()
How it works:
from burgerbot import Burgerbot imports the BurgerBot librarybot = Burgerbot() creates a new robot objectbot.forward(2) moves the robot forward for 2 secondsbot.stop() stops both motorsWhy this matters: Forward movement is the foundation of robot navigation. Understanding how to control movement duration helps you create precise navigation patterns.
What it does: Reverses both motors to move the robot backward.
The code:
from burgerbot import Burgerbot
bot = Burgerbot()
# Move backward for 1.5 seconds
bot.backward(1.5)
bot.stop()
How it works:
bot.backward(1.5) reverses both motors for 1.5 secondsReal-world use: Backward movement is essential for obstacle avoidance - when your robot detects an object, it needs to reverse before choosing a new direction.
What it does: Rotates the robot in place by spinning the motors in opposite directions.
The code:
from burgerbot import Burgerbot
bot = Burgerbot()
# Turn left for 1 second
bot.left(1)
bot.stop()
# Wait a moment
import time
time.sleep(0.5)
# Turn right for 1 second
bot.right(1)
bot.stop()
How it works:
bot.left(1) spins the robot counterclockwise by running the right motor forward and left motor backwardbot.right(1) spins the robot clockwise by running the left motor forward and right motor backwardTip: A 1-second turn typically rotates the robot about 90 degrees, but this varies based on battery charge and surface friction. Experiment to find the right timing for your robot!
Now that you understand the basics, you can combine movements to create patterns:
from burgerbot import Burgerbot
import time
bot = Burgerbot()
# Drive in a square
for i in range(4):
bot.forward(2) # Forward for 2 seconds
bot.stop()
time.sleep(0.2) # Brief pause
bot.right(1) # Turn 90 degrees
bot.stop()
time.sleep(0.2)
print("Square complete!")
What this does: Creates a square pattern by repeating forward movement and 90-degree turns four times.
Why: Motor polarity determines direction - if wired backward, βforwardβ becomes βbackwardβ
Why: Manufacturing differences between motors or uneven wheel wear causes speed imbalances
Why: Low voltage or loose connections prevent motors from running
bot.left(0.8) or bot.left(1.2) and fine-tuneWhy: Turn angle depends on motor speed, battery charge, and surface friction - it requires calibration
Congratulations! Your BurgerBot is moving! Now letβs practice:
Modify forward duration: Change bot.forward(2) to bot.forward(5). How much farther does your robot travel? Can you measure the distance?
Create a triangle: Can you make your robot drive in a triangle shape? Hint: Youβll need 120-degree turns instead of 90-degree turns.
Figure-8 pattern: Create a figure-8 by combining forward movement with left and right turns. This is challenging!
Obstacle course: Set up some boxes and navigate your robot around them using only forward, backward, and turn commands.
Challenge: Write a function called move_distance(centimeters) that calculates the correct duration to move a specific distance. Youβll need to measure how far your robot travels in 1 second, then use that to calculate duration.
Now that your robot can move in all directions, the next lesson will teach you how to measure distance using the ultrasonic rangefinder. This is the first step toward autonomous navigation!
You can use the arrows β β on your keyboard to navigate between lessons.
Comments