Lab 5 — Data Logging, Filtering & Sensor-Based Motion¶
Practical focus¶
Log PWM, encoder, distance and IMU data; compare raw and filtered readings; apply a moving average or median filter; make the car slow as obstacle distance decreases.
Objectives¶
- Log four data streams simultaneously with consistent timestamps.
- Implement a moving-average and a median filter, and compare them.
- Explain the trade-off filtering makes: less noise, more lag.
- Make vehicle speed a function of measured distance rather than a constant.
Procedure outline¶
TODO — expand.
- Set up CSV-style serial logging:
millis(), pwmL, pwmR, encL, encR, distance, heading. - Capture a run. Import to a spreadsheet and plot.
- Apply a moving average over N samples. Try N = 3, 5, 10 and overlay the results.
- Try a median filter on the distance channel specifically — it rejects single-sample spikes that a mean smears out.
- Implement
speed = f(distance)so the car slows as it approaches an obstacle.
Filtering is not free
A 10-sample moving average on a 20 Hz sensor delays your obstacle detection by a quarter of a second. At 0.5 m/s that is 12 cm of extra stopping distance. Choose N deliberately and justify it in your report.
Log to CSV from the start
Paste straight into a spreadsheet. Do not print prose you then have to clean up.Deliverable¶
Raw-vs-filtered plots + speed = f(distance) behaviour.