Scilab xcos: run a script or define a function in Simulation -> Set Context

909 Views Asked by At

I have my own function which I want to use via scifunc_block_m block. The function is defined in an .sci file, as suggested in this answer. Running the script from the scilab console before starting the simulation works fine. However, if I call exec() of this very .sci under xcos Simulation -> Set Context instead, the function seem to remain unknown in xcos. Am I missing something about the context setting?

xcos Set Context

It began with a function typed into scifunc_block_m or expression block. However,

  • I didn't want to make the block big and was unable to use .. to split the function definition over multiple lines to prevent the text spilling over the block boundaries.
  • The function will be used several times, I wanted a single definition vs copy&paste.

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER
  1. For the Set Context part: I guess that you must specify the absolute path of fader_func.sci, either directly in the set Context box, or through a variable defined in the console:
--> fader_PATH = "C:\the\path\fader_func.sci"
// Then in the Context box;
exec(fader_PATH,-1);

Or directly in the Context box (far less portable solution):

exec("C:\the\path\fader_func.sci", -1);
  1. about scifunc_block_m input Continuation dots are unlikely supported. Instead, have you tried to explicitly split any long instruction in several shorter ones?
tmp = tanh((u3-u1+u2/2)/0.25/abs(u2))
y1 = 0.5 + sign(u2)*tmp/2