// START OF SCILAB CODE // (C)2018 Kevin Dorma Consulting, Ltd., short code to test PID controller for First Order or Integrating processes // shows the response to a step change in setpoint and load // Time delay functionality not available with this approach // the time range maxTime = 20 // in seconds dt = 1.0 // time step of 1 sec // select the model and the parameters typeModel = ['firstOrder','integrating'] theModel = 'firstOrder' K1 = 1 // gain for first order process OR the rate of gain for integrating process tau1 = 2.0 // first order time constant. not used for integrating // the PI controller Kc = 2 // Controller Gain tauI = 2.0 // Integrating Time tauD = 0.0 // Derivative time // that's it. // Create the transfer function for the process model s=%s; // this defines the Laplace variable s select theModel case typeModel(1) then G=K1/(tau1*s+1); // first order case typeModel(2) then G=K1/s; // integrating else G = K1 // need to throw an error end // transfer function for the controller Gc = Kc*(1 + 1/(s*tauI) + tauD*s) // closed loop TF for sp change and load change GCL = [G*Gc/(1+G*Gc); G/(1+G*Gc)] GCL=syslin('c',GCL); // the time range t=[0:dt:maxTime]'; //time in minutes theResults=csim('step',t,GCL)'; plot(t,theResults); h1=legend(['Setpoint';'Load']) // END OF SCILAB CODE