Gecko-Research Scripting Tutorial
Gecko-Research Scripting Tutorial
Introduction
To open the GeckoSCRIPT tool, start Gecko- The top field, Imports, allows you to import
CIRCUITS, and click on the GECKO menu any Java class or package for use within your
(furthest to the right on the menu bar). There script (e.g. java.util). Therefore the entire Java
you will find a menu item called API is available for use.
GeckoSCRIPT.
The grey non-editable upper-right window To simplify the writing of scripts, Gecko-
lists the GeckoSCRIPT-specific functions SCRIPT provides a listing of all blocks
which are available for modifying the available in a model, their names, and for each
parameters of an element of a model and for type of block, the accessible parameters and
controlling the execution of the simulation of outputs, along with their description. To show
the model. A detailed description of each this listing, click on the Available Blocks
function with a simple example of its use is button. As our model is currently blank, the
available by clicking on the Details button. list is empty.
Now, go back to the GeckoCIRCUITS main Click the ‘Refresh’ button again. You will see
window, and construct a simple RC circuit a list of output names and their description.
schematic:
Getting started
To see a listing of available
GeckoSCRIPT-specific outputs,
functions foradd a
voltage measurement
manipulating blockand
model blocks to the model (e.g.
controlling
measuring the
the simulation voltage across the resistor).
setParameter("R.1","R",50);
setParameter("C.1","C",1e-6);
writeOutputLn("Hello World!");
Included with this tutorial is a file called Now this of course can be done by the user
buck_control.ipes Open this model in Gecko- manually: simulate, increase the proportional
CIRCUITS. gain in the model’s PI block, simulate, and
It contains a circuit with a simple Buck repeat until Ku and Tu are found. A much
converter, together with a control loop more convenient and faster way to do it is to
modelling a PID controller using the PI and use GeckoSCRIPT.
PD control blocks available in Gecko-
CIRCUITS. The proportional gain is set to 1, To facilitate this, a Java block is included in
and the integral and differential gains to zero, the model that monitors the output voltage,
i.e. the loop is uncompensated. Via the and determines whether it oscillates and
constant block, the output reference is set to 6 constant frequency and amplitude. The outputs
V, and the input voltage is 12 V. If you run the of the Java block are the amplitude of
simulation and open the uppermost SCOPE oscillation, a digital signal indicating (1/0 i.e.
showing the output voltage, you will see the true/false) whether the amplitude is constant,
output voltage is 3 V. Therefore, a proper the period of oscillation and a digital signal
controller giving required output voltage indicating whether the period is constant.
regulation must be designed.
Now open GeckoSCRIPT. A script imple- filter are set, the output voltage reference, and
menting the Ziegler-Nichols algorithm has the initial PID coefficents.
already been included with the model.
The following code increases the proportional In the next part of the code, if the amplitude
gain in a loop while running the simulation and period of oscillation are indeed constant,
and checking whether Ku has been found. we retrieve the observed period of oscillation
Tu from the simulation – in this case output
“2” of the Java block – and the ultimate gain
Ku, which is parameter “r0” of the PI control
block.
Then a message is displayed in the script Keeping the SCOPE which displays the output
output that the tuning process is finished, and voltage open, run the script. You will see the
the flag to exit the loop is set. output of the script change as the loop is
executed, and you will also see the model re-
If the amplitude and period are not both simulated (with different results, as the gain is
constant, we increase the proportional gain by changing) with each loop iteration.
0.1, set this in the model as the new
proportional gain, and continue running the
loop.
All of functions for model manipulation and In the Help Directory of MATLAB you will
simulation control available in GeckoSCRIPT find a description of how to install a newer
within GeckoCIRCUITS, some of which were Java version if necessary.
described previously, are also available for
control of GeckoCIRCUITS through and
within MATLAB®.
In order to use GeckoCIRCUITS in MAT- MATLAB to apply the changes. The dynamic
LAB, you must first tell MATLAB of its class path setting, however, will only persist
location. If you are using a Windows machine during your current MATLAB session.
and have installed GeckoCIRCUITS into a
directory called C:/GeckoCIRCUITS/, then the Please save your simulation model and close
path to the GeckoCIRCUITS simulator is GeckoCIRCUITS now.
C:/GeckoCIRCUITS/GeckoCIRCUITS.jar
>> javaclasspath
>> javarmpath Controlling GeckoCIRCUITS in
MATLAB using GeckoSCRIPT functions
When you have set the static class path by Add path to GeckoCIRCUITS
editing classpath.txt, then you must restart
The functions for controlling a Gecko- GeckoCIRCUITS should now be running outside of
CIRCUITS simulation and model from MATLAB at port 43035
MATLAB are identical to those listed in the You are now connected to the GeckoCIRCUITS
instance at port 43035
GeckoSCRIPT main window and function in
the same way. The functions for MATLAB are
If an error message is displayed instead, the
located in a Java package called
port is already being used or is blocked. Try
gecko.GeckoRemote.*.
then another port number. On most machines,
the default port 43035 should be free.
To avoid calling the functions always with the
full package name, import this package into
It is also possible that any firewall program
MATLAB with the command
you have installed on your computer will
complain about unauthorized access from
>> import('gecko.GeckoRemote.*')
MATLAB or the Java Runtime Environment.
On Windows machines for example, if
As of version 1.6, communication between
prompted by a message from the firewall, click
MATLAB and GeckoCIRCUITS is done using
“Allow Access” in either case. Even if you do
network ports on the local machine. This
not have administrative rights to do this,
allows GeckoCIRCUITS to run outside of
ignoring such messages (i.e. clicking “Cancel”
MATLAB, in your operating system’s Java
in this example) should not be a problem,
Virtual Machine (JVM), rather than
since both MATLAB and GeckoCIRCUITS
MATLAB’s, while still allowing you to
are running on the local machine.
control simulations and access their results
from MATLAB. NOTE: If you are already familiar with
GeckoCIRCUITS and MATLAB, and have
As a result, besides the list of functions you previously used the old package GeckoExternal,
have already seen in GeckoSCRIPT, for see Appendix for instructions on migrating to
control from MATLAB there are several more GeckoRemote.
functions necessary. One of them is
startGui(int port). This function starts a new
instance of GeckoCIRCUITS, enabled for
remote access, from MATLAB. You must
specify a free network port number. If you do
not, GeckoCIRCUITS will attempt to use the If problems with the firewall persist, please
default port, 43035. Therefore, before you contact your System Administrator and ask
proceed, type into the MATLAB command him to allow MATLAB and Java access to the
line network ports. Ask for advice on which
network ports to use.
>> startGui()
Now, it is not necessary to start
This will open the GeckoCIRCUITS main GeckoCIRCUITS from inside MATLAB using
window. You will also see this message the startGui() function. You can connect from
displayed in the MATLAB command line: Controlling
MATLAB toGeckoCIRCUITS
GeckoCIRCUITS in if it is already
MATLAB using GeckoSCRIPT
running, provided it is enabled for remote
Starting GeckoCIRCUITS in OS JVM (outside Import
access.GeckoRemote
To try this out,package
let us first disconnect
MATLAB)... startGui()
>> openFile('buck_control.ipes')
>> runSimulation()
Controlling GeckoCIRCUITS in
MATLAB using GeckoSCRIPT
Using GeckoSCRIPT functions from the
MATLAB command line
There are however, some differences. If you We define a step-width dt and simulation time
look at the simulation we performed during the tEnd and pass these as arguments to the
tuning process earlier, you will notice that the function. We also define a variable to keep
simulation was performed each time for 0.02 track of how much of the simulation time
seconds. However, we can tell whether we we’ve covered.
have reached Ku much earlier than that. We
only need to see a few cycles. Wouldn’t it be You can also call initSimulation() without
better if we could run a part of the simulation, arguments. In that case the simulation is
check the results, then change the parameters initialized with parameters specified from
if necessary, and continue, and so on? within GeckoCIRCUITS, just like when you
call runSimulation().
There are certain GeckoSCRIPT functions
which allow for just that.
www.gecko-research.com
andreas.muesing@gecko-research.com
Document version: July 2012
APPENDIX
Switching from GeckoExternal to
GeckoRemote for MATLAB Use
As of version 1.6, this API is deprecated – from MATLAB. This was a serious
please do not use it anymore. Switch to using problem experienced by many users.
gecko.GeckoRemote instead.
GeckoExternal remains usable for purposes of From a user’s point of view, the changes are
backwards compatibility. using it, it will minor and easy to make. In your old scripts,
display a message that it is deprecated and simply change the line
recommend moving to GeckoRemote, but import(‘gecko.GeckoExternal.*’)
otherwise it will work as before. Therefore to
your old MATLAB scripts, written before import('gecko.GeckoRemote.*')
version 1.6, are still usable as they are. and everything else should work without
modifications. Please note that now you must
However, GeckoExternal is no longer be mindful of port numbers in some cases –
maintained or supported. Therefore you are please read the section of this tutorial dealing
strongly urged to switch to using with setting up the GeckoCIRCUITS-
GeckoRemote in your MATLAB scripts. MATLAB link.