Driving along a planned path
We can use our straight-line driving motions and curved turns to make an almost square path on the floor. We can use the helper functions we’ve made to keep this short.
Putting line and turn moves together
We are going to put some of our learning together to make a simple square pattern, as the following diagram shows:
Figure 5.8 – Driving a square path
The figure shows a square made up of four straight lines and four turns. These eight instructions are four repeating sets of a straight line and then a turn. We will have to adjust the timing of the turn to make it close to 90 degrees.
We start this code with some helpers for our motions – in pwm_drive_square.py
:
import time import robot def straight(speed, duration): robot.set_left(speed) robot.set_right(speed) time.sleep(duration) def left(speed, duration): ...