Motor monitor and self-heal agent#

A monitoring and self-healing agent for the motor.

Not a language-model agent: a supervisory loop with four jobs, run every control step.

  1. Estimate (state slot): a Kalman filter fuses the encoder with the MEMS accelerometer and, when it is used, the slow quantum accelerometer, whose near-bias-free samples keep the MEMS bias calibrated.

  2. Monitor: the accelerometer measures what the joint really did, so two redundancy checks are available. (a) The encoder is compared with a one-step dead-reckoned prediction from the accelerometer: a jump or a dropout is an encoder fault. (b) A single-fault least-squares fits of accel = gain*u - damping*omega - coulomb*tanh(omega/0.02) + push over the last second (one free parameter per hypothesis, so the fault types are not confounded).

  3. Diagnose: an estimate that leaves the nominal band for several steps names the fault: actuator gain loss, friction increase, external push, encoder jump, encoder lost, or an unrecoverable actuator.

  4. Heal: encoder faults mask the encoder and fall back on the accelerometers; plant faults re-linearise the command with the fitted plant (u = (a_des + damping*omega + coulomb*tanh - push) / gain); an unrecoverable actuator ends in a safe stop.

Only faults of those five kinds are handled. The agent knows the nominal plant (it is the controller’s design model), which is the classical assumption for fault detection; whether that holds on a real drive is a question for hardware.

Classes

MotorAgent

Monitor, diagnose and heal one motor.

Functions

run_fault_episode

Two-leg move with faults injected: go to target A, then (at switch_at) to target B, which is where the score is taken.

class MotorAgent(heal=True, quantum=True, dt=0.05, stroke=0.2, window=16, persist=3)[source]#

Bases: object

Monitor, diagnose and heal one motor. heal=False only monitors; quantum=False leaves the quantum accelerometer out.

step(meas, u)[source]#

Feed one set of measurements (and the command that produced them). Returns the state estimate (theta, omega).

control(u_pd)[source]#

Turn the controller’s command into the one sent to the motor (identity unless healing and a plant fault is diagnosed).

property final_diagnosis#

the encoder fault if one was found, else the latest plant diagnosis.

Type:

The fault the agent believes at the end

run_fault_episode(act, rng, faults=(), policy='agent', steps=80, switch_at=30, tol=0.0625)[source]#

Two-leg move with faults injected: go to target A, then (at switch_at) to target B, which is where the score is taken.

act(target, theta, omega) is the controller (for example TinyVLA.act). policy is 'encoder' (raw encoder, no agent), 'kalman' (Kalman state estimate, no agent), 'model' (Kalman with the nominal motor model, no agent), 'monitor' (agent that only monitors), 'agent no quantum' or 'agent'.