Lesson 5. Along the line
In picturesAfter this lesson the robot drives along a drawn line — any of the three kit tracks or your own, drawn with the mouse. There are only two new chips, and the robot «steers» with its wheels alone.
5.1. Idea: the line sensor
A line sensor looks down at the paper: over the black line its OUT = 1, over white — 0. We put two sensors at the front corners of the chassis, the line between them: while the robot drives straight, both see white.
5.2. Idea: drifted off — steer back
The robot drifts left off the line — the line slips under the left sensor. To come back, the robot must turn left. And a turn for us is the difference of the wheels (lesson 1): stop the left wheel, the right one turns — the robot turns left, around the left wheel. The same on the right.
The rule for each wheel is the same: a wheel turns as long as its sensor does not see the line.
5.3. Idea: L_ON — and the GO switch too
What we want: a wheel turns if the motors are on (GO) and its sensor is not on the line:
| GO | SL (left sees) | LON (left turns) |
|---|---|---|
| 0 | any | 0 — stopped |
| 1 | 0 | 1 — drives |
| 1 | 1 | 0 — steers back |
- Formula:
LON=GOANDNOT SL.
As in lesson 2 — by De Morgan: «A AND NOT B» = «NOT (NOT A OR B)». With NOT GO (NGO, an inverter of the CD4069):
LON=NOR(SL,NGO),RON=NOR(SR,NGO) — two gates of the CD4001.
The wheel direction does not change — both always forward: L_DIR = R_DIR = VCC.
5.4. Idea: why the tracks look like this
- Smooth turns. The robot turns around a stopped wheel — a circle of half the track width. A tighter turn — both sensors slip off and the robot loses the line. The kit tracks’ tightest turn is a circle of more than 80 points radius.
- No crossings. At a crossing both sensors see the line — both wheels stop and the robot freezes.
- No pen. The pen trail is a line too: the sensors would take it for the track.
5.5. Build
A separate project (a new canvas): paper with a track, a chassis, two line sensors and two chips. The tracks are in the kit files track-1-stadium.json, track-2-bean.json, track-3-dumbbell.json.
Step 1. Power
| Part | Pin / action | Label / where |
|---|---|---|
| Power | output | VCC |
| Ground | output | GND |
Step 2. Paper and track
Paper — 800 × 500 (written by the handle). On the paper’s panel press ⬆ and pick a track file: a black line appears on the paper. Start with the stadium.
| Part | Pin / action | Label / where |
|---|---|---|
| Paper | size (corner handle) place | 800 × 500 anywhere handy |
Step 3. The robot
Line sensors — Sensors menu → Line. Drag the left one by its orange nut to the front-left green point of the chassis, the right one — to the front-right. Put the chassis on the line: nose along it, so that the line runs between the sensors.
| Part | Pin / action | Label / where |
|---|---|---|
| Robot chassis | wheel speed (Alt/⌘+click) L_ON R_ON L_DIR R_DIR place | 60 LON RON VCC VCC by eye: left of the middle across, at the top down |
| Line (line sensor) | OUT mount | SL on fl (front-left point of the chassis) |
| Line (line sensor) | OUT mount | SR on fr (front-right point of the chassis) |
Step 4. Switch
| Part | Pin / action | Label / where |
|---|---|---|
| Input (switch) | output | GO |
Step 5. Chips
| Part | Pin / action | Label / where |
|---|---|---|
| TI CD4069UB | A G B C D E F | GO NGO GND GND GND GND GND |
| TI CD4001B | A B J C D K E F G H | SL NGO LON SR NGO RON GND GND GND GND |
Leave unconnected: H…L of the CD4069UB, L and M of the CD4001B.
5.6. Check
- Load the «stadium» track, put the robot on the line (the line between the sensors), switch the power on.
- Switch
GOon — the robot drives along the line. The eye of a sensor over the line lights up, its wheel stops for a moment — and the robot steers back. Lap after lap. - Switch
GOoff — the robot stops. - Load the «bean», then the «dumbbell» (⬆ on the paper — the drawing is replaced) and put the robot on the line again: there the turns go the other way too — the robot handles them as well.
- Chassis speed (Alt/⌘+click its body): 30, 60, 120 — it keeps the line at all of them; at 120 it steers more sharply.
| Sensors | Left | Right | Robot |
|---|---|---|---|
| line between them | turns | turns | drives straight |
| left on the line | stops | turns | turns left |
| right on the line | turns | stops | turns right |
You can draw your own track with the mouse (✏ on the paper panel): one closed line, no crossings, smooth turns — no tighter than a circle two robots across.
Lesson 5 paste (Cmd+I)
Paste into a new project — it is a separate project. The chips from robot-chips.json are needed. Load the track on the paper (⬆).
# Lesson 5 — along the line: two line sensors; a sensor sees the line — its wheel stops, the robot steers back to the line.# Paste: Cmd+I into a new project. A separate project. The track — the paper ⬆ button, a track file from the kit.# ---------- power ----------power(VCC)ground(GND)# ---------- paper for the track ----------mpaper p{w=800, h=500}at(p, 0, 0)# ---------- robot: chassis, line sensors at the front corners ----------mchassis rb{spd=60}(L_ON=LON, R_ON=RON, L_DIR=VCC, R_DIR=VCC)at(rb, p, 265, 80)mline sl(OUT=SL)mount(sl, rb.fl)mline sr(OUT=SR)mount(sr, rb.fr)# ---------- GO — motors ----------input(GO)# ---------- CD4069: NOT GO ----------"TI CD4069UB"(A=GO, G=NGO, B=GND, C=GND, D=GND, E=GND, F=GND)# ---------- CD4001: a wheel turns if GO and its sensor does not see the line ----------"TI CD4001B"(A=SL, B=NGO, J=LON, C=SR, D=NGO, K=RON, E=GND, F=GND, G=GND, H=GND)¿No te sale? Algo no funciona →