br3ttb / Arduino-PID-AutoTune-Library

416 stars 225 forks source link

Reverse type of controller #14

Open bmandl opened 9 years ago

bmandl commented 9 years ago

This two lines of code are made for DIRECT type of pid controller. What if user wants reverse type? Output will never step in other direction. We have to swap +'s and -'s.

    //oscillate the output base on the input's relation to the setpoint

    if(refVal>setpoint+noiseBand) *output = outputStart-oStep;
    else if (refVal<setpoint-noiseBand) *output = outputStart+oStep;

To this:

    //oscillate the output base on the input's relation to the setpoint

    if(refVal>setpoint+noiseBand) *output = outputStart+oStep;
    else if (refVal<setpoint-noiseBand) *output = outputStart-oStep;
br3ttb commented 9 years ago

this is a valid problem. if you (or someone) deals with it in a branch I will merge.

bmandl commented 9 years ago

I wouldn't find out if I wouldn't strugle with this issue for a month. First, when I had no idea what is wrong, I tried to solve it with setting output step to negative value. Oscilation acctualy worked, but parameters were negative. So I jumped into source of library.