Large Error Instability

Hello John,

Thank you for your input. Your approach seems much cleaner but unfortunately, I am still getting the same results.

I feel that if I exceed my PID control signal to much, it goes unstable. By providing a step response the PID signal is too high (high err) in which causes instability. Contraining the signal is not helping for some reason. During instability (after a step response - my serial monitor just shows a repeating 255 or -255, never decreasing.

I constrained the maximum errors but I still am getting the same weird results.

  err_dot = err - err_old;
  err_dot = constrain(err_dot, -max_der, max_der);

  err_intgrl = err + err_intgrl;
  err_intgrl = constrain(err_intgrl, -max_int, max_int);

The problem I feel is the gear box on the DC motor. Because the scaling is not 1:1 - as the maximum PWM signal is set, the slaveEncoder goes to infinite because the gearbox is sending encoder positions in the thousands. I am trying to compensate for this with the scaling the encoder count in Slave_checkDirection() and Master_check Direction() but it is only efficient until a certain point.

Your thoughts?