RL Robotics LabSearch ↗
Lesson / authored

Week 18 · Build: Correct only what you observed

Session 2 of 4 · Correct drift · Phase 5

Plan about 15 minutes for explanation, 30 minutes for practical work and 10–15 minutes for documentation. A longer build may continue into the next session: stop safely, commit the current state and record the next check. Desktop simulations count as software evidence; label them clearly and record physical validation separately.

Engineering challenge

When does a known landmark improve position, and when can it mislead you? This session focuses on correct only what you observed.

Before you start

The previous week’s recorded baseline and Week 17, Improve. For later sessions this week, retain the preceding session’s files and predictions.

Equipment: Desktop Python, editor, paper and ruler; for physical work, the configured 3pi+ 2040, clear floor mat and hardware checklist. Week 3 additionally uses the separate low-voltage LED circuit described in its procedure.

For any motion, verify the stop button, short time limit and clear floor area first. Keep the wheels raised for a new device program until its commands and stop behaviour are checked. A hazard or uncertain input is a reason to stop and document, not to force the trial to finish.

Theory and mathematics

Correct only what you observed

Suppose a uniquely identified line lies at x = 0.50 m and the robot crosses it nearly perpendicular. A detection at an estimated x = 0.54 m suggests a −0.04 m correction in x. The reading does not automatically correct y or heading. A weighted update x_new = x_est + α(x_landmark − x_est) uses 0 ≤ α ≤ 1; α = 1 trusts the landmark fully. This simple blend is not a Kalman filter. The sensor sits at an offset from the robot centre; account for that offset or stop at a surveyed reference point.

Worked example — illustrative values

A known line at x = 0.50 m is observed when estimated x = 0.54 m. With α = 0.5, x_new = 0.54 + 0.5(0.50 − 0.54) = 0.52 m. y and heading remain unchanged. This calculation assumes the centre offset has already been accounted for and the line identity is correct.

Write the calculation in your notebook before running code. State which values you measured, which you assumed and which the program calculates. A correct numerical calculation cannot rescue an incorrect physical assumption.

Run and explain the model

The following is desktop Python, not a ready-to-run motor program. Download this week’s example, save it in your student repository and run python3 code/w18.py from the repository root. The same small model is reused across the week so you can learn it, build with it, test it and revise it.

# Desktop Python teaching example. Numerical inputs are illustrative.
def correct_x(x_est, landmark_x, alpha, expected, fresh, gate_m=0.08):
    if not 0 <= alpha <= 1:
        raise ValueError("alpha outside [0, 1]")
    residual = landmark_x - x_est
    if not expected or not fresh or abs(residual) > gate_m:
        return x_est, "rejected"
    return x_est + alpha * residual, "accepted"

for case in [(0.54, True, True), (0.8, True, True), (0.54, False, True)]:
    x, expected, fresh = case
    print(correct_x(x, 0.5, 0.5, expected, fresh))

Run the example on desktop Python before adapting it. Change one valid input and check the result; keep device-only calls in a separate adapter. If an exception appears, read its final line, identify the input or assumption that caused it and make the smallest explained correction. Do not delete validation merely to obtain output.

Understanding the model and its limits

The gate rejects a correction unless landmark identity is expected, the reading is fresh and the coordinate residual lies within the declared window. Accepted corrections blend only x. With α=0, detection changes no estimate; with α=1, it trusts the known coordinate fully. A large residual could mean accumulated drift, but could also mean the wrong line was associated. The gate is a heuristic, not a complete probabilistic estimator. Record acceptance/rejection reasons and check a separate surveyed checkpoint afterward. Reusing the correction line as the only accuracy test would force the desired answer by construction.

Practical instructions

  1. Run the correction example on accepted, out-of-window and stale observations.
  2. Add the centre/sensor offset to your coordinate model or use a stopped surveyed reference.
  3. Implement a logged gated correction without changing unobserved coordinates.
  4. Replay a known trace and retain both corrected and original estimates.

Experiment

Test six cases: valid, stale, unexpected identity, too-large residual, α = 0 and α = 1; predict outcomes first.

Before testing, record your prediction, changed factor, measured response, fixed conditions and stopping rule. Save every attempted run, including failures, with a condition and source version. If hardware is unavailable, use an explicitly labelled synthetic/replay dataset and list the physical question it cannot answer. Do not invent completed trials.

Deliverable

Six deterministic correction cases with rejection reasons and untouched y/heading.

Save notebook/w18-s2.md, the relevant code revision, raw CSV or test-case records, and one labelled diagram/plot/table. Link the files relatively from your notebook. Use the entry template and report guide.

Completion criteria

A documented failed prediction can meet the learning criteria. A missing physical trial must remain marked untested; software success alone does not validate the robot.

Reading and video

Reflection and next step

Which assumption most affected your result? Point to one observation that supports your explanation and one alternative explanation the evidence has not ruled out. Write a specific next test with a changed factor and measurable outcome, then proceed through the week’s Learn → Build → Experiment → Improve cycle.

← Previous sessionCourse roadmapNext session →