You can look at my SMC worksheets here
http://deltamotion.com/peter/Mathcad/SMC/
The SMC code itself is very simple.
Basically SMC is just code to turn on/off a switch. An extremely simple version would be to turn on the switch ( heater ) when the temperature is below the set point and turn it off when the temperature is greater or equal to the set point. This will work buy you know that the PV will over shoot the SP. You could simply turn off the heater 3 degrees or some number of degrees before reaching the set point but that is crude and the temperature can drop below the set point before the heater is turned on. This is the dead band approach that is simple.
SMC doesn't use the dead band approach to avoid over shooting. Instead is uses a rate predictor sort of like the way people describe the derivative gain in a PID. The rate predictor does use the derivative of error just like the PID does. The plant or system time constant should be used as the gain. The error from the position term and the error from the rate predictor are added together to get a combined value of what you could think of as the proportional error and the rate of error ( derivative error ) it looks like this
Code:
ERROR=SP-PV
ERROR_RATE=(ERROR-LAST_ERROR)/UPDATE_INTERVAL
s = tau*ERROR_RATE+ERROR
IF s >=0 Then
heater on
ELSE
heater off
END_IF
LAST_ERROR=ERROR;
So if the update interval is 1 second and the plant time constant is 1 minute or 60 seconds then the decision to turn the heater on or off occurs every second. The update interval should be much faster than the plant time constant.
The teachers make a big deal out of something so simple. The make a big deal out of making sure the heater will actually raise the temperature to the SP under all conditions. They make a big deal about convergence. Here is a what they are trying to say. You know the PV will converge or is converging if the ERROR*ERROR_RATE<0. Think about it.
Now SMC can be more complicated. SMC doesn't work will when there is a dead time between when the heater goes on and the temperature starts to increase. The code for computing s gets to be a little more complicated if the plant has two time constants like one for the thermal mass and one for the response time of the temperature detector. In this case the formula for s is now
Code:
s=tau1*tau2*ERROR''+(tau1+tau2)*ERROR'+ERROR
I am using ERROR' to mean the error rate and the ERROR'' to mean the second derivative of the error.
Code:
ERROR''=(ERROR(n)-2*ERROR(n-1)+ERROR(n-2))/UPDATE_INTERVAL^2
The SMC code is still simple but computing the second derivative of the error is not.
Here is a video I made years ago for LinkedIn.
http://deltamotion.com/peter/Videos/SOPDT Sliding Mode Control with Smith Predictor.mp4
There was a discussion about how long dead time can be and still be controllable. I added random errors just to show how the SMC with Smith Predictor would respond.
The Smith Predictor is necessary for most temperature control applications because of the dead time.