The SCILAB method

The SCILAB method starts the Scilab program at the initial time t=dt opening a DDE link and permits you to execute a .sce Scilab file at each regulation time step dtu for this module (dtu can be a multiple of the numerical time step dt).

The Scilab .sce script file will be used as detailed hereafter. The name of this file can be specified in the specific parameters of the method SCILAB (pid.sce in the example provided in dat/exemple/scilab). It may indicate that name with either .sce extension (ex .: pid.sce) or without this extension (ex .: pid). In the case where the extension is not present it will be automatically added. If this file is found in the current sub-directory where the xml file of the current project is, then it will be the one used without offering the user to choose another one, which facilitates the user’s task. If this file does not exist in the current subdirectory, then a file can be selected from .sce existing files in the data subdirectory. If no name is specified, then a default name is generated and sought: module2.sce, module3.sce, etc., or a generic module"n".sce, where "n" is the controller number, starting usually at 2 (for the index 1 is used for the laws function of time, which are managed also internally as a regulator if necessary).

In the interface when calculating steady flow scenarios (FLUVIA Program) or transient scenarios (SIREN Program), the names of these .sce files from the project (xml file), automatically generated or selected by the user are shown.

At this initial time step (t=dt) the SCILAB method (of the SIRENE or FLUVIA calculation program of SIC) sends to the Scilab environment (workspace) : the calculation time step dt, the regulation time step dtu, the final time tfin and an "interf" flag allowing to manage the interfaces in the .sce file according to the interface mode as defined in the option menu.

For this and every later time step t ≥ dt (multiple of dtu, see the discussion of dtu and dt), SCILAB method sends to the Scilab environment (workspace) controlled variables y, corresponding targets yt, measured variables z, current control variable positions u and current time t. The names of these variables can be redefined. These variables are vectors since they can be multiple. In Scilab the vectors are by defaut columns (size(u) = [nu 1]), contrary to Matlab where they are lines (size(u) = [1 nu]). These vectors y, yt and z are those of the current instant t. The vector u is that calculated at the current time t and which will be applied and effective from the moment of following calculation t + dt. If you want to have the history of these vectors it is for you to store them in variables in the Scilab memory space (the variables are stored and saved in memory between 2 calls), or possibly on a file.

The SIRENE (or FLUVIA) program then executes the selected Scilab .sce file (at each time step t=n.dtu, n=1 to nmax such as t=nmax.dtu=tfin).

The SIRENE (or FLUVIA) program then retrieves the control action variables u from the Scilab workspace (as calculated by the .sce file) and applies them into SIRENE (or FLUVIA).

This SCILAB regulation method permits you to write and test quickly a regulation method while taking advantage of all Scilab development environment. In addition, it does not require any compilation or link edition of the SIRENE (or FLUVIA) program. Scilab is a free software developed under a free license and can be downloaded from the Internet. On the other hand, the regulation module execution is slower because of data exchanges between SIRENE (or FLUVIA) and Scilab, and because a .sce file is interpreted by Scilab and not compiled directly in executable code. You can check this execution time since we provide the same example with the intrinsic PID regulation module, the Scilab and the MatLab DDE link and the wdlang module.

Example of .sce file (see example provided under dat/ex_scilab):

  1. % Pid.sce file for a PID controller
  2. // Initialize ----------
  3. // Matlab and Scilab manage vectors differently
  4. // In Matlab, by default, a vector is a line (size (u) = 1 nu)
  5. // In Scilab , a default vector is a column (size (u) = nu 1)
  6. // To avoid unnecessary duplication of indexing, we adapt to that convention
  7. // Matlab and Scilab scripts are then slightly different
  8.  
  9. if t == dt
  10. [nu n1]=size(u);
  11. [ny n1]=size(y);
  12. eold=zeros(ny,1);
  13. se=eold;
  14. de=eold;
  15. end;
  16.  
  17. // calcul des coefficients utiles ----------
  18. Kp=[14.78;1.44;4.22;2.51;1.53];
  19. Ti=[1440;1680;1200;1440;1440];
  20. Td=zeros(nu,1);
  21. N =zeros(nu,1);
  22. for i=1:nu,
  23. if Ti(i)==0;
  24. Ki(i)=0;
  25. else
  26. Ki(i)=Kp(i)/Ti(i)*dt/2;
  27. end
  28. if Td(i)==0;
  29. Kd1(i)=0;
  30. Kd2(i)=0;
  31. else
  32. if N==0
  33. Kd1(i)=0;
  34. Kd2(i)=Kp(i)*Td(i)/dt;
  35. else
  36. Kd1(i)=1/(1+N(i)/Td(i)*dt);
  37. Kd2(i)=Kp(i)*N(i)*Kd1(i);
  38. end;
  39. end;
  40. end;
  41.  
  42. // calcul du pid vectoriel ----------
  43. e=yt-y;
  44. se=se+Ki.*(eold+e);
  45. de=Kd1.*de+Kd2.*(e-eold);
  46. u=Kp.*e+se+de;
  47.  
  48. // sauvegarde ancien ecart ----------
  49. eold=e;
  50.  
  51. // dessin de y et u ----------
  52. if interf==1
  53. // plot2;
  54. end;

Download

For the SCILAB method, the specific parameters to give are the default name of the .sce file and the name of the variables in Scilab workspace.

A debug option allows to decide if you want messages in case of problems (with 0 you have no message, with 1 you have messages on a scilab.dbg file in the current directory, with 2 you have the same + messages displayed on the screen). The scilab.dbg file is opened in append mode and you have therefore to delete it before a new simulation if you want to forget about previous messages. We recommend using the mode 2 during the development of .sce file and switch mode 0 for routine simulations (time gain) . [ RMQ : this management is functional in the DDE link Matlab, but not yet in the DDE link Scilab , Scilab module is therefore more difficult to debug from SIC, it is good to test it first directly into Scilab using a small script garnishing vectors y, yt and z, as well as variables t, dt, tfin, etc. running the script .sce testing and verifying the vector u calculated in both dimension and values​​].

You can specify the location of the Scilab.exe file, but in fact the Scilab.exe program that will be run will correspond to the version of the Scilab version indicated in the Windows path and to the version selected from the Options/Options menu. It also requires that the system PATH contains the reference to the good Scilab version subdirectory (the correct version you want to use), and there is no before reference to another subdirectory also contains dynamic libraries such as lapack.dll. Otherwise there will be a conflict (eg with another version of Scilab, or a version of MatLab, see below). The solutions can then be either change the path or temporarily rename the installation subdirectories of these other programs (it generally requires administrator rights to do this). It also requires the environment variable TMPDIR is set (Windows Start Menu, System, Advanced System Properties, Environment Variables, TMPDIR = C:\ tmp for example).

You can also specify if you want to close or not Scilab at the end of the simulation.

Different versions are available: from the SIC version 5.29 it is compatible with the Scilab version 4.0, 5.0.2, 5.2.2 and 5.3.3. In February 2013 the Scilab 5.4.0 version became available, but the DDE link routines have changed (the library libscilab.lib is no longer available but replaced by call_scilab.lib). Ditto for 5.5.1 and later. These new versions have not yet been tested, but we will soon, or under urgent request ! If you are using a different version, please contact us, with your libraries we can certainly compile a specific version (only in 32 bits mode for the moment).

In case you have an error or warning message (for example about the lapack.dll library), you may have a conflict between some MatLab and/or Scilab versions installed on your computer. The one found first into the Windows path definition, and the one selected into the Options/Options must be the same. You can also temporary change the name of the installation directory of some other version(s) to prevent this conflict. The reason is that different versions of MatLab and Scilab use different versions of some libraries (including the lapack one).