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
from StudioBot import *

#move forward at speed 80 for 1 second
drivetrain.set_effort(0.5,0.5)
time.sleep(1)
drivetrain.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
from StudioBot import *

drivetrain.set_effort(0.5,0.5)

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

Last updated