GeckoSCRIPT PDF
GeckoSCRIPT PDF
Introduction
To open the GeckoSCRIPT tool, start The top field, Imports, allows you to im-
GeckoCIRCUITS, and click on the GECKO port any Java class or package for use
menu (furthest to the right on the menu within your script (e.g. java.util). Therefore
bar). There you will find a menu item the entire Java API is available for use.
called GeckoSCRIPT.
The grey non-editable upper-right window mostly identical to the names of the para-
lists the GeckoSCRIPT-specific functions meters used in the dialog boxes.
which are available for modifying the
parameters of an element of a model and To simplify the writing of scripts, Gecko-
for controlling the execution of the simu- SCRIPT provides a listing of all blocks
lation of the model. A detailed description available in a model, their names, and for
of each function with a simple example of each type of block, the accessible para-
its use is available by clicking on the meters and outputs, along with their de-
Details button. scription. To show this listing, click on the
Available Blocks button. As our model is
currently blank, the list is empty.
Now, go back to the GeckoCIRCUITS main To see a listing of available outputs, add a
window, and construct a simple RC circuit voltage measurement block to the model
schematic: (e.g. measuring the voltage across the
resistor). Click the ‘Refresh’ button again.
You will see a list of output names and
their description.
setParameter("R.1","R",50);
setParameter("C.1","C",1e-6);
writeOutputLn("Hello World!");
Now let’s run the simple script written will demonstrate its functionality using a
previously. Click on the Run button. You simple example where the controller
will notice that the GeckoSCRIPT window parameters for a buck converter are tuned
automatically switches to the Script to achieve a stable voltage regulation.
Output tab. This is where any output
written using the writeOutput or the
writeOutputLn functions will be displayed.
The text field under this tab now displays
the phrase Hello World!, as was specified
in the script. Please go back to the Gecko-
CIRCUITS main window. You will notice
that the resistor and capacitor parameter
values have been changed to those speci-
fied in the script. GeckoSCRIPT has per-
formed as instructed.
Included with this tutorial is a file called and the period of this oscillation, denoted
buck_control.ipes Open this model in Tu, are then used to calculate the three
GeckoCIRCUITS. PID controller coefficients – the
It contains a circuit with a simple Buck proportional gain Kp, integral gain Ki and
converter, together with a control loop differential gain Kd.
modelling a PID controller using the PI
and PD control blocks available in Gecko- Now this of course can be done by the
CIRCUITS. The proportional gain is set to user manually: simulate, increase the
1, and the integral and differential gains to proportional gain in the model’s PI block,
zero, i.e. the loop is uncompensated. Via simulate, and repeat until Ku and Tu are
the constant block, the output reference is found. A much more convenient and faster
set to 6 V, and the input voltage is 12 V. If way to do it is to use GeckoSCRIPT.
you run the simulation and open the
uppermost SCOPE showing the output vol- To facilitate this, a Java block is included
tage, you will see the output voltage is 3 V. in the model that monitors the output
Therefore, a proper controller giving voltage, and determines whether it
required output voltage regulation must oscillates and constant frequency and
be designed. amplitude. The outputs of the Java block
are the amplitude of oscillation, a digital
A common approach to PID controller signal indicating (1/0 i.e. true/false)
tuning is the Ziegler-Nichols method. In whether the amplitude is constant, the
this method, with the other gains set to period of oscillation and a digital signal
zero, the proportional gain is increased indicating whether the period is constant.
until the output of the control loop – in this
case the output voltage of the converter –
oscillates at a constant frequency and Controller tuning example
amplitude. This ultimate gain, denoted Ku, Open buck converter model
Ziegler-Nichols tuning procedure
Now open GeckoSCRIPT. A script imple- The first part of the script code initializes
menting the Ziegler-Nichols algorithm the most important model values. Using
has already been included with the model. the setParameter function, the inductance
and capacitance values of the converter
output LC filter are set, the output voltage
reference, and the initial PID coefficents.
In the field declarations we have declared On line 5 we set the switching frequency of
all the variables we need for the algo- the converter, by setting the frequency
rithm: the PID controller coefficients, the parameter of the signal generator block
ultimate gain and period, Boolean flags for that creates a sawtooth waveform used to
whether the amplitude and frequency are generate a pulse-width modulated signal
constant, and a flag that tells us when to for the converter main switch.
stop searching.
The following code increases the pro- and the since the number of outputs can
portional gain in a loop while running the vary, the outputs are simply designated
simulation and checking whether Ku has numerically from top to bottom, starting
been found. from zero. Note that the names are how-
ever still Strings, not numbers. In this
case we are interested in output “1” and
“3”.
Then a message is displayed in the script Now that you have examined and under-
output that the tuning process is finished, stood the script you can compile it.
and the flag to exit the loop is set. Compilation should finish successfully.
If the amplitude and period are not both Keeping the SCOPE which displays the
constant, we increase the proportional output voltage open, run the script. You
gain by 0.1, set this in the model as the will see the output of the script change as
new proportional gain, and continue the loop is executed, and you will also see
running the loop. the model re-simulated (with different
results, as the gain is changing) with each
Once the loop finishes, the last part of the loop iteration.
code calculates the PID coefficients
according to the Ziegler-Nichols PID
tuning rule, and sets these parameters in
the PI and PD control blocks in the model.
So far we have shown how to write simu- This tutorial was implemented and tested
lation control scripts using the scripting on MATLAB release 2010b. Java 1.6 has to
environment provided within Gecko- be the actual Java version in the MATLAB
CIRCUITS. However, sometimes coupling environment. Before proceeding make
a GeckoCIRCUITS simulation with another sure that Java 1.6 is the actual Java
simulation or computation program is version in the MATLAB environment:
desirable.
>> version -java
All of functions for model manipulation
ans =
and simulation control available in Gecko- Java 1.6.0 with Sun
SCRIPT within GeckoCIRCUITS, some of Microsystems Inc. Java
which were described previously, are also HotSpot(TM) Client VM mixed
available for control of GeckoCIRCUITS mode
®
through and within MATLAB .
This allows a user to load GeckoCIRCUITS In the Help Directory of MATLAB you will
into the MATLAB environment, control a find a description of how to install a newer
simulation from the MATLAB environment Java version if necessary.
(from the command line or an m-file), to
use MATLAB functions to calculate
parameters for the simulation, and to plot
simulation results – or the results of
several simulations – within MATLAB.
In order to use GeckoCIRCUITS in MAT- You can view and undo your changes to
LAB, you must first tell MATLAB of its the dynamic class path employing the
location. If you are using a Windows commands
machine and have installed GeckoCIR-
CUITS into a directory called >> javaclasspath
C:/GeckoCIRCUITS/, then the path to the >> javarmpath
GeckoCIRCUITS simulator is
When you have set the static class path by
C:/GeckoCIRCUITS/GeckoCIRCUITS.jar editing classpath.txt, then you must re-
start MATLAB to apply the changes. The
To add this to MATLAB’s class path, dynamic class path setting, however, will
append the above line to MATLAB’s only persist during your current MATLAB
classpath.txt file. You can do this within session.
MATLAB by typing
Please save your simulation model and
>> edit classpath.txt close GeckoCIRCUITS now.
The functions for controlling a Gecko- This will open the GeckoCIRCUITS main
CIRCUITS simulation and model from window. You will also see this message
MATLAB are identical to those listed in the displayed in the MATLAB command line:
GeckoSCRIPT main window and function
in the same way. The functions for MAT- Starting GeckoCIRCUITS in OS JVM
(outside MATLAB)...
LAB are located in a Java package called GeckoCIRCUITS should now be running
gecko.GeckoRemote.*. outside of MATLAB at port 43035
You are now connected to the
GeckoCIRCUITS instance at port
To avoid calling the functions always with 43035
the full package name, import this
package into MATLAB with the command If an error message is displayed instead,
the port is already being used or is
>> import('gecko.GeckoRemote.*') blocked. Try then another port number.
On most machines, the default port 43035
As of version 1.6, communication between should be free.
MATLAB and GeckoCIRCUITS is done
using network ports on the local machine. It is also possible that any firewall
This allows GeckoCIRCUITS to run outside program you have installed on your
of MATLAB, in your operating system’s computer will complain about
Java Virtual Machine (JVM), rather than unauthorized access from MATLAB or the
MATLAB’s, while still allowing you to Java Runtime Environment. On Windows
control simulations and access their machines for example, if prompted by a
results from MATLAB. message from the firewall, click “Allow
Access” in either case. Even if you do not
As a result, besides the list of functions have administrative rights to do this,
you have already seen in GeckoSCRIPT, ignoring such messages (i.e. clicking
for control from MATLAB there are “Cancel” in this example) should not be a
several more functions necessary. One of problem, since both MATLAB and
them is startGui(int port). This function GeckoCIRCUITS are running on the local
starts a new instance of GeckoCIRCUITS, machine.
enabled for remote access, from MATLAB.
You must specify a free network port NOTE: If you are already familiar with
number. If you do not, GeckoCIRCUITS will GeckoCIRCUITS and MATLAB, and have
previously used the old package
attempt to use the default port, 43035.
GeckoExternal, see Appendix for instructions
Therefore, before you proceed, type into
on migrating to GeckoRemote .
the MATLAB command line
Now, let’s go back to our simulation task. You can now verify that the converter is
again not regulating the output voltage
Open the model you previously modified properly by typing into MATLAB
and saved, buck_control.ipes. You can do
this from MATLAB by typing >> runSimulation()
Included with this tutorial is a file called Now let’s take a look at the m-file. Up to
buck_control_tuning.m, which you can line 21, the script does the same as
open from MATLAB. It is an m-file that previously, only with MATLAB syntax
performs the Ziegler-Nichols tuning, just rather than Java. Now look at lines 21 to
like the script we previously analysed and 24. In order to control a simulation step-
ran from within GeckoCIRCUITS. by-step, we first must initialize it and for
this we use the function initSimulation.
There are however, some differences. If
you look at the simulation we performed
during the tuning process earlier, you will
notice that the simulation was performed
each time for 0.02 seconds. However, we
can tell whether we have reached Ku
much earlier than that. We only need to
see a few cycles. Wouldn’t it be better if We define a step-width dt and simulation
we could run a part of the simulation, time tEnd and pass these as arguments to
check the results, then change the para- the function. We also define a variable to
meters if necessary, and continue, and so keep track of how much of the simulation
on? time we’ve covered.
There are certain GeckoSCRIPT functions You can also call initSimulation() without
which allow for just that. arguments. In that case the simulation is
initialized with parameters specified from
You can use GeckoSCRIPT functions to within GeckoCIRCUITS, just like when you
simulate one single simulation step at a call runSimulation().
time, so simulate several steps at a time,
and to simulate a specified certain time
(e.g. 10 microseconds).
Now let’s take a look at the loop which Then we must tell GeckoCIRCUITS that the
performs the tuning. Apart from the MAT- simulation is finished. We do this in line 55
LAB / Java syntax differences, you will by calling endSimulation().
notice that instead of using the
runSimulation() function as before, which The rest of the script is the same as
runs the entire simulation up to tEnd, we before within the Java version.
are using simulateTime.
Note that instead of using simulateTime,
you can use simulateSteps, and specify
the exact number of steps to simulate
rather than the time to simulate.
Gecko-Simulations AG
Physikstrasse 3, H13
CH-8092 Zurich, Switzerland
www.gecko-simulations.com
[email protected]
Summary
Contact information
APPENDIX
Switching from GeckoExternal to
GeckoRemote for MATLAB Use
Prior to GeckoCIRCUITS version 1.6, the The main advantages are that
package gecko.GeckoExternal was used
for controlling GeckoCIRCUITS from 1) You can now close GeckoCIRCUITS,
MATLAB. even if when started from MATLAB,
without having to close all of MATLAB;
As of version 1.6, this API is deprecated –
please do not use it anymore. Switch to 2) You don’t have to worry about memory
using gecko.GeckoRemote instead. allocation for Java inside MATLAB;
GeckoExternal remains usable for 3) You will not have problems with
purposes of backwards compatibility. compiling your simulation models’ Java
using it, it will display a message that it is blocks when running GeckoCIRCUITS
deprecated and recommend moving to from MATLAB. This was a serious
GeckoRemote, but otherwise it will work problem experienced by many users.
as before. Therefore your old MATLAB
scripts, written before version 1.6, are still
usable as they are. From a user’s point of view, the changes
are minor and easy to make. In your old
However, GeckoExternal is no longer scripts, simply change the line
maintained or supported. Therefore you import(‘gecko.GeckoExternal.*’)
are strongly urged to switch to using to
GeckoRemote in your MATLAB scripts. import('gecko.GeckoRemote.*')
and everything else should work without
The main reason for the switch is that modifications. Please note that now you
GeckoRemote enables GeckoCIRCUITS to must be mindful of port numbers in some
run in your operating system’s Java cases – please read the section of this
Virtual Machine (JVM) rather than tutorial dealing with setting up the
MATLAB’s JVM. GeckoCIRCUITS-MATLAB link.