Session 1 · 80 min
How often should the rover measure?
Sampling: the controller sees each wheel once per interval. A short interval gives few counts per sample, so one count more or less is a big jump in cm/s (noise from counting); a long one is smoother but reacts late. The speed and error are in cm/s, so a new interval changes the noise, not what Kp means. The encoder's own noise: uneven slots, a wobbling disc, a SIG wire run beside the motor leads (keep them apart), and light from outside (the datasheet asks for the sensor's detecting face to be kept away from external light; its detector is most sensitive at 900 nm, in the infrared). The sensor has hysteresis built in (the datasheet gives IFHL/IFLH as 0.55 to 0.95): its output goes HIGH at one light level and back LOW only at a lower one, so a slot edge passing slowly gives one clean change, not a burst. Seeing it: the Serial Plotter draws each labelled value as a line.
In the studio
No studio lab: this session is off-screen.
Hands-on
Start from your R14-U2 session 5 sketch with Kp = 0 and print, on each sample, labelled values for the Serial Plotter: target:, left: and right:, separated by commas, with Serial.println() at the end. Upload, then open the Serial Plotter before the motor battery goes on, as you do with the Serial Monitor. Lift the rover, wheels in the air, and run at one steady value with the sample interval at 50, 100 and 200 ms. For each, note the lowest and highest speed in steady running and how many counts one sample holds. Then, wheels still lifted, the adult holds an incandescent torch (never a hot halogen lamp) at the open side of one sensor, away from the wires, while you watch the plot for extra or missing counts. The detector is most sensitive at 900 nm, in the infrared, so an LED torch may show no effect; "no effect" is a valid result.
Starting code: The learner's own sketch from R14-U2 session 5, with Kp = 0 and labelled values printed for the Serial Plotter.
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
A sampling table (interval → counts per sample, lowest and highest steady speed in cm/s, how late a change shows), a drawing or screenshot of the plot at two intervals (the rover only, no people), and a note on what the torch did, "no effect" included.
- Predict
- Which interval will make the plotted speed the most jagged?
- Debug
- If the Serial Plotter draws nothing, check that each line ends with Serial.println() and that its baud rate matches Serial.begin().
- Reflect
- Which interval would you give the controller, and what does it cost?
⚠ 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, wheels in the air, for every run in this session. The torch is incandescent, never a hot halogen lamp, held by the adult clear of the wheels and the wires. 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: Data-driven tuning