Skip to content
Tactiverge

Engineering mission · M-006

The Unreliable Sensor

Two distance sensors disagree, and a third reading looks impossible. Decide what the robot should believe, and how sure it can be.

About 1.5 h · advanced · 6 steps · Uses Lab 03 · Free

The situation

A warehouse robot measures its distance to a shelf before reaching in to pick a box. It has two distance sensors pointing at the same shelf. Sensor A is cheap and noisy: from repeated tests against a known distance, its readings scatter with a standard deviation of σ = 4.0 cm. Sensor B is better: σ = 2.0 cm. Neither has a known offset.

At one moment, Sensor A reads 102.0 cm and Sensor B reads 96.0 cm. The robot needs one number for the distance, and an honest statement of how uncertain it is, because it will only reach in if it is confident it is within 2 cm of the right distance.

Then a moment later a third reading arrives from a spare sensor, Sensor C (σ = 3.0 cm): 130.0 cm.

Your task is to design the robot's rule for combining readings and rejecting bad ones. You will compute the best combined estimate from A and B, decide whether to trust C, and then write a general rule that would work for any readings, not just these. The numbers have exact answers; the rule is a design choice with several good options, and you will be judged on how well yours is reasoned.

You will learn to

  • Combine independent measurements with inverse-variance weighting.
  • Compute the uncertainty of a combined estimate and explain why it is smaller than either input.
  • Use averaging and the σ/√n rule to compare a cheap sensor with a better one.
  • Design an outlier-rejection rule and explain its trade-offs.

Constraints

  • C1Assume each sensor's errors are independent, random and unbiased, with the σ values given.
  • C2The robot reaches in only if the combined σ is at most 2 cm.
  • C3Your rejection rule must work for any number of sensors and any readings, not just this example.
  • C4Show the arithmetic for every numeric answer.

Background

Why weight readings?

If two sensors are equally good, the sensible estimate is their average. If one is much noisier, it should count for less. Inverse-variance weighting gives each reading a weight w = 1 / σ²: halving a sensor's σ makes its weight four times larger.

estimate = (w1 · z1 + w2 · z2) / (w1 + w2)
σ_estimate = √(1 / (w1 + w2))

This assumes the sensors' errors are independent, random and unbiased. Under those assumptions, it gives the most precise combination possible from these two readings.

Worked example (not the mission data)

Two sensors read 40.0 cm (σ = 1.0 cm) and 43.0 cm (σ = 2.0 cm). The weights are 1 / 1² = 1 and 1 / 2² = 0.25.

  • Estimate = (1 × 40.0 + 0.25 × 43.0) / 1.25 = (40.0 + 10.75) / 1.25 = 40.6 cm.
  • σ = √(1 / 1.25) = √0.8 ≈ 0.89 cm.

The estimate sits much closer to the better sensor, and its uncertainty is smaller than either sensor's alone.

Here is the same idea in Python, checked on two equally good readings:

import math

def fuse(readings):
    """readings: list of (value, sigma). Returns the inverse-variance estimate and its sigma."""
    weights = [1 / s ** 2 for _, s in readings]
    estimate = sum(w * v for w, (v, _) in zip(weights, readings)) / sum(weights)
    return estimate, math.sqrt(1 / sum(weights))

# Worked example from the background (not the mission data)
est, sigma = fuse([(50.0, 3.0), (53.0, 3.0)])
print(f"estimate {est:.2f} cm, sigma {sigma:.2f} cm")
estimate 51.50 cm, sigma 2.12 cm

For two equal sensors the estimate is the plain average, and σ falls by a factor of √2: 3.0 / √2 ≈ 2.12 cm.

Averaging repeated readings

Averaging n independent readings from one sensor reduces σ to σ / √n. To halve the noise you need four times as many readings, which costs time.

Spotting a reading that does not belong

Two readings agree reasonably if their difference is small compared with the uncertainty of that difference. For independent readings, the difference has σ = √(σ1² + σ2²). A difference of more than about 3 of these σ is very unlikely from noise alone, so it suggests a fault, a reflection or the sensor seeing a different object. Rejecting readings is a trade-off: too strict and you throw away real changes, too loose and one bad reading corrupts the estimate.

How to approach it

  1. 01

    Check the two readings agree

    Before combining A and B, check they are consistent. Compute their difference and the σ of that difference, √(4.0² + 2.0²). How many σ apart are they? Is that plausible from noise alone?

  2. 02

    Combine A and B

    Compute the weights, the inverse-variance estimate and its σ. Check your answer with the fuse function. Can the robot reach in, given the 2 cm requirement?

  3. 03

    Compare averaging with a better sensor

    How many readings of Sensor A would you need to average to match Sensor B's σ of 2.0 cm? What would that cost the robot in time if each reading takes 50 ms? When might the cheaper sensor plus averaging be the better design, and when not?

  4. 04

    Decide about Sensor C

    Compare Sensor C's 130.0 cm reading with your combined A and B estimate, using the σ of the difference. Decide whether to include it. Then think about what physical causes could produce such a reading, and whether the robot should do anything besides ignore it.

  5. 05

    Write a general rule

    Write a rule, in steps or pseudocode, that takes any set of readings with their σ values, rejects ones that do not belong and returns an estimate with its σ. Say what it does if only one reading is left, or if two readings disagree with each other and there is no third to break the tie.

  6. 06

    Connect to a moving robot

    Open the sensor fusion explorer. The Kalman filter there uses the same weighting idea, but over time. Raise the camera noise and watch how the fused estimate leans more on odometry. Write two sentences connecting what you see to your weighting calculation.

Your work

Everything above is free to read and use. To save drafts, submit versions and get feedback, sign in.

You can also work on paper: the prompts below are what a submission asks for.

  1. Inverse-variance estimate from Sensors A and B (cm)
  2. σ of the combined estimate (cm)
  3. Readings of Sensor A to average to match Sensor B's σ
  4. Decision about Sensor C
  5. General combination and rejection rule
  6. When the method breaks

How it's judged

There is more than one good answer. This rubric describes what strong work looks like.

Combining measurements

Beginning
Uses a plain average or an incorrect weighting.
Developing
Correct weights but an arithmetic error, or σ of the estimate missing.
Proficient
Correct estimate and σ, with the arithmetic shown and the reach-in decision made.
Exemplary
As Proficient, plus explains why the combined σ is smaller than either input and what would change if the errors were correlated.

Consistency and outliers

Beginning
Sensor C is accepted or rejected without calculation.
Developing
A calculation is made but uses the wrong σ for the difference.
Proficient
Consistency of A and B and the outlier status of C are both checked with the σ of the difference.
Exemplary
As Proficient, plus physical causes of the outlier are considered and the robot's response goes beyond simply ignoring it.

General rule design

Beginning
No general rule, or one that only works for these numbers.
Developing
A general rule without edge cases or a justified threshold.
Proficient
A clear rule with a justified threshold and handling of the one-reading and two-disagreeing cases.
Exemplary
As Proficient, plus the rule avoids being dragged by the outlier it is testing, for example by comparing each reading with the others' combination.

Engineering trade-offs

Beginning
Averaging versus a better sensor is not discussed.
Developing
The number of readings is found but time cost is not considered.
Proficient
Time cost is calculated and a reasoned choice made between averaging and a better sensor.
Exemplary
As Proficient, plus the student identifies when averaging fails, such as when the target moves or errors are not independent.

Reflect

  • Before calculating, where did you expect the combined estimate to land? Why did it land where it did?
  • Why is rejecting a reading a design decision and not just a calculation?
  • What would make you distrust the σ values you were given?

Go further

Suppose Sensor A actually has an unknown constant offset of a few centimetres. Design a short calibration procedure using a known reference distance, and explain how the offset, if ignored, would bias the combined estimate even though its reported σ looks small.