]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.tutorial/scl/Tutorial/3.03 (Exercise) Controller tuning.md
Merge "Fix to OrderedSetTemplate, preference for autocompletion"
[simantics/platform.git] / bundles / org.simantics.scl.tutorial / scl / Tutorial / 3.03 (Exercise) Controller tuning.md
1 ## Controller tuning exercise\r
2 \r
3 ### Step 1\r
4 \r
5 Load the model [ControllerTuning.apros](http://www.simantics.org/~niemisto/SCL20150513/ControllerTuning.apros).\r
6 \r
7 Run a sequence from SCL console that first sets the value of the set point (`SP01#SP_VALUE`) to 110,\r
8 then waits 10 seconds and stops.\r
9 \r
10 ::value[Apros/Sequences/runSequence,Simantics/Sequences/execute,Simantics/Sequences/setVar,Simantics/Sequences/wait,Simantics/Sequences/stop]\r
11 \r
12 Open the chart and examine the results.\r
13 \r
14 ### Step 2\r
15 \r
16 Put your sequence inside a function that takes the controller parameters\r
17 `PIC01#PI_GAIN` and `PIC01#PI_INTEGRATION_TIME` as a parameter and sets\r
18 them at the same time with the set point. It should also load the IC\r
19 before simulation with command\r
20 \r
21     loadInitialCondition (syncRead $ \_ -> fromResource $ relativeResource currentModel "/Initial%20Condition")\r
22 \r
23 ### Step 3\r
24 \r
25 Create a separate simulation thread that computes the last time the flow speed\r
26 `XA01#ANALOG_VALUE` is within 1 from the set point value 110. Your function\r
27 should return that value. The following functions are useful for that:   \r
28 \r
29 ::value[Simantics/Sequences/getVar]\r
30 ::value[Simantics/Sequences/fork]\r
31 ::value[Prelude/repeatForever]\r
32 \r
33 ### Step 4\r
34 \r
35 Try the optimization routine\r
36 \r
37 ::value[Simantics/Newuoa/bobyqa]\r
38 \r
39 with function\r
40 \r
41     f [x,y] = let dx=x-1 ; dy=y-2 in dx*dx + dy*dy\r
42 \r
43 ### Step 5\r
44 \r
45 Optimize the controller parameters using the objective function you created in step 3.\r
46 \r