With DC motor servo setups, there is a known risk of runaway conditions if the feedback encoder cable gets disconnected or the encoder malfunctions. If the machine is stationary when this happens, the feedback malfunction can show 1-2 encoder ticks of position error to LinuxCNC, which is too small to trigger following error. The PID integrator will try to compensate the error, causing the axis to slowly accelerate towards one end until it crashes.
I had a near-miss with this when messing with the cabling with machine powered on (I know, stupid..). Fortunately quick e-stop press avoided a crash this time. To protect against any future cabling or encoder faults, I made this little HAL component.
Parameters:
- control_threshold: Movement is expected to occur if absolute value of control exceeds this threshold.
- feedback_threshold: Encoder is considered to work correctly if the changes in feedback exceed this threshold.
- time_threshold: Time delay to account for motor inertia.
Pins:
- input control: The output from PID controller
- input feedback: The feedback input to PID controller
- output out: Goes high if runaway is detected
The basic idea is that once the PID output is high enough, the motor should start moving. If the component doesn't see movement in encoder feedback within given time, it can be used to trigger emergency stop. Small movements that are below
feedback_threshold are expected to occur within
time_threshold seconds, after which PID output will return below the threshold. Larger movements will reset the timer every time a
feedback_threshold worth of movement is detected since the last reset.
There is example of using this component in a full configuration here:
github.com/HacklabJKL/sergei_cnc2/commit...636d14fa01c15c82e95c