Project: draw a letter

Plan a path, drive it, leave a trail.

1.6DrivingRobot club20 min

Do this lesson in the simulator

Everything in this module in one run: plan a path, drive it by distance, turn or strafe at the corners, and leave a trail on the mat that spells something.

Plan first

The robot leaves a trail behind it in the simulator. To draw a letter, you plan the strokes as a list of moves. An L is two strokes: a long one down, then a short one to the right.

Write the plan as comments before any code:

# L: start top left, facing down
# 1. down 60 cm
# 2. turn to face right (or strafe)
# 3. right 30 cm

Stroke one

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

# drive forward at 60 for 60 cm, then stop
forward(60, distance=60)
print("bottom of the L at", position())

Run this in the simulator

The robot starts facing down the mat in this task (its heading is 180), so forward draws the downstroke.

Stroke two, two ways

With a turn:

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

# drive forward at 60 for 60 cm, then stop
forward(60, distance=60)
# face right
turn_left(30, angle=90)
# drive forward at 60 for 30 cm, then stop
forward(60, distance=30)
print("done at", position(), "facing", round(heading()))

Run this in the simulator

With a strafe, no turning:

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

# drive forward at 60 for 60 cm, then stop
forward(60, distance=60)
# facing down, so "left" is to the right of the mat
left(60, distance=30)
print("done at", position(), "facing", round(heading()))

Run this in the simulator

Which trail looks more like an L? The strafe version keeps the corner sharp.

Task: draw an L

Start at the top left facing down. Drive the long stroke into the corner zone, then the short stroke into the goal.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

# stroke one, stroke two

Your own letters

The free-play simulator has no zones. Plan a letter from your name (T, E, F, H and Z are easy; S and O need drive with rotation) and draw it there.

Challenges

  1. Draw your first initial. Take a screenshot of the trail.
  2. Draw two letters, lifting the "pen" between them: drive to the start of the second letter in one move.
  3. Write stroke(cm) and corner(deg) functions and draw an E with them.