# Astrom-Hagglund Relay PID tuning - relay transfer function?

I'm implementing a PID temperature controller on a PLC. To cut down on installation time (this design may be reused many times), I want to have the PID parameters tuned automatically rather than manually.

To do this, I'm trying to implement Astrom and Hagglund's relay tuning algorithm. Essentially, the control effort is inverted each time the feedback crosses the setpoint (eg, each time the sign of the error changes).

Now, I'm pretty sure that when I do this, I just change the input to the plant back and forth between a positive and negative amplitude. Most descriptions of the method seem to also indicate this. The trouble I'm having is that right next to that description, I always see a diagram that looks like this:

This diagram seems to contradict this idea by seemingly suggesting that the plant input should be the error multiplied by the setpoint value. That is, the output from the relay is $$\text{Plant Input} = \left\{\begin{matrix} Ae(t);\; e(t) > 0 \\ -Ae(t);\; e(t) < 0 \end{matrix}\right.$$ rather than just $$\text{Plant Input} = \left\{\begin{matrix} A;\; e(t) > 0 \\ -A;\; e(t) < 0 \end{matrix}\right.$$

where $$\A\$$ is the amplitude and $$\e(t)\$$ is the error signal.

Intuitively, the first one seems wrong as this is essentially just a proportional controller, and when the error becomes negative, the double minus sign means control action is still positive. Still, I want to be absolutely sure about this - which one is right?

Your second PlantInput description is correct.
The diagram you posted is ambiguous, but interpreting the relay block as a sign function rather than a gain (which is usually of triangular shape) would dissolve your confusion and have it agree with your intuition.