introduction to scicoslab-scicos
TRANSCRIPT
-
8/16/2019 Introduction to ScicosLab-Scicos
1/33
Introduction to ScicosLab\Scicos
Lombardi Lorenzo
September 1, 2011
This document is an abstract of my thesis in Electronic Engineering at the ni!ersity of"lorence at the Laboratory of ltrasound and #$T% $isclosure of this document is permitted free as long
as the authorship &ill be recognized and its use reser!ed only for educational and research purposes %
1
-
8/16/2019 Introduction to ScicosLab-Scicos
2/33
IndexIntroduction to ScicosLab\Scicos %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1
'remise%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(
1%1ScicosLab%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%)
1%2 Introduction to ScicosLab*Scicos%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%)1%2%1 +dd ne& bloc to Scicos%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1-
1%( .ibliography%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%((
2
-
8/16/2019 Introduction to ScicosLab-Scicos
3/33
'remiseThe operating system on &hich &ere carried out the e/amples in the
document is indo&s ' S'( on &hich &ere installed !ersions )%)b- of
ScicosLab and !ersion 1%%1 of Eria Enterprise, code3named 45iacomo4, &ith
the ScicosLab 'ac 6%( % $ifferent 7Ses and * or later !ersions of the soft&aremay bring to significantly differ result &ith &hat follo&s, ho&e!er I hope that
the tutorial &ill be useful the same%
(
-
8/16/2019 Introduction to ScicosLab-Scicos
4/33
1%1 ScicosLab
ScicosLab is an 7pen Source soft&are pacage &hose de!elopment is carried
out by the 8ET+L+1 group enclosing some researchers belonging to I#9I+2 and
E#':( based on !ersion ) of Scilab and containing &ithin it an important toolbo/called Scicos%
Scilab is a soft&are for numerical computation that includes, &ithin libraries,
hundreds of useful features for different uses; from the mathematical calculation to the
simulation of control systems% It also offers the opportunity to design the personal
functions in :, : you can still
change the &orboo &ithout ha!ing to restart the program ?
7pen ScicosLab% To place the &oring directory to the desired folder,
type the command
cd>4'ath folder4?@
The Auotes that enclose the path of the folder used to a!oid problems
related to the presence of any spaces in the path
>es%; :;\$ocuments and Settings\folder?
To start Scicos, in the top bar, under 4+pplication4 menu, select
4Scicos4 >or run the command BScicos >?@B 3ithout AuotesC 3 In ScicosLab?
This &ill open a ne& &indo&% In this &indo&, in the top menu, go on
the 4'alette4 menu and select 4pal tree4; a third &indo& &ill appear &ith
!arious e/pandable folders containing all blocs >4palette4? usable in Scicos%
7pen the
menu 4sources4 and position itself on the bloc 45E#DS94
"ig% 1%1; 5E#DS9% bloc
1 8EThodes, +lgorithmes et Logiciels pour lB +utomatiAue, http;**&&&3
rocA%inria%fr*metalau*2 Istitut #ational de 9echerche en InformatiAue et en +utomatiAue, http;**&&&%inria%fr*
( Ecole #ationale des 'onts es des :haussFes, http;**&&&%enpc%fr*english*intDinde/%htm
)
-
8/16/2019 Introduction to ScicosLab-Scicos
5/33
>scrolling the mouse o!er the !arious blocs present in the menu the
name of the bloc are displayed?
$rag the 45E#DS94 bloc into the &indo& of Scicos !ia a single
clic of the left mouse button on it, hold it until it is positioned in the desired position%
Gou can mo!e a bloc already present on the plan &ith the same
system, or by right3clicing the mouse on the bloc and select 48o!e4%
5o to the menu 4Sins4 and place the bloc 4cscope4 &ith the same system
described for the bloc 45E#DS94%
'lace the mouse on the output arro& of the bloc 5E#DS9, clic
&ith the left mouse button and hold it do&n, dra& a line from this bloc the
entrance to the bloc :scope
"ig% 1%2; :S:7'E bloc%
'lace the mouse on the output arro& of the bloc 5E#DS9, clic
&ith the left mouse button and hold it do&n, dra& a line from this bloc the
entrance to the bloc :scope
"ig% 1%(; Simple e/ample of connection bet&een blocs%
#o&, on the top bar of the Scicos &indo&, go to 4Simulate4 menu and
select 49un4% This &ill open a fourth &indo& named 4ScicosLab 5raphic4 and
&hat &ill not be e/actly the sAuare &a!e that &e e/pected;
-
8/16/2019 Introduction to ScicosLab-Scicos
6/33
"ig% 1%); 5raph of the bloc : S:7'E resulting from the diagram of "ig% (%
The sa&tooth displayed an 4edge effect4 arising from the manner in
&hich the scope combines t&o samples by default% The mechanism is Ba littleB
complicated to e/plain and is not one of the ob=ecti!es of this introduction, but
rather to see ho& to sol!e this problem%
:lose the graph &indo& and, returning on Scicos, drag the bloc
diagram 4:L7:HDc4 from the 4Sources4 menu;
"ig% 1%; :L7:HDc bloc%
Then go on the bloc : and S:7'E, double clicing &ith the left
mouse button on it >7r by a single right clic and select the 47pen * Set4? to
change in the setup &indo& of the bloc that &ill open item 4 Accept herited
events4 from one to zero as sho&n in "ig% 1%%
-
8/16/2019 Introduction to ScicosLab-Scicos
7/33
"ig% 1%; Setting &indo& of bloc :S:7'E%
In this &ay on the top of the bloc :S:7'E appear a small red arro&;
8o!e the mouse on the output arro& of the bloc :L7:HDc and drag a line
>red? from here to the ne& red arro& input appeared abo!e the bloc :S:7'E;
"ig% 1%J; $iagram comprising the synchronization bloc :L7:H c%
To create segmented line, &hile you are tracing mae a single clic
&ith the mouse at the point &here you &ant to change direction%
+t this point, e/ecuting the command 4Simulate 3K run4 again, thegraph &ill sho& the sAuare &a!e desired;
J
-
8/16/2019 Introduction to ScicosLab-Scicos
8/33
"ig% 1%-; 5raph of the bloc : S:7'E resulting from the diagram of "ig% 1%J%
The bloc :L7:HDc force blocs connected to it to &or at the
freAuency set by him; double clicing &ith the left mouse button on this bloc
&ill open the &indo& for setting the options bloc :L7:HDc; the best &ay to
understand ho& it &ors is to do !arious tests and see &hat happens%
Try changing the 4'eriod4 by !arying it bet&een 0%001 and 1,
remembering that a greater freAuency of calculation does Not always mean
greater accuracy of simulation, but rather if it rises too high you ris
o!erloading the system &ith unnecessary calculations that in the best case do
not bring any benefit to the process of calculation and simulation%
Try also to replace the bloc 45E#DS94 &ith other blocs in the
4Soucres4 menu, for e/ample &ith the bloc 45E#SI#Df4 >to clear the bloc
45E#DS94 highlight it by clicing once &ith the right mouse button and
select B $elete 4;the cancellation of a bloc also results in the disappearance of
all the connections that this has &ith the other blocs in the chart?
-
-
8/16/2019 Introduction to ScicosLab-Scicos
9/33
"ig% 1%6; $iagram of "ig% 1%J &ith sine &a!e generator%
Lie the bloc 5E#DS9 >and many others?, the bloc 5E#SI#Df
allo&s you to set the desired properties >specifically amplitude, freAuency and
phase? opening the &indo& of setting the bloc properties by double clic of
the left mouse button on the bloc under consideration%
To set the duration of the simulation, in Scicos, on the menu
4Simulate 3K setup4 and change the 4"inal integration time4%
ith the 49ealtiming scaling4 option you can select the speed of the
simulation; 0 ma/imum speed permitted by the system in use, 0% graph
e!ol!es speed Doubled in respect to ho& &ould the real system simulated, 1
simulation e!ol!es in real time , 2 slo&ed by a factor of 0% and so on%
hile you are in a simulation, you can stop it using the 4Stop4
command in the menu bar at the top of the Scicos &indo&, you can then restart
the simulation from the stop point, restart from the origin or end it by the
4Simulate 3K run4 command%
To change the size of the a/es of the graph, open the settings &indo& of
the bloc :scope and edit the fields 4Gmin4, 4Gma/4 and 49efresh period4 that
indicates the length of the a/is of the graph; be careful that this does not
e/ceed the 4"inal integration time4 set in the parameters of the simulationC
To change the indications on the a/es instead, for e/ample to be able touse the chart created in a presentation or similar, clic the menu 4Edit 3K
"igures properties4 on the ScicosLab 5raphic &indo& ,and, in the &indo& of
options that &ill appear, change the 4Label4 field present in the 4Label
7ptions4 menu of the !arious tabs on the right under 47b=ect 'roperties4 menu
that appears &hen you select the 4+/es4 menu on the left% In this &ay is
possible to modify the instructions gi!en on the chart a/es, plus the title of the
graph itself contained in the field 4#ame of Scope >label M Id?%4 >see "ig% 1%?
This &ill be useful &hen &e &ill ha!e schemes &ith many graphics%
To sa!e a chart, the &indo& ScicosLab 5raphic, run the command
4Sa!e4 under the 4"ile4 menu in the top left, in this &ay >remembering to addthe e/tension 4%scg4 at the end of the name because this is not done
6
-
8/16/2019 Introduction to ScicosLab-Scicos
10/33
automatically by ScicosLab? you can sa!e the chart in format ScicosLab
5raphic so you can re3open later for further analysis >eg using the command
4Noom4, the t&o magnifiers present under the file menu, &hich allo& zoom in
on a specific section of the graph sho&n &ithin a rectangle that is created by
holding do&n the left mouse button and dragging &ithin the limits of the
graph?%To load a sa!ed chart, once opened a &indo& ScicosLab 5raphic, run
the command 4Edit 3K Erase figures4 and then 4"ile 3K Load4 loading the
desired graph% sing the 4"ile 3K E/port4 command you can sa!e graphics also
&ith other e/tensions >5I", .8', etc%?
The !ariables in use can be e/plicitly inserted bet&een the blocsBs
parameters of the scheme or be indicated indirectly through :7#TET of the
schema%
+s an e/ample consider the follo&ing scheme, composed of the blocs
already seen 5E#SI#Df, 5E#DS9, :L7:HDc and :S:7'E, and by the bloc '97$:T in the menu 4#onDlinear4;
"ig% 1%10; $iagram &ith magnitudes indicated by conte/t%%
The result of the simulation, after ha!ing properly set the calculation
time of the bloc :L7:HDc, is sho&n in "ig% 1%11%
Should be noted that to start a simulation is necessary that all the inputs
of the blocs included in the diagram are connected to a!oid the uncertainty of
their !alue, &hile the same is not binding as regards the outputs%%
10
-
8/16/2019 Introduction to ScicosLab-Scicos
11/33
"ig% 1%11; 5raph of the .loc : S:7'E resulting from the diagram of "ig% 1;10%
LetBs go bac no& to the Scicos graphic &indo& and go to the menu
4$iagram 3K :onte/t4 accessible from the menu bar at the top of the Scicos
&indo&; &ill open a te/t &indo& in &hich to enter the parameters of interest%
In the present case &e insert the follo&ing;
a = 2f1 = 2b = 3f2 = 4
Tab% 1%1; :onte/t of the diagram of "ig% 1;10%
:lic 47H4 at the bottom and go bac on the Scicos 5raphic; open the
setting &indo& of the bloc 5E#SI#Df &ith a double clic of the left mouse
button and insert in the 48agnitude4 field the !alue 4a4 defined in the conte/t
and in the field 4"reAuency >9ad * s? 4, the !alue4 f1 4as seen in "ig% 1;12%
11
-
8/16/2019 Introduction to ScicosLab-Scicos
12/33
"ig% 1%12; Setting &indo& of bloc 5E#SI#Df%
In this &ay the amplitude of the sine &a!e is set to the !alue indicated
by the !ariable 4a4 in the conte/t and the freAuency at the !alue f1% Then open
the settings &indo& of the bloc 5E#DS9 and modified !alues 48inimum!alue4 and 48a/imum !alue4 respecti!ely 43b4 and 4< b4, then set the field
4'eriod >sec?4 to the !alue 41 * f2 4%
Try again simulation to see the effects of the changes made to the chart%
The use of the conte/t in this &ay may seem superfluous, but &hen you
ha!e comple/ patterns, composed of many blocs nested one inside each other
in &hich the same !ariable may be repeated &ithin se!eral blocs, or in &hich
the same mathematical e/pression is repeated in more than one parameter, the
conte/t allo& to change this !ariable or this e/pression =ust one time &ithout
ha!ing to go and search for each bloc &here this is used at the ris of losing
some and allo&ing you to change the scheme faster and speed up the processtuning of the simulation itself%
.ut &hat does it mean to ha!e 4more blocs nested inside each other4O
hen you ha!e Pery large patterns, it is often possible to di!ide them into
functional sections that perform specific purposes, in this case to simplify the
understanding of the &hole schema is useful to enclose these sections in special
blocs, called 4superblocs4, so that the o!erall schema is composed of
functional superblocs connected to one another%
To create a superbloc, clic &ith the left mouse button on the Scicos
diagram in a blan space and, &ithout releasing it, dra& a rectangle that
includes all the blocs you &ant to be included in the superbloc% "or e/ample,
going bac to the first scheme, highlight +ll blocs e/cluding the bloc
:L7:HDc >you can also enter this one in the superbloc, but for our purposes
is better to not include it? in order to ha!e the situation sho&n in "ig% 1;1(%
12
-
8/16/2019 Introduction to ScicosLab-Scicos
13/33
"ig% 1%1(; Qighlight of the blocs of the diagram of "ig% 1;10 to be included in the superbloc%
Then clic &ith the right mouse button and select the 49egion to
superbloc4% e &ill ha!e a scheme similar to that sho&n in "ig% 1%1)%
"ig% 1%1); $iagram of "ig% 1;10 enclosed in a superbloc%
To obtain a more orderly pattern you can delete the red lin that
connects the bloc :L7:HDc to the superbloc created >5o on it &ith themouse and clic the right button and then select the 4$elete4? to mo!e the
1(
-
8/16/2019 Introduction to ScicosLab-Scicos
14/33
bloc nearest and reconnect the t&o in a less segmented &ay, &ithout losing
any functionality% In fact, by re3e/ecuting the command 4Simulate 3K run4 the
graph obtained &ill be identical to that obtained pre!iously%
$ouble3clicing &ith the left mouse button on the superbloc, or by
right clicing on it and selecting the 47pen * set4, you can open a secondscheme Scicos comprising the blocs contained in the superbloc%
The irregular red pentagon &ith in the number one represents the point
in &hich, &ithin the superbloc, enters the e/ternal control signal coming from
bloc :L7:HDc%
If the superbloc had more inputs, including of non3acti!ation type , &e
&ould ha!e had other pentagons >.lacs, for signals? &hile if the superbloc
had had some outputs &e &ould ha!e had some similar pentagonal blocs
indicating the outputs from the superbloc%
Gou can still add ne& inputs and outputs e!en &hen the superbloc has
already been created% To add an input to the superbloc, add the bloc 4I#Df4
a!ailable in the 4Sources4 menu
"ig% 1%1; I#Df bloc%
"or not changing too much our e/ample, open the setting &indo& of the
bloc '97$:T and change the field 4#umber of input or sign !ector4 from
4R1, 314 to 4R1@ 31@ 14 ; this adds an input to the multiplier bloc%
The operation that is performed on the inputs is a multiplication if the
input is mared &ith a 414 and a di!ision if 4314% The order in &hich the inputsappear outside the bloc are, from top to bottom, in the same order in &hich
they are listed in the input !ector from left to right%
In this &ay the pre!ious connections are unaffected, but due to the
different arrangement of the inputs on the side of the bloc '97$:T the
connection lines may no longer be straight%
To change the path of a connection mae a single clic o!er it &ith the
left mouse button; in the points &here the line changes direction appear some
&hite rectangles@ select them &ith the mouse pressing the left button and,
&ithout releasing it, is possible to mo!e the selected angle to the desired
position%
'lace the mouse on the tip of the bloc I#Df and dra& a line from this
to the ne& entrance to the bloc '97$:T% +dd to the diagram the bloc
47TDf4 a!ailable in the 4Sins4 menu
"ig% 1%1; 7TDf bloc%
'lace the mouse in the middle of the line =oining the bloc '97$:T
to the bloc :scope and, by double clicing &ith the left mouse button >or,
alternati!ely, by pressing the 4l4 >4Lin4? on the eyboard? to connect this line
1)
-
8/16/2019 Introduction to ScicosLab-Scicos
15/33
to the 7TDf bloc% The end result &ill be similar to that sho&n in "ig% 1%1J%
"ig% 1%1J; Inner !ie& of the superbloc of "ig% 1;1) &ith addition of inputs and outputs%
#o&, closing the Scicos 5raphic &indo& that encloses the blocs
&ithin the superbloc and returning bac to the main schema, the superbloc
&ill sho&, in addition to the acti!ation input, a signal input and an output, for
no& unused, as sho&n in "ig% 1%1-%
"ig% 1%1-; $iagram of "ig% 1;1) &ith input and output to the superbloc%
+dd in this scheme a bloc 4:7#STDm4 a!ailable in the menu
4Sources4 and another bloc '97$:T, then set the field 4:onstant4 of the bloc :7#STDm at t&o and connect it to the created input of the superbloc%
:onnect an e/tension from this ne& input to the input of the bloc '97$:T,
&hile the other input &ill carry the signal coming out of the superbloc% Then
add to the graph also the bloc 4:8S:7'E4 a!ailable in the menu 4Sins4,
&hich allo&s you to !ie& more than one graph on the same screen, and
acti!ate the input e!ent by setting to zero the !alue of the option 4+ccept
herited e!ents 0 * 1 4as done pre!iously for the bloc cscope%
.y default the bloc :8S:7'E accepts t&o inputs and then displays
t&o graphs; inside its settings &indo& you can still add ne& entries and then
display multiple graphs in one screen by setting appropriately these
parameters%
1
-
8/16/2019 Introduction to ScicosLab-Scicos
16/33
"ig% 1%16; Setting &indo& of the bloc : S:7'E >$efault settings?
To ha!e a greater number of inputs you ha!e to specify the type, for
each of them, in the parameter 4input port sizes4% +n 414, as &e shall see later,
corresponds to an input of real scalar type%
"or each input here declared must then be specified the size of the a/es of the
graph by the parameters 4Gmin !ector4, 4Gma/ !ector4 and 49efresh period4,
that ha!e the same meanings of the bloc :S:7'E%
9eturning to our e/ample, connect to the inputs of the bloc
:8S:7'E the output signal from the superbloc and that coming from bloc
'97$:T =ust added, as sho&n in "ig% 1%20%
"ig% 1%20; Scheme comprising the superbloc of "ig% 1%1)%
1
-
8/16/2019 Introduction to ScicosLab-Scicos
17/33
#o&, running the command 4Simulate 3K 9un4, &ill appear t&o screens
of ScicosLab 5raphic; one &ith a single graphic related to the bloc :scope
inside the superbloc and one &ith t&o charts relati!e to the bloc :8S:7'E
=ust entered%
+s for the bloc :scope, also for bloc :8S:7'E is possible to
change the labels displayed on the chart a/es through the settings in the menu4Edit 3K "igures properties4, &ith the difference that no& the menu 4+/es4
present in the area 47b=ects bro&ser 4at the left are t&o%
#ote that, apart from a scale factor related to the different settings of the
ma/imum !alues sho&n on the a/es, the graph produced from the bloc
:S:7'E and the first of the bloc :8S:7'E are identical because they are
related to the same signal%
hen you ha!e comple/ schemes is ad!isable to associate at the points
of e/it and entry of the superblocs some identification labels of the signals
that ha!e to be connected, to do this open the superbloc and position on the
I*7 blocs I#Df and 7TDf, and by changing the parameter 4bloc properties3K Identification4 associate a label to the bloc input >or output? to the
superbloc% In our e/ample &e can associate the tag 4in4 to the input bloc and
4out4 at the output bloc, and the t&o patterns so modified finally appear as in
"ig% 1%21 "ig% 1% 22%
"ig% 1%21; Inner !ie& of the Supercloc created &ith the addiction of input and output label%
"ig% 1%22; $iagram of "ig% 1;20 after addition of labels of input and output from the superbloc %
1J
-
8/16/2019 Introduction to ScicosLab-Scicos
18/33
-
8/16/2019 Introduction to ScicosLab-Scicos
19/33
Tae, from the menu Sources t&o bloc :7#STDm and the bloc
:L7:HDc, then, from the menu Sin, for a change, the bloc +""I:QDm,
then from the menu Linear, tae the bloc S88+TI7# and from the menu
7thers the cited bloc :.L7:H)%
$ouble clic &ith the left mouse button on the blocs :7#STDm and
in the settings &indo& that &ill open set the !alue of the field 4:onstant4respecti!ely to ten and si/%
7pen the settings &indo& of the bloc bloc S88+TI7# and
change the !alue of the 4#umber of input of sign !ector >of 1, 31?4 from 4R1@
314 to 4R1@ 14 ; this field indicates the operation that must be performed to the
corresponding input; 4 14 indicates that the input should be added to the other
and 4314 &hich must be subtracted% +dding other 414 or 4314 you can add more
inputs to the bloc% The order in &hich they &ill appear in the graphical
interface of the bloc is the same, top to bottom, of ho& they are defined here
from left to right%
If the number of inputs are considerable and the input arro&s result too
close, you can Change the size of the block >as of any other bloc? by clicing&ith the right mouse button on it and selecting 4.loc 'roperties 3 K 9esize 4%
Lea!ing aside momentarily blocing :.L7:H), &e conclude the
description of the scheme saying that blocing +""I:QDm simply ser!es to
display the numeric !alue of the input recei!ed; for proof that &e are going to
do the default settings are fine, ho&e!er the ad!ice is al&ays to do se!eral
attempts &ith !arious options to see the effects and ho& they &or
independently; the practice teaches better than a thousand &ords% In place of
this bloc &e could use the bloc :scope already seen, and as it is a static
system &e could ha!e omitted the bloc :L7:HDc, ho&e!er &e mo!e for&ard
&ith &hat positioned and realize the scheme of "ig% 1%2)%
"ig% 1%2); .loc :.L7:H) e!aluation scheme%
#o& &e ha!e to enter the code in the bloc :.L7:H); to mae it open
its settings &indo&, &hich &ill appear as in "ig% 1%2
16
-
8/16/2019 Introduction to ScicosLab-Scicos
20/33
"ig% 1%2; Setting &indo& of bloc :.L7:H)%
The 4Simulation function4 indicates the name of the function that the
bloc &ill perform; the suggestion is to set the same name of the computational
function choice, in this case, such as 4SAuare4%
The 4Imput port sizes4 indicates the number and the size of the bloc
inputs; the message 41, 14 indicates that &e ha!e an input scalar type >1 1?%
"or e/ample, if &e &anted t&o inputs of the same type &e &ould ha!e tochange this !oice by &riting 4R1, 1, 1, 14
The field 4Imput port type4 indicates the type of input to the bloc; the
number 1 indicates, as already seen, a real input% e shall see later ho& the
data types are associated &ith these numbers in Scicos, for no& lea!e it so%
The items 47utput port size4 and 47utput port type4 indicate the same
things respecti!ely of the items 4input port type4 and 4input port size4, but
related to the outputs%
The items 4Input e!ent port sizes4 and 4output e!ent port sizes4 indicate
the number and type of inputs and outputs of e!ents to the bloc >the 4red
arro&s4?% In our case &e do not need them so &e can lea!e these fields blan%
The item 4Initial continuous state4 indicates, for blocs that contain aninternal state, the !alue that this must ha!e at the beginning of the simulation%
20
-
8/16/2019 Introduction to ScicosLab-Scicos
21/33
The item refers to the case of a continuos time type function, for blocs
containing discrete time type functions &e &ill use the field 4Initial discrete
state4%
The meaning of the rest of the items on the menu, along &ith all the
others, is a!ailable by clicing on the 4Qelp4 button at the bottom left of the
setting &indo&% The 4Qelp4 menu is a!ailable for almost all the blocs in thesame &ay; by selecting the Qelp button at the bottom of the setting &indo&%
:ontinuing &ith our e/ample, then, the only change that &e mae to the
default settings is to set the title of the function in 4SAuare4% >9eplace, in the
field 4Simulation function4 of "ig% 2), the name 4toto4 &ith 4SAuare4?%
SubseAuently it &ill open a &indo& titled 4: function4 containing the basic
template of the computational function of Scicos, appearing as sho&n in Tab%
1%2%
#include
void Square(scicos_block block!in" fla$% / ini" / if (fla == 4$ % / ou"&u" co'&u"a"ion / else if(fla == 1$ %
/ endin /
else if (fla == )$ %
Tab% 1%2; .asic structure of a Scicos bloc computational function in :%
The Scicos blocs defined &ith a computational function in : are based
on the same basic structure through &hich you can access all the information of
the bloc under e/amination; inputs, outputs, parameters and internal states%
This structure is defined in the file 4scicosDbloc)%h4 and this e/plain
&hy &e need to include this header in all of the computational function &ritten
in :%
$uring the simulation, the computational function is called &ith a flag
&hich corresponds to the tas to be e/ecuted% 7n the first e/ecution thefunction is called &ith flag ) that performs the procedures of initialization of
!ariables of the bloc >of the input, state and output? and then proceed &ith the
flag 1 &hich corresponds to the computation of outputs based on the !alues
of inputs and of the state%
In case &e ha!e also state !ariables, subseAuently to the flag 1, the
computational function &ill acti!ate the function corresponding to the flag 2
in &hich are updated state !ariables defined &ithin the bloc%
hen the simulation ends, or in case of an error that reAuires abortion
of the simulation, the last flag to be called is the that addresses the procedures
for releasing the internal memory for any !ariable declared in the initialization
phase%
Is possible to acti!ate also other flags related to other tass for specific
21
-
8/16/2019 Introduction to ScicosLab-Scicos
22/33
operation, but for this e/ample they does not interest us and since they are
referred to ad!anced functionality their e/planation is left to more specific
tutorial%
To realize the function that calculate the sAuare root of the imput the
computational function must be modified as sho&n in Tab% 1%(%
#include #include
-
8/16/2019 Introduction to ScicosLab-Scicos
23/33
initialize t&o pointers to double type !ariables that represent the input
and the output of our bloc, &ith &hich are associated by the macros
45et9ealIn'ort'trs >bloc, 1?4 and 45et9eal7ut'ort'trs >bloc, 1?4%
In Tab% 1%) there are some of the most commonly used macros to define
the inputs and outputs for the most common simple cases;
acro re"urn escri&"ion
*e",n-or"-"rs(block!5$
void +e"urns a &oin"er "o "hein&u" &or" 656 s&ecified.
*e"+eal,n-or"-"rs(block! 5$
double +e"urns a &oin"er "o "hereal &ar" of "he in&u" &or"656 s&ecified
*e",'a,n-or"-"rs(bl
ock! 5$
double +e"urns a &oin"er "o "he
i'ainar7 &ar" of "he in&u"&or" 656 s&ecified
*e"in"8,n-or"-"rs(block! 5$
char +e"urns a &oin"er "o "hecharac"er "7&ed in "hein&u" &or" 656 s&ecified
*e"in"19,n-or"-"rs(block! 5$
shor" +e"urns a &oin"er "o "heda"a "7&e shor" on "hein&u" &or" 656 s&ecified
*e"in"32,n-or"-"rs(block! 5$
lon +e"urns a &oin"er "o "heda"a "7&e lon &resen" on"he in&u" &or" 656
s&ecified
*e"uin"8,n-or"-"rs(block! 5$
unsinedchar
+e"urns a &oin"er "o "heda"a "7&e unsined char&resen" on "he in&u" &or"656 s&ecified
*e"uin"19,n-or"-"rs(block! 5$
unsinedshor"
+e"urns a &oin"er "o "heda"a "7&e unsined shor"&resen" on "he in&u" &or"656 s&ecified
*e"uin"32,n-or"-"rs(
block! 5$
unsined
lon
+e"urns a &oin"er "o "he
da"a "7&e unsined lon&resen" on "he in&u" &or"656 s&ecified
*e"u"-or"-"rs(block! 5$
void +e"urns a &oin"er "o "heou"&u" &or" 656 s&ecified
*e"+ealu"-or"-"rs(block! 5$
double +e"urns a &oin"er "o "hereal &ar" of "he ou"&u"&or" 656 s&ecified
*e",'au"-or"-"rs(block! 5$
double +e"urns a &oin"er "o "hei'ainar7 &ar" of "heou"&u" &or" 656 s&ecified
*e"in"8u"-or"-"rs(block! 5$
char +e"urns a &oin"er "o "hecharac"er &resen" on "he
2(
-
8/16/2019 Introduction to ScicosLab-Scicos
24/33
ou"&u" &or" 656 s&ecified
*e"in"19u"-or"-"rs(block! 5$
shor" +e"urns a &oin"er "o "heda"a "7&e shor" &resen" on"he ou"&u" &or" 656s&ecified
*e"in"32u"-or"-"rs(block! 5$
lon +e"urns a &oin"er "o "heda"a "7&e lon &resen" on"he ou"&u" &or" 656s&ecified
*e"uin"8u"-or"-"rs(block! 5$
unsinedchar
+e"urns a &oin"er "o "heda"a "7&e unsined char&resen" on "he ou"&u" &or"656 s&ecified
*e"uin"19u"-or"-"rs(block! 5$
unsinedshor"
+e"urns a &oin"er "o "heda"a "7&e unsined shor"&resen" on "he ou"&u" &or"656 s&ecified
*e"uin"32u"-or"-"rs(block! 5$
unsinedlon
+e"urns a &oin"er "o "heda"a "7&e unsined lon&resen" on "he ou"&u" &or"656 s&ecified
Tab% 1%); List of the most used macros to define inputs and outputs computational function &ritten in :%
To clarify the relationship bet&een the data type and the name of the
macro, as &ell as the interpretation of the data types used in ScicosLab, &e can
refer to Tab% 1% that associates each data type e/pressed in the Scilab language
the corresponding : data type as &ell as the number &ith &hich this isrepresented in the declaration of the inputs and outputs in the Scicos blocs%
Scilab : Scicos block
real double 1
co'&le5 double 2
in"32 lon 3
in"19 shor" 4
in"8 char )
uin"32 unsined lon 9
uin"19 unsined shor" ;
uin"8 unsined char 8
Tab% 1%; 8atches bet&een !ariables in Scilab language and : language%
#o& it should be clear &hy in the items 4Imput port type4 and 47utput
port type4 in the settings &indo& of the bloc :.L7:H) &e placed the
number 1; >"ig%1%2)? in this &ay the inputs to our bloc &ill be defined as
49eal 4, that correspond to the double type in :%
:ontinuing &ith the analysis of the code, in the body of the 4SAuare4function &e meets a flo& control based on the s&itch statement; &e ha!e
2)
-
8/16/2019 Introduction to ScicosLab-Scicos
25/33
already described the meaning of the acti!ation flags in a computational
function in Scicos, in these fields &e are going to &rite the code &hich in each
case &ill be gradually carried out by the function%
In our case the initialization =ust reset the output >flag )?, &hile for the
computation of the outputs >flag 1? arises in the output !alue of the sAuare
root of the inputs calculated &ith the sArt >? function%The use of a !ector for to access at the output port >as for the input? in
this case represents a refinement more conceptual than practical; ha!ing an
output of scalar type &e could also assign the output !ia the pointer to the
name of the same;
out sArt>in?@
In the generic case in &hich &e ha!e a !ector type output, ho&e!er,
because the name of a !ector represents a pointer to the first element of the
!ector itself, to access the !arious elements of the !ector &e should direct them
in the same manner as &e do &ith !ectors, as done abo!e%
Il flag risulta !uoto in Auanto per la funzione SAuare non occorre
eseguire alcuna operazione specifica al termine della simulazione%
The flag is blan because the function SAuare do not reAuire any
specific action at the end of the simulation% +fter checing the !alidity of the
computational function by the usage of the bloc :.L7:H), to add a ne&
bloc to Scicos is necessary to &rite the interfacing function of the bloc%
The interfacing function, as mentioned, is &ritten in Scilab language
and unfortunately there arenBt many tutorials on ho& to proceed; I do not deny
that many of the statements herein ha!e been identified by trial and therefore
may be sub=ect to error, in &hich case I as forgi!eness in ad!ance, hoping that
they are eAually useful%
Qo&e!er, as for the computational function, also the interfacing
function is based on a basic template structure to be edited from time to time
depending on the bloc; for my e/perience, the seleton of a basic interfacing
function is reported in Tab% 1% >already adapted to our function SAuare?
func"ion 05!7!"7&=Square(ob!ar1!ar2$5=07=0"7&=0
selec" obcase &lo" "hen s"andard_dra(ar1$case e"in&u"s "hen 05!7!"7&=s"andard_in&u"s(ar1$case e"ou"&u"s "hen 05!7!"7&=s"andard_ou"&u"s(ar1$case e"oriin "hen 05!7=s"andard_oriin(ar1$
case se" "hen
5=ar1
case define "hen
2
-
8/16/2019 Introduction to ScicosLab-Scicos
26/33
-
8/16/2019 Introduction to ScicosLab-Scicos
27/33
indicates that the interfacin! function created is referred to a Scicos
bloc &hose model is defined by the function 4scicosDmodel >?4 >as it &as
necessary to insert the directi!e 4#include 4
at the beginning of the computational function?
The line
%odelsi% = list ()Square), *$
indicates that the name of the co%putational function called by the
bloc >SI8ulation function? is 4SAuare4 and is &ritten in :, then the bloc &ill
be lined to a file 4SAuare%c4%
+s mentioned, the co%putational function can be &ritten in different
languages; for e/ample, if &e had &ritten a co%putational function in Scilab
language &e &ould ha!e to &rite this line as 4model%sim list >4 SAuare 4, ?4
The ro&s
%odelin = ["]
%odelout = ["]
%odelbloc+type = c
indicate that our bloc &ill ha!e only one input >If &e had t&o &e
should ha!e &ritten 4model%in R1@ 14? and a single output >same as for the
inputs? and that, again, the co%putational function is &ritten in :%
The line
%odeldep'ut = [- t- f]
ser!es to indicate to the interfacin! function the beha!ior of
computational function !ia t&o .oolean !ariables; deptDu >the first parameter?
and depDt%
If the !ariable depDu >W t? is set to true the bloc is al&ays acti!e, ie the
outputs depend also from the time >hich does not mean they necessarily ha!e
to changeC? hile the !ariable depDt, if true, indicates that the bloc It has at
least one output &hose !alue depend only on the input !alues >&ithout
depending from internal states or parameters?%
The line
!r'i = [txt = [ Square ]&& xstrin!b (ori! ("$, .ri!inal (#$, txt, s/ ("$,
s/ (#$, fill $&]
represent the graphical aspect of the bloc; the te/t and the position of
the same, the size of the font etc %%%
The line
exprs = list ($
2J
-
8/16/2019 Introduction to ScicosLab-Scicos
28/33
contains an array of strings representing the default !alues displayed in
the &indo& setting of the bloc in the fields used for to set the parameters of
the bloc; our bloc has no parameter to initialize so the list is empty%
The line
x = standard'define ([# #], %odel, exprs, !r'i$
create through a standard function of Scilab the real bloc defining the
size and lining the directi!es gi!en in the !arious cases pre!iously setted >the
parameters in the field 4model%4 defined in the case BdefineB, the &indo&
setting defined in case BsetB, the graphical interface of the 4grDi4 etc%? for the
bloc to be fully functional%
7nce our co%putational function has been tested and created its
interfacin! function, is necessary to sa!e them for compiling and lining them
in Scilab%
To do it open notepad and copy the code of the co%putational function,
sa!ing it as a : file in a default folder >or create a ne& dedicated folder? and do
the same for the interfacin! function sa!ing it as a 4%sci4 file >4SAuare%sci4?%
Then open Scilab and set the &or directory in the folder &here you sa!ed the
file abo!e >using the 4:hange directory4 command using the button sho&ing
the yello& folder in the toolbar belo& the Scilab menu, bet&een the &ords 4
'references 4and4 :ontrol 4, or by the command4 cd >BpathB? 4?
7nce you positioned the &oring directory in the right folder you must
compile and lin the co%putational function by typing the follo&ing command;
libn=ilib'for'lin+()Square), )Squareo), [], )c), )0a+elib)$&
This command reAuire fi!e parameters; the first, 4SAuare4, indicates the
name of the function to be lined in Scilab, the second, 4SAuare%o4, the name of
the ob=ect that &ill be created by the compiling process of our source code, the
third is a list of e/ternal libraries needed to create the ob=ect >none in this case,
thatBs &hy the list is empty?, the fourth indicates that the code to be lined is
&ritten in : language and the fifth is the name of the default maefile%
7nce the command is e/ecuted, in the default folder &ill be created
se!en ne& files, including a 4loader%sce4 file; this ha!e to be e/ecuted in Scilab
by typing
exec loadersce&
and, after, compile the interfacing function by typing
exec Squaresci&
2-
-
8/16/2019 Introduction to ScicosLab-Scicos
29/33
"ig% 1%2; :ompilation and linage of computational and interfacing function in ScicosLab * Scicos%
#o& open Scicos and select the 4+dd ne& bloc4 option a!ailable
under the 4Edit4 menu as in "ig% 1%2J%
"ig% 1%2J; 'ath to add a ne& bloc to Scicos%
26
-
8/16/2019 Introduction to ScicosLab-Scicos
30/33
In the &indo& that &ill appear >see "ig% 1%2-? insert 4SAuare4
and type 474
"ig% 1%2-;Selection of the name of the ne& bloc that ha!e to be added io the scheme
If e!erything is done correctly &e &ill see in the scheme this our ne&
bloc, &hich &ill appear as in "ig% 1%26%
(0
-
8/16/2019 Introduction to ScicosLab-Scicos
31/33
"ig% 1%26; The ne& bloc created placed in Scicos%
To test the ne& bloc created &ith the ne& interfacing function &e =ust
ha!e to create a test scheme; the result should be identical to that obtained &ith
the :.L7:H) containing the co%putational function pre!iously tested%
"ig% 1%(0; Scicos scheme containing the ne& bloc created%
If during our &or on Scicos, &e needed to get bac in ScicosLab to
change the &oring directory, or perform calculations, &e can do it &ithoutclosing the Scicos &indo& using the 4+cti!ate ScicosLab indo&4 command
(1
-
8/16/2019 Introduction to ScicosLab-Scicos
32/33
located under the 4Tools4 menu@ once you finished the &or on ScicosLab you
can return on Scicos typing 4Scicos >?@4 or !ia the menu 4+pplications4 of
ScicosLab >or, more simply, clicing again on the &indo& Scicos?
(2
-
8/16/2019 Introduction to ScicosLab-Scicos
33/33
1%( .ibliography
R1 TQESIS, Ing Lorenzo Lombardi, )1%ple%enta/ione di al!orit%i di
controllo della traiettoria e di co%unica/ione per un robot a controllo re%oto e
relative verifiche speri%entali4, ltrasound and #$T labs, uni!ersity of "lorence, Italy, 2011%
R2 Stephen L% :ampbell, Xean3'hilippe :hancelier, and 9amine #iouhah
)0odelin! and Si%ulation in Scilab2Scicos with Scicos3ab **) , second
edition, Springer%
R( 'hil Schmidt, )4reatin! a 4 5unction 6loc+ in Scicos) , tutorial online,
http;**&&&%scicos%org*Scicos:.locTutorial%pdf
R) Scicos Team, )4onstructin! new bloc+s in Scicos) , tutorial online,
http;**&&&%scicos%org*"ormationDscicosDmarsD200-%pdf