Phase-aware Torque Prediction
Command-context nominal torque modeling achieving 0% false positives and ~99% accel-phase accuracy for residual-based collision detection

The top chart shows actual torque (red) vs predicted torque (blue). The prediction closely tracks actual torque across all phases — acceleration, cruise, and deceleration. The bottom chart shows the residual (green) staying well within the ±threshold bands (purple). With the threshold set at approximately 1 Nm (1000 mNm), the system can sensitively detect even minor collisions while maintaining zero false positives during normal operation.
Context
Two products operate under environment-dependent load conditions:
- Ceily (robotic bed): Load changes when bedding is replaced (e.g., summer → winter bedding).
- Wally (wall-mounted system): Open/Close torque profile changes when installation slope differs (e.g., buildings on floating structures).
Torque is read directly from the motor driver.
Goal: Predict nominal torque reliably across these environment shifts and isolate abnormal torque (collision/obstruction) using residuals.
Why this is hard: Environment changes invalidate fixed torque models—the system must adapt online without retuning.
Core Problem
Residual-based detection only works if the predictor outputs a clean estimate of “what torque should be” in normal operation.
Three issues made this difficult:
-
Measured inputs contaminate the predictor
If measured accel/jerk are used directly, disturbances (contact/obstruction) leak into the feature space. The model starts explaining abnormal torque as normal → residual shrinks → detection weakens.
-
Command ≠ applied motion (especially in S-curve acceleration)
Even when commands are simple (e.g., accel is linear, jerk is constant), the real system applies them smoothly:
- accel command (1st order) manifests as a cubic-like applied profile
- jerk command (0th order) manifests as a quadratic-like applied profile
A predictor that uses raw command values without capturing the applied shape produces phase-dependent error, causing residual swings and false positives.
-
Torque dynamics are phase-dependent: Acceleration, cruise, and deceleration have different dominant factors. A single regime (“one-size-fits-all”) model produces residual spikes at transitions → false positives.
Key insight
To keep residual meaningful, nominal torque must be predicted from command context that matches the applied motion, not measured values:
- Predicted torque = nominal torque from commanded motion context
- Measured torque = nominal + abnormal
- Residual = abnormal component (what we want to isolate)
This required building clean, normalized command-derived pattern features (0–1 range) that represent how accel/jerk are actually applied during S-curve motion.
Approach
1) Accel-phase feature engineering: command-to-applied mapping
I decomposed accel-phase torque to recover how commands manifest in the real system:
- Remove S-curve velocity contribution from measured torque
- Remove linear accel contribution
- Remaining signal = S-curve curvature (two quadratic segments, consistent with jerk-limited motion)
Applied-shape mapping:
- accel command (1st order) → cubic-like profile
- jerk command (0th order) → quadratic-like profile
Generated normalized pattern features a_pattern, j_pattern ∈ [0,1]—regression learns coefficients automatically.
Result: ~99% accurate accel estimation, stabilizing nominal torque prediction.
2) Phase-aware nominal torque model (TorqueContext)
Input vector changes based on SpeedController state:
| Phase | Input | Rationale |
|---|---|---|
| Accel | [v_cmd, a_pattern, j_pattern, 0] | Applied-shape–aware command context |
| Cruise | [v_cmd, Δt, 0, 0] | Friction settles over time; Δt captures decay |
| Decel | [τ_preDecel, Δt, 0, 0] | Friction-dominated; anchored by pre-decel torque |
3) Online regression with outlier-robust learning
Weighted Least Squares prevents “learning collisions as normal”:
- If
|residual| > sensitivity→ outlier weight0.1, else normal weight1.0 - High-residual events influence model minimally; normal updates stay responsive
4) Stability gating
- Suppress residual-based detection during initial learning (parameters still drifting)
- Learning complete when θ change rate < 0.5% for 10+ cycles
- Learning-phase protection: Use last accel torque as
estimated_max_torque—compare against max rather than unstable residual, providing coverage before convergence
Tradeoffs & Limitations
- Delayed full monitoring: Stability gating requires 10+ stable cycles before enabling residual-based detection—mitigated by max-torque comparison during learning.
- Outlier influence: Outlier weight is 0.1 (not 0), so repeated collisions can still slowly shift the model.
- Phase transition sensitivity:
τ_preDecelcapture depends on accurate phase detection; jitter at transitions can affect decel baseline.
Results
- False positives: 0 observed in field deployment testing
- Accel-phase estimation: ~99% accuracy (command-to-applied matching)
- Sensitivity: detects impacts down to ~1N equivalent (estimated from controlled impact tests)
- Detection latency: ~150 ms (3 cycles × 50 ms control period)
- Safety response: Emergency state, ≤500 ms stop
- User feedback: red LED pulse for 5 seconds
Key Takeaway
Predicting nominal torque from applied-shape–aware command context (not measured signals) keeps residuals meaningful for collision detection.
I achieved this by:
- Accel-phase component extraction + normalized pattern features (0–1)
- Phase-aware inputs (Accel/Cruise/Decel) with 4-dimensional input vector
- Outlier-robust online learning (weighted updates: 1.0 normal, 0.1 outlier)
- Stability gating (enable monitoring after θ converges at <0.5% for 10+ cycles)