ScilabTec Xcos PDF
ScilabTec Xcos PDF
1
Xcos: Introduction
2
Xcos: Features
● Use standards
HDF5 standard which has been chosen to guarantee data exchanges
between Scilab and Xcos Editor
A free Modelica compiler which enables the simulation of implicit diagrams
A brand new graphical user interface based on JGraphX
3
Xcos: Overview
4
Xcos: Overview
5
Xcos: Overview
6
Xcos: Overview
7
Xcos: Overview
8
Xcos: Overview
9
Xcos: Overview
10
Xcos: Overview
11
Xcos: A simple block (1)
Controls
Commands
Data communication is handled by data ports and data links (in black)
● Event links and event ports (discrete time)
Activation and control is performed through event ports and links (in red).
12
Xcos: A simple block (2)
Controls
BLOCK.sci block.c
Inputs runtime Outputs
parameters
evaluation
management
function
Commands
13
Xcos: the new editor
Xcos editor
● Backward compatibility
Scicos compiler
Scicos Code
Scilab
simulator generation
14
Xcos: Reusing Scilab quality process
15
Demo time,
any questions ?
www.scilab.org
16
ScilabTec 2010
17
Optimization of a PID regulator
18
Optimization of a PID regulator
importXcosDiagram('automatic_test.xcos');
function y = f_pid(x)
context.w0 = w0;
context.m = m;
context.K0 = K0;
context.P = x(1)*Pfact;
context.I = x(2)*Ifact;
Info = scicos_simulate(scs_m,list(),context,flag='nw');
y_error = mean(abs((block_output('values')(:,1) - block_output('values')(:,2))));
y_diff = mean(abs(diff(block_output('values')(:,2))));
y = 0.5*y_error + 0.5*1*y_diff; .
endfunction
19
Optimization of a PID regulator
20
Demo time,
any questions ?
www.scilab.org
21
ScilabTec 2010
22
Definition of a new C block
0
Goal: 0,5
Store N samples of the input in a buffer Buffer size
1
Ouput the buffer as a vector output of size 0,5
0
N -0,5
-1
-0,5
Parameters: 0
Padding value (real parameter - rpar) 0,5
1
Buffer size (int parameter - ipar)
23
Definition of a new C block
The simulation function side
1 – Initialization
#include "scicos_block4.h"
2 – Simulation finalization
void buffer_vect_xcos(scicos_block *block, int flag) 3 – Update block internal state
{
int nsamples = GetIparPtrs(block)[0];
4 – Put the value on the output port
double padding_value = GetRparPtrs(block)[0];
switch(flag)
{
case Initialization:
GetWorkPtrs(block) = (double *)MALLOC(sizeof(double)*nsamples);
for(int i=0;i<nsamples;i++) ((double *)GetWorkPtrs(block))[i] = padding_value;
1
break;
case Ending:
FREE(GetWorkPtrs(block)); 2
break;
case StateUpdate:
for(int i=1;i<nsamples;i++)
((double *)GetWorkPtrs(block))[i-1] = ((double *)GetWorkPtrs(block))[i]; 3
((double *)GetWorkPtrs(block))[nsamples-1] = ((double *)GetInPortRows(block,1))[0];
break;
case OutputUpdate:
for(int i=0;i<nsamples;i++)
((double *)GetOutPortPtrs(block,1))[i] = ((double *)GetWorkPtrs(block))[i]; 4
break;
}
}
24
Definition of a new C block
The interface function side (1/2)
function
[x,y,typ]=BUFFERVECT_c(job,arg1,arg2)
...
select job
case 'plot' then
standard_draw(arg1)
case 'getinputs' then
[x,y,typ] = standard_inputs(arg1)
case 'getoutputs' then
[x,y,typ] = standard_outputs(arg1)
case 'getorigin' then
[x,y] = standard_origin(arg1)
case 'set' then
A
case 'define' then
B
end
endfunction
25
Definition of a new C block
The interface function side (2/2)
26
Some more custom blocks
The FFT scope
This block is not yet available under Scilab.
(Scilab 5.3)
Signal 1
Signal 2
27
External module hierarchy
XcosMod Building the blocks and build the palette
builder.sce
Etc
XcosMod.start Loading macros, libs, gateways and adding
XcosMod.quit the palette to xcos
macros
help The interfacing functions of the blocks +
en_US others functions
fr_FR
sci_gateway
C The simulation functions of the blocks +
Cpp other functions
Ffortran
src
C
Cpp
Fortran
tests
unit_tests
nonreg_tests
28
Palette loading process
A part of XcosMod/builder.sce
// Build xcos palette
// =========================================================
xpal = xcosPal("Buffer");
xpal = xcosPalAddBlock(xpal, 'FFT_SCOPE', module_dir + '/macros/img/fft_scope.jpg');
xpal = xcosPalAddBlock(xpal, 'PS_SCOPE', module_dir + '/macros/img/ps_scope.jpg');
xpal = xcosPalAddBlock(xpal, 'VECTOR_SCOPE', module_dir + '/macros/img/vector_scope.jpg');
xpal = xcosPalAddBlock(xpal, 'BUFFER_VECT', module_dir + '/macros/img/buffer_vect.jpg');
xpal = xcosPalAddBlock(xpal, 'REAL_FFT', module_dir + '/macros/img/real_fft.jpg');
xpal = xcosPalAddBlock(xpal, 'INVERSE_FFT', module_dir + '/macros/img/inverse_fft.jpg');
xpal = xcosPalAddBlock(xpal, 'WINDOW_FUNC', module_dir + '/macros/img/window_func.jpg');
A part of XcosMod/etc/XcosMod.start
// load palette
// ======================================
xcosPalAdd(module_dir + '/Buffer.xpal');
29
Demo time,
any questions ?
www.scilab.org
30
Thanks for your attention,
any questions ?
www.scilab.org
31