Session 1 · 90 min
How straight is open loop?
Open loop: one analogWrite() value to both wheels and no correction. If R14-U1's table shows the two wheels at different speeds for the same value, the rover curves, and how much can change from run to run. A baseline for the unit: the sideways drift after 2 m and its spread over five runs. Straightness is measured in cm: the drift on the floor, and in the log each wheel's distance (its counts × its own cm per count), never the raw count difference, since the two wheels' cm per count can differ.
In the studio
No studio lab: this session is off-screen.
Hands-on
Lay a 2 m tape line on the floor with a start cross. Start from your R14-U1 session 5 sketch, driving both wheels at one value until the average distance reaches 200 cm, with the stall rule in the drive state, and logging both counts and both distances every 100 ms. Upload, open the Serial Monitor before the motor battery goes on (opening it restarts the UNO), lift the rover, wheels in the air, and check that both wheels turn forward. Then run five trials on the floor, never above 160 of 255, the front-centre mark on the start cross each time: measure how far the mark ends from the line (left or right, in cm) and note the final left − right distance difference in cm.
Starting code: The learner's own sketch from R14-U1 session 5, set to drive 200 cm, with its stall rule.
Pins
- D2
- left wheel encoder SIG (photo interrupter breakout)
- D3
- right wheel encoder SIG (photo interrupter breakout)
- D4
- driver AIN1 (left motor)
- D5
- driver PWMA (left motor)
- D6
- driver PWMB (right motor)
- D7
- driver AIN2 (left motor)
- D8
- driver STBY moved from D3
- D9
- HC-SR04 Trig (wired, not read; kept OUTPUT and LOW)
- D10
- HC-SR04 Echo (wired, not read in these sketches)
- D11
- driver BIN2 (right motor)
- D12
- driver BIN1 (right motor)
- A0
- STOP button (other side to GND) moved from D2
Evidence to collect
An open-loop table: five runs, the sideways drift at 2 m (cm, left or right), the final left − right distance difference (cm), and the spread of the drift (largest minus smallest).
- Predict
- Which way will the rover curve, judging from your R14-U1 speed table?
- Debug
- If it curves a different way on each run, check the castor and the floor before the code: the same input should give a similar run.
- Reflect
- Would a fixed change to one wheel's value fix the curve for good? Why or why not?
⚠ Adult checks before power-on: Before every upload: setup() never sets pin 2 or 3 as OUTPUT (the encoders drive those pins). The motor battery reaches the driver's VM only, through its power-off switch; the board's 5V goes to the driver's VCC only; every GND is joined. Lifted for the first run of every new sketch; then the first run on the floor at the lowest value that starts both wheels, never above 160 of 255; later runs stay within that ceiling, on a clear floor with the power-off switch in reach. The stall rule: in every driving state, go to STOPPED if a wheel's count is unchanged for 5 samples while its value is above its measured start value, or if the segment runs over twice its measured time. The USB cable is held clear of the wheels by the adult. Fingers and hair clear of wheels and discs while the motor battery is on. Lift the rover (wheels in the air) before switching the motor battery back on: the sketch keeps running on USB, so the wheels take its last command at once.
Works towards: Feedback control