Open Loop

The StudioBot can move around without any feedback on what the wheels are doing.

The following code will drive the robot forward for 1 second and then brake.

import time
import BBS

bot = BBS.StudioBot()

#move forward at speed 80 for 1 second
bot.forward(80)
time.sleep(1)
bot.stop()

The following code shows how to turn the robot without the encoders. It's important to remember that the robot will keep turning until it is told to stop.

import time
import BBS

bot = BBS.StudioBot()

#move left for 1 second
bot.left(80)
time.sleep(1)
bot.stop()
#move right for 1 second
bot.right(80)
time.sleep(1)
bot.stop()

The following code will drive the robot forward until it senses an obstacle that is 20cm or less in front of it. When it sees this obstacle it will stop.

import board
import time
import adafruit_hcsr04
import BBS

bot = BBS.StudioBot()

sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.TRIGGER, echo_pin=board.ECHO)

bot.forward(80)

while True:
    try:
        distance = sonar.distance
        print(distance)
        if distance < 20:
            bot.stop()
            
    except RuntimeError:
        print("Retrying!")
    time.sleep(0.1)

Last updated