Lesson 1. The chassis: two wheels

In pictures

After this lesson the canvas has an arena — paper, walls and an obstacle — and a robot on two wheels. With switches you drive it forward, back and spin it on the spot, and the pen on the robot draws on the paper where it has been.


1.1. Idea: no steering wheel — just two wheels

A robot vacuum, a tank and our robot have no steering wheels. There are two wheels, left and right, each with its own motor. A turn comes from the difference: which wheel turns which way.

Each wheel has two pins:

  • ON — turns (1) or stands (0);
  • DIR — which way: 1 — forward, 0 — back.
L_DIR=1 R_DIR=1both forwardstraightL_DIR=0 R_DIR=0both backbackwardsL_DIR=1 R_DIR=0left forward, right backclockwiseL_DIR=0 R_DIR=1the other wayanticlockwise
Four moves from two wheels. Green arrow — the wheel turns forward, red — backwards. No steering: the robot turns by the difference of its wheels.

1.2. Idea: four moves

Both ON pins sit on one switch GO, and the directions on two switches LDIR and RDIR:

  • both forward — the robot drives straight;
  • both back — it drives backwards;
  • left forward, right back — it spins on the spot clockwise;
  • the other way round — anticlockwise.

The wheels turn at the same speed — 60 canvas points per second, and they are 80 points apart. A spin on the spot is quick: almost a quarter turn per second.

1.3. Idea: the arena

  • Paper remembers the pen trail. The pen on the rear point of the chassis is always down — the paper shows the robot’s whole path.
  • Contour — walls along the edge of a rectangle. The robot presses against them: the wheels turn but the robot stands.
  • Obstacle — a solid block inside the arena.

Scale: 5 canvas points — 1 centimetre. The 800 × 500 arena is 160 × 100 cm, the robot is 14 × 16 cm.

1.4. Build

We set up the arena and the robot. Mechanics come from the Mechanics button (paper, contour, obstacle, chassis, pen), switches and power — from the palette. A label on a part’s pin — double-click the pin and type the name.

Step 1. Power

PartPin / actionLabel / where
PoweroutputVCC
GroundoutputGND

Step 2. The arena

Put the paper down first and the contour over it, corner to corner. Size — with the handle in the bottom-right corner: while the part is selected, its size is written by the handle. The obstacle goes in the middle of the arena, a little right of centre.

PartPin / actionLabel / where
Papersize (corner handle)
place
800 × 500
anywhere handy
Contoursize (corner handle)
place
800 × 500
exactly over the paper (corners match)
Obstaclesize (corner handle)
place
80 × 80
by eye: in the middle across, in the middle down

Step 3. The robot

Put the chassis in the left part of the arena, nose to the right. Drag the pen by its orange base nut to the rear green point of the chassis — it snaps on. The pen’s DOWN pin goes to VCC: the pen is always down and draws the path.

PartPin / actionLabel / where
Robot chassiswheel speed (Alt/⌘+click)
L_ON
R_ON
L_DIR
R_DIR
place
60
GO
GO
LDIR
RDIR
by eye: at the left edge across, in the middle down
PenDOWN
mount
VCC
on r (rear point of the chassis)

Step 4. Switches

GO stays to the end of the kit — it switches the motors on. LDIR and RDIR are a trial: in lesson 2 the chips will set the wheel direction, and we will remove these two switches.

PartPin / actionLabel / where
Input (switch)outputGO
Input (switch)outputLDIR
Input (switch)outputRDIR

1.5. Check

  1. Switch the power on. GO is off — the robot stands still.
  2. LDIR = 1, RDIR = 1, switch GO on — the robot drives forward, the pen draws a straight line. Switch GO off.
  3. LDIR = 0, RDIR = 0, GO — the robot drives backwards.
  4. LDIR = 1, RDIR = 0 — the robot spins on the spot clockwise; LDIR = 0, RDIR = 1 — anticlockwise.
  5. It reached a wall — the wheels turn but the robot stands: the chassis body turns red. Spinning on the spot while pressed against the wall will not work — the body’s corners catch the wall. First back (0/0), then turn (1/0) — and forward again.
LDIRRDIRRobot (GO on)
11drives forward
00drives backwards
10spins clockwise on the spot
01spins anticlockwise

Lesson 1 paste (Cmd+I)

Paste into a new project. It puts everything: power, the arena, the robot with the pen and the switches.

# Lesson 1 — the chassis: two wheels, the direction of each; an arena with an obstacle, the pen draws the path.# Paste: Cmd+I into a new project.# ---------- power ----------power(VCC)ground(GND)# ---------- arena: paper, contour over it, obstacle ----------mpaper p{w=800, h=500}mwall w{w=800, h=500}mblock ob{w=80, h=80}at(p, 0, 0)at(w, p, 0, 0)at(ob, p, 440, 210)# ---------- robot: chassis, pen on the rear point ----------mchassis rb{spd=60}(L_ON=GO, R_ON=GO, L_DIR=LDIR, R_DIR=RDIR)at(rb, p, 80, 210)mpen pen(DOWN=VCC)mount(pen, rb.r)# ---------- GO — motors (stays to the end of the kit) ----------input(GO)# ---------- trial: wheel direction (removed in lesson 2) ----------input(LDIR)input(RDIR)

¿No te sale? Algo no funciona →