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.
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.
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) + pushover the last second (one free parameter per hypothesis, so the fault types are not confounded).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.
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
Monitor, diagnose and heal one motor. |
Functions
Two-leg move with faults injected: go to target A, then (at |
- class MotorAgent(heal=True, quantum=True, dt=0.05, stroke=0.2, window=16, persist=3)[source]#
Bases:
objectMonitor, diagnose and heal one motor.
heal=Falseonly monitors;quantum=Falseleaves 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 exampleTinyVLA.act).policyis'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'.