02224 Modelling and Analysis of Real-Time Systems - Guide to Simulting your Program
02224 Modelling and Analysis of Real-Time Systems Spring 2024
Guide to Simulting your Program
When you have implemented your control strategy in Java, you may like
to debug it on a simulator of the LEGO contruction, perhaps before
testing it on the physical setup (separate instructions will appear
later).
Note that you should not use the simulator for verifying your control
strategy (this must be done at the UPPAAL level). Use it only to
discover flaws in your Java coding.
The Simulator
The simulator is given as Java package bagsortsim which is
accessed by the control program through classes corresponding to those
of the Lejos RCX environment (package
josx.platform.rcx
on
lejos.sourceforge.net)
Only the classes and methods described in the assignment paper are
fully implemented.
Other classes
are not fully
implemented or not provided at all as they are not strictly necessary for the
proper operation of the control program.
For convenience, the simulator also provides the
josx.util.Timer class which may be used for periodic timing.
The Simulator is set up and controlled by the methods:
BagSortSim.getSimulator()
Static method that
obtains a singleton instance
of the simulator.
start()
Method to start the simulation engine. Should
be called before the control algorithm is started.
boolean checkin(no,color)
Puts a bag at
Checkin no (1 or 2). The color may be either
BagSortSim.BLACK or BagSortSim.YELLOW. If a bag is
already present in the sensor section a, the method returns
false and a message is displayed.
If the simulation parameter Respect activation is enabled,
bags cannot be checked in if the sensor is not activated and are
ignored with a warning message
If the simulation parameter Max 1 on feed belt is enabled,
only a single bag is allowed at a feed belt at a time. Checkins
done while a bag is present at the feed belt (i.e. sections a and b)
are ignored with a warning message.
The bag is placed ahead of the sensor as specified by the
simultation parameter min bag separation.
The checkin operation may be used
by a dispatcher thread to provide a specific scenario as an
alternative to the manual operation.
void setActiveCheck(on)
Sets whether the activation
state of the censor (i.e. the red LED light) should influence the
checkin or not. Should be set by the
simulation driver program according to the assumptions made by the
control program. By default, the activation check is disabled.
void setFeedCheck(on)
Sets whether more than one bag on
a feed belt at a time is prohibited or not. Should be set by the
simulation driver program according to the assumptions made by the
control program. By default, the feed check is disabled.
The feed belt is
considered free as soon as a bag starts entering section c.
void setSeparation(int mm)
Sets the distance in front of
the sensor at which bags are to be put on the feed belt when checked
in. Since a bag can be checked in only when the previous bag has
left the sensor, this effectively determines the separation between
bags. The value may range between 0 and 80
[millimeters].
The default separation is 10 mm.
Caveats
The simulator does not model every aspect of the physical system. In
particular:
Motor speeds should only be set to 5.
The feed belts should not be run backwards.
The distribution belt should not be stopped when a bag is in section
c.
The feed belt should not be stopped during first 1.8 seconds of a
bag turning in section c.
The simulator only makes a rudimentary collision test.
The simulator generates WARNING messages when the control performs
operations which are unlikely to be reliably modelled in UPPAAL
(e.g. reversing the distribution belt).
If the simulator generates ERROR-messages during simulation, the
simulation cannot be assumed to reflect the real system.
Using the Simulator
To see an example run of the simulator, fetch the simulator
package simulator.jar and try the command:
java -jar simulator.jar
This will run an automated simulation of the
SingleSort.java shown in the assignment
notes.
To use the simulator for your own control program:
Insert the jar-file into your Java CLASSPATH, or, alternatively,
use command line option -cp .:simulator.jar [or -cp .;simulator.jar on Windows] to make
the jar-file available when you compile and run your program.
Alternatively, unpack the contents of the jar-file and import it
into a new project of your favourite IDE, eg. IntelliJ.
Write a small driver class which initializes the simulator and runs
your control program. For an example see the program
RunSimulation.java example program that
comes with the jar-file.
The driver program should set the simulation parameters according to
the assumptions made by your control program.
Compile and run your driver and control programs
with the standard javac and
java .
You may manually put bags on the feed belts using the buttons. Alternatively,
you may start up a dispatcher thread that checks in bags using the
checkin(...) operation described above. In the
provided example, the dispatcher thread Travellers adds
bags randomly to one of the check-ins.
The simulator is mainly provided for your convenience and is not
guaranteed to be flawless.
If you experience any problems, you may contact HHL.