Test a policy with imperfect sensors

Replace a perfect measurement with noise, bias, delay, and missing samples.

Exercise brief·Beginner·3 min read

Opening the Python editor…

Requirements and learning goals

Before you start

  • Python 3
  • An observation contract with units and timestamps

You will be able to

  • Distinguish random noise from systematic error
  • Test stale and missing observations without confusing them with zero

The browser exercise above works without extra setup. The project brief below assumes the listed prerequisites and gives you a task and checks to perform. Need a guided first project?

Why clean data can teach the wrong behavior

A simulator can supply an exact distance at perfectly regular intervals. A real sensor may fluctuate, report a consistent offset, drift as it warms up, or miss a reading. Cameras add motion blur, exposure changes, occlusion, and imperfect calibration. Transport adds delay and jitter.

A trained only on pristine inputs can rely on precision or timing that hardware cannot supply. Random noise is only one part of that gap: averaging may reduce fluctuations, but it does not remove a fixed calibration error or make an old frame current.

In the Go2/G1 sensor workflow, pause a sensor and check how your app handles stale observations. Then compare simulated readings with recorded hardware data before choosing fault ranges.

Inject repeatable faults

This is a synthetic distance sensor, not a robot driver. Save it as sensor_faults.py and run python3 sensor_faults.py:

import random
 
rng = random.Random(7)
truth_m = 1.0
bias_m = 0.05
for step in range(8):
    capture_s = step * 0.1
    arrival_s = capture_s + (0.3 if step == 5 else 0.02)
    value = None if step == 3 else truth_m + bias_m + rng.gauss(0, 0.01)
    age_s = arrival_s - capture_s
    usable = value is not None and age_s < 0.15
    print(step, value, round(age_s, 2), usable)

Expect readings near 1.05 m despite a true distance of 1 m. Step 3 is missing; step 5 is late. Both are unusable. These numbers illustrate faults; they are not measured specifications for any sensor.

Checkpoint 1 of 2

Suppose you extend the loop and average 100 usable readings from this synthetic sensor. What value does the average approach?

Commit to an answer. Every choice explains itself.

Test your response

Feed the samples into your observation adapter. Missing must not become zero distance. Late samples must not gain a new capture timestamp. Repeated runs should produce the same results because the random seed is fixed.

Checkpoint 2 of 2

Your adapter stamps each sample with the time it arrives instead of the time it was captured. What happens to the late sample at step 5?

Commit to an answer. Every choice explains itself.

Optional extension: introduce faults separately, then combine them. Measure task success and stop behavior, not just average prediction error. Choose realistic ranges from hardware logs; independent Gaussian noise cannot reproduce every real failure.

Related lesson: sim-to-real checks. The sensor dashboard walkthrough explains pausing sensors and checking freshness.

Can you do each of these?

  • Distinguish random noise from systematic error
  • Test stale and missing observations without confusing them with zero

0 of 2 checkpoints solved. Try checkpoint 1

Previous: Define observations, actions, and rewards
All lessons in this topic
  1. 1. Define observations, actions, and rewards
  2. 2. Test a policy with imperfect sensors
  3. 3. Train a small policy and keep the experiment reproducible
  4. 4. Learn from demonstrations without copying hidden state
  5. 5. Evaluate and replay a policy as a complete system
  6. 6. Measure the simulation-to-hardware gap

Ask Wendy

Answers about Wendy and WendyOS

What would you like to know?

Ask about devices, development, and deployment.

Check linked docs for technical details.