1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
5 // This file is distributed under the same license as the Scilab package.
6 // =============================================================================
10 // Load and run a diagram that calls a Scilab macro (tkscaleblk.sci)
11 exec("SCI/modules/scicos/tests/unit_tests/bug_8348.cosf", -1);
12 // Call sciblk2 instead of sciblk4
13 scs_m.objs(1).model.sim = list("tkscaleblk", 3);
16 // Rewrite tkscaleblk so it minds sciblk2's syntax
17 wMode = warning("query");
19 function [xd, tvec, z, x, outptr] = tkscaleblk(flag, nevprt, t, x, z, rpar, ipar, inptr)
23 slider = get("-38f07e57:12bd41b596e:-7f2b#slider");
26 // Calculate real value
27 value = get(slider,"value") / rpar(3);
29 w = get("-38f07e57:12bd41b596e:-7f2b");
31 set(w, "info_message", string(value));
39 // If already exists (stopped) then reuse
40 f = get("-38f07e57:12bd41b596e:-7f2b");
45 f = figure("Figure_name", "TK Source: " + "", ...
46 "dockable", "off", ...
47 "infobar_visible" , "on", ...
48 "toolbar", "none", ...
49 "menubar_visible", "off", ...
50 "menubar", "none", ...
51 "backgroundcolor", [1 1 1], ...
52 "default_axes", "off", ...
53 "figure_size", [180 350], ...
54 "layout", "border", ...
55 "figure_position", [40 40], ...
56 "Tag", "-38f07e57:12bd41b596e:-7f2b");
58 frame_slider = uicontrol(f, ...
60 "constraints", createConstraints("border", "left", [180, 0]), ...
61 "border", createBorder("line", "lightGray", 1), ...
62 "backgroundcolor", [1 1 1], ...
67 initial = mean(bounds);
68 uicontrol(frame_slider, ...
69 "Style", "slider", ...
70 "Tag", "-38f07e57:12bd41b596e:-7f2b#slider", ...
74 "Position", [0 0 10 20], ...
75 "SliderStep", [rpar(3) 2*rpar(3)]);
77 frame_label = uicontrol(frame_slider, ...
79 "constraints", createConstraints("border", "right"), ...
80 "backgroundcolor", [1 1 1], ...
84 labels = string([bounds(2) ; ...
85 mean([bounds(2) initial]) ; ...
87 mean([bounds(1) initial]) ; ...
89 labels = "<html>" + strcat(labels, "<br /><br /><br />") + "</html>";
91 uicontrol(frame_label, ...
93 "String", labels(1), ...
94 "FontWeight", "bold", ...
95 "backgroundcolor", [1 1 1]);
97 // Update default value
98 outptr = list(initial / rpar(3));
101 f = get("-38f07e57:12bd41b596e:-7f2b");
111 cpr = scicos_simulate(scs_m);
119 // Check the sensitive value of the continuous state
120 assert_checkalmostequal(list2vec(cpr(2)(2)(9)), cpr229);
123 // Load and run a diagram that calls a Scilab macro (anim_pen.sci)
124 exec("SCI/modules/scicos/tests/unit_tests/pendulum_anim5.cosf", -1);
125 // Call sciblk2 instead of sciblk4
126 scs_m.objs(8).model.sim = list("anim_pen", 3);
128 // Rewrite anim_pen so it minds sciblk2's syntax
129 wMode = warning("query");
131 function [xd, tvec, z, x, outptr] = anim_pen(flag, nevprt, t, x, z, rpar, ipar, inptr)
144 set("figure_style","new")
148 Axe.data_bounds=rpar(4:7)
151 S=[cos(phi),-sin(phi);sin(phi),cos(phi)]
152 XY=S*[rpar(4),rpar(5);-csiz,-csiz]
153 gca().foreground = 3;
154 xsegs(XY(1,:),XY(2,:)-rcirc)
162 XY=S*[x1 x2 x2 x1 x1;y1,y1,y2,y2,y1]
163 gca().foreground = 5;
164 xfpoly(XY(1,:),XY(2,:))// cart
165 gca().foreground = 2;
166 xfarc(XY(1,1),XY(2,1),rcirc,rcirc,0,360*64) //wheel
167 xfarc(XY(1,2),XY(2,2),rcirc,rcirc,0,360*64) //wheel
169 XY=S*[xTemp,xTemp+plen*sin(theta);0,0+plen*cos(theta)]//pendulum
170 xsegs(XY(1,:),XY(2,:))
178 XY=Axe.children(4).data'+ [cos(phi)*(xTemp-xold);sin(phi)*(xTemp-xold)]*ones(1,5)
179 Axe.children(4).data=XY'
181 Axe.children(3).data(1)=XY(1,1)
182 Axe.children(3).data(2)=XY(2,1)
183 XY=Axe.children(4).data'+ [cos(phi)*(xTemp-xold-rcirc);sin(phi)*(xTemp-xold-rcirc)]*ones(1,5)
184 Axe.children(2).data(1)=XY(1,2)
185 Axe.children(2).data(2)=XY(2,2)
188 XY=[x1,x1+plen*sin(theta);y1,y1+plen*cos(theta)]
189 Axe.children(1).data=XY'
199 cpr = scicos_simulate(scs_m);
202 -0.00000010072892435; ...
203 -0.0000000093251865; ...
204 12.731754622278423; ...
205 0.00000000775393652; ...
206 -0.00000007274473145; ...
207 0.00000008598899216; ...
208 -0.00000000636625628; ...
209 -0.00000010072892435;
210 -0.0000000093251865; ...
211 -0.00000100269157242; ...
212 12.7317556249699955; ];
214 // Check the sensitive value of the continuous state
215 assert_checkalmostequal(list2vec(cpr(2)(2)(9)), cpr229, [], 1e9);