Mathematics for robot reasoning
The course uses arithmetic, graphs and small-step models before formal calculus. Read the relevant section when it appears in a lesson. Work one example by hand, run the matching weekly program and then apply it to your own measurements. The numbers below are illustrative.
Units, ratios and average speed — Weeks 2–5
Convert centimetres to metres by dividing by 100: 60 cm = 0.60 m. Milliseconds become seconds by dividing by 1000. Use unit-bearing names such as distance_m and time_s.
Average speed = distance/time. 0.60 m in 3.0 s gives 0.20 m/s. This is average motion over the interval, not instantaneous speed. Negative signed displacement can be useful for direction; ordinary travelled distance is nonnegative. A zero or negative duration is invalid for this calculation.
Check: 90 cm in 4.5 s = 0.20 m/s. Explain why confusing milliseconds with seconds makes the result 1000 times wrong.
Mean, range and sample spread — Weeks 1, 5, 8
For values x₁ … xₙ, mean = sum(x)/n. Range = largest−smallest. Sample standard deviation is the square root of sum((x−mean)²)/(n−1), requiring n ≥ 2. For 0.19, 0.20, 0.20, 0.21, 0.20 m, mean = 0.20 m, range = 0.02 m and sample standard deviation ≈0.0071 m.
Spread describes differences between trials. It does not capture every calibration or ruler bias. Standard error of the mean, s/sqrt(n), describes sampling variability under assumptions such as representative independent trials; it does not make systematic measurement error disappear. With five observations, show all points and be cautious about broad claims.
Use Python statistics.mean and statistics.stdev for analysis. Official statistics reference.
Measurement uncertainty and residuals — Weeks 5–8
Resolution is the smallest indicated step; uncertainty includes placement, timing and model effects too. A 1 mm ruler can still have several millimetres of endpoint ambiguity. Separate signed bias from trial-to-trial spread.
For speed v = d/t and conservative small relative bounds Δd/d and Δt/t, a first-order worst-case estimate is Δv/v ≈ Δd/d + Δt/t. With d = 0.60±0.01 m and t = 3.0±0.2 s, relative bound ≈0.0167+0.0667=0.0834, so Δv≈0.017 m/s. Report approximately 0.20±0.02 m/s. This approximation is not an exact confidence interval. Independent random standard uncertainties combine differently, by a root-sum-square model, and require explicit assumptions.
Residual = measured−predicted. Mean signed residual reveals bias; mean absolute residual describes typical magnitude. Do not average positive/negative errors and call a near-zero result perfect accuracy.
Circuits and power — Week 3
V = IR for an approximately ohmic resistor. An LED needs a series resistor: estimate I = (V_source−V_LED)/R, using its actual operating conditions. For a resistor, P = VI = I²R = V²/R. Use voltage across the resistor in the last expression, not automatically the full battery voltage.
Example: 1 V across 330 Ω gives 3.03 mA and 3.03 mW. Measure voltage with probes across the component, in DC voltage mode using COM and V/Ω sockets. Never place a current-mode meter directly across a battery. The course uses a separate 2×AA LED circuit; it does not require modifying robot power rails.
Encoder calibration — Week 6
Let c be signed encoder-count change and d measured travel. A scale k has units m/count, giving d ≈ kc. Fit a through-origin scale k = sum(cᵢdᵢ)/sum(cᵢ²) only when zero counts should represent zero travel. Inspect residuals; an offset or changing slip can violate that assumption. Fit left/right scales separately if evidence warrants.
Example: 1000 counts correspond to 0.10 m, giving k = 0.0001 m/count. A new 1500-count trial predicts 0.15 m. These are illustrative values, not the robot’s factory calibration. Count convention, gearbox and actual wheel motion must be verified. Validate the scale on distances not used to fit it.
Angles and differential-drive motion — Weeks 7, 17
One revolution is 2π radians = 360°. Convert degrees to radians with degrees×π/180. A quarter-turn is π/2≈1.571 rad.
With wheel travel dL/dR and effective track width b, centre travel ds=(dL+dR)/2 and heading increment dθ=(dR−dL)/b. Equal travel gives straight motion; opposite travel gives a centre turn. Starting at heading θ, a small midpoint update is x_new=x+ds cos(θ+dθ/2), y_new=y+ds sin(θ+dθ/2), θ_new=θ+dθ.
For dL=0.09 m, dR=0.11 m, b=0.10 m and θ=0, ds=0.10 m and dθ=0.20 rad. The update gives x≈0.0995 m, y≈0.0100 m. Midpoint integration approximates an arc; use shorter steps or an exact arc model when increments are large. Wheel slip violates the ideal rolling assumption even if the algebra is correct.
Check: dL=−0.05 m and dR=+0.05 m at b=0.10 m gives ds=0 and dθ=1 rad counterclockwise under the chosen convention.
PID as sampled arithmetic — Weeks 9–12
Error e = target−measurement. Proportional contribution is Kp e. Integral accumulates e×dt each sample. Derivative estimates change/dt; taking derivative of measurement with a negative sign avoids a large setpoint-change kick. Gains carry units appropriate to the measured quantity and output command.
Example: speed error 0.05 m/s for 0.1 s adds 0.005 m to the accumulated error. A speed change of 0.02 m/s in 0.1 s is 0.2 m/s². Integral and derivative are not extra magic: integral can wind up when output is limited, and derivative amplifies noise. Clamp or condition integration, bound output, reset state on rearm and log actual dt.
A simplified teaching controller is u=clip(Kp e + Ki I − Kd Δmeasurement/dt). The course begins with proportional control and only retains added terms when held-out evidence improves. MathWorks feedback video.
Thresholds, confusion tables and hysteresis — Weeks 13–16
A threshold maps a continuous reading into a decision. Label the ground truth independently, then count true hazard detected, hazard missed, safe falsely stopped and safe correctly accepted. Precision/recall require clearly defined positive class and denominators; do not calculate a ratio with zero denominator without marking it undefined.
Hysteresis uses different thresholds to enter/leave a state. Example: enter dark at ≥700, leave dark at ≤600. A reading of 650 keeps the previous state. This reduces chatter but does not identify a physical obstacle automatically. Calibrate on your actual floor and lighting.
Coordinates, bearings and grid paths — Weeks 18–20
Distance to a waypoint is sqrt(dx²+dy²); bearing is atan2(dy,dx). Wrap angle difference with atan2(sin(error),cos(error)). From 179° to −179°, the shortest error is +2°, not −358°.
For cell size a, cell (i,j) has centre ((i+0.5)a,(j+0.5)a) relative to a corner origin. Define this convention once. Four-neighbour BFS minimizes moves for equal-cost edges; Manhattan distance |dx|+|dy| is a lower bound on move count. Inflate obstacles for robot radius and margin before planning; a centre point is not a zero-size robot.
Reliability and conditional results — Weeks 23–24
Always report successes/attempts and conditions. Eight arrivals in ten attempts is an observed 80% fraction, not a universal probability guarantee. Error among the eight arrivals is conditional on arrival; show the two failures separately. Do not pool versions changed midway through testing. A safe stopped failure can support a guard claim while failing a navigation requirement.
For every calculation, ask: what are the units, what assumptions connect the number to the physical robot, and which independent measurement could disprove the conclusion?