A commercial milking robot cannot assume the udder sits still — the cow shifts weight, and a laser or ultrasonic sensor's single reading is noisy. The controller fuses repeated scans with a scalar recursive (Kalman) filter, updating a position estimate x̂ and its variance P after every measurement z:
K = P / (P + R) gain from current uncertainty P and sensor noise R
x̂' = x̂ + K·(z − x̂) blend new measurement into the estimate
P' = (1 − K)·P uncertainty shrinks with every scan
Once P drops below a lock threshold, the arm commits to x̂ as the attach target. The arm itself is a 2-link manipulator solved with closed-form inverse kinematics (law of cosines) rather than iterative search — given target distance d in the reach plane and link lengths L₁, L₂:
d = √(r² + h²) r = horizontal offset, h = vertical offset
elbow angle = acos((L1²+L2²−d²) / (2·L1·L2))
shoulder angle = atan2(h, r) + acos((L1²+d²−L2²) / (2·L1·d))
- Sensor noise — the standard deviation R of each raw scan; higher noise needs more scans to converge, or leaves the final lock less certain.
- Cow movement — the true teat position keeps drifting by a small sway while the estimate is being built and while the arm is en route, which is the main real-world source of attachment misses.
- Arm speed — how fast the end effector chases the current estimate once it commits to move.
- An attach only succeeds if the cup arrives within tolerance of the true, currently-swaying teat position — not just the last estimate — which is exactly the race real systems have to win.
Real-world relevance: automatic milking systems (e.g. Lely, DeLaval, GEA) use this laser-scan-plus-filter-plus-analytic-IK pipeline per teat, several times a day, per cow, unsupervised.