Robot systems accept inputs, such as directions on how to move, and produce the requested movements as outputs.
The outputs from robots that use Open-Loop Control have no effect on its inputs. When the inputs are matched to the task and the robot’s movements precise, Open Loop Control is a good choice.
The GPIOZERO Robot Class provides methods for simple motions:
Simple Motion with Speed Control
Robot speed is controlled with versions of the basic methods that take a FLOAT argument (i.e., a decimal number in the range 0.0 to 1.0) as the speed:
So far, this code has been straightforward with a single movement. A robot can do a sequence of actions after each other. The code listing chaining_movements.py shows how.
import gpiozero import time robot = gpiozero.Robot(left=(27, 17), right=(24, 23)) try: # Robot actions here for n in range(6): robot.forward() time.sleep(0.5) robot.left() time.sleep(0.3) robot.right() time.sleep(1) finally: robot.stop()
By tuning the timings, this will drive in a shape such as a hexagon. Line 8 makes a loop, so the action will be repeated. Lines 9, 10 drive forward for a little time. Lines 11,12 then turn left for a bit of time too. Lines 13 and 14 then do a victory spin to the right. An excellent, fun way to end autonomous events if you can determine a victory condition.