Chapter 5, "Designing Actors," of
the Volume 1: Introduction to Ptolemy II of the
Ptolemy II Design Document at
discusses how to design actors, but the design document does
not discuss compiling the actor and adding it to Vergil. The reason
for this omission is because we are hoping to eventually have a cleaner
method for adding actors. The text below is a how-to guide for
the current environment
For this example, we are going to take the Ramp actor
and change the default step from
The new actor will be called Ramp2.
The instructions below assume that you have installed
the Java Development Kit (JDK), which includes the
binary, that you have a
make binary and other tools installed,
that Ptolemy II has been installed, and that
make have been run. For details about the
installation process, see
Under Windows XP with JDK1.4 and Cygwin, to do the setup, I did:
bash-2.04$ PTII=c:/ptII4.0 bash-2.04$ export PTII bash-2.04$ cd "$PTII" bash-2.04$ ./configure bash-2.04$ make fast >& make.outConfigure and make usually generate a few warnings.
Below are the steps necessary to add an actor:
.javafile that implements your actor:
cd $PTII/ptolemy/actor/lib cp -p Ramp.java Ramp2.javaNote that if we had copied our java code from a different directory, we would also have to change the package statement (usually near line 31) in the java code. This is good to keep in mind since there is no error message to clue you in to this particular error.
Ramp2.javato the value of
JSRCS. A good place for this is just after the
Quantizer.java \ Ramp.java \ RandomSource.java \
Quantizer.java \ Ramp.java \ Ramp2.java \ RandomSource.java \This step is not strictly necessary, but it is good programming practice to put all source files in the makefile. Another reason we add it to the makefile is so that our new actor will be included in the
$PTII/ptolemy/actor/libdirectory (which is where you should already be).
makewill descend into the subdirectories and compile any needed files and eventually run
rm -f `basename Ramp2.java .java`.class CLASSPATH="../../.." "/cygdrive/c/jdk1.3/bin/javac" -g -O Ramp2.javaand
Ramp2.classwill be produced.
$PTII/ptolemy/actor/lib/sequencesources.xmland add Ramp2 just after the lines for Ramp
<entity name="Ramp" class="ptolemy.actor.lib.Ramp"> <doc>Create a sequence of tokens with increasing value</doc> </entity> <entity name="Sinewave" class="ptolemy.actor.lib.Sinewave"/>To:
<entity name="Ramp" class="ptolemy.actor.lib.Ramp"> <doc>Create a sequence of tokens with increasing value</doc> </entity> <entity name="Ramp2" class="ptolemy.actor.lib.Ramp2"> <doc>Create a sequence of tokens with increasing value 2</doc> </entity> <entity name="Sinewave" class="ptolemy.actor.lib.Sinewave"/>
bash-2.04$ vergilIf this does not work, you may not have created an alias for vergil. Try specifying the full path name, like this.
- To test the Ramp2 actor:
- Drag the Ramp2 actor over to the main canvas on the right
- Clock on
GenericSinksand drag a Display actor over to the main canvas
- Connect the two actors by left clicking on the output of the ramp2 actor and dragging over to the input of the Display actor
SDFand drag the SDF director over to the right window
Runand change the number of iterations from
10, then hit the Run button.
- You should see the numbers from 0 to 18 in the display
To add a new set of actors, we first create a .xml file
that lists the actor. In this case, the file
and it contains one actor,
<?xml version="1.0" standalone="no"?> <!DOCTYPE plot PUBLIC "-//UC Berkeley//DTD MoML 1//EN" "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd"> <entity name="myactors" class="ptolemy.moml.EntityLibrary"> <configure> <?moml <group> <doc>My Actors</doc> <entity name="Ramp2" class="ptolemy.actor.lib.Ramp2"> <doc>Create a sequence of tokens with increasing value of 2</doc> </entity> </group> ?> </configure> </entity>Below we discuss two ways of adding the configuration:
Under Windows XP,
$HOME might be found at
c:/Documents and Settings/yourlogin, so
the UserLibrary.xml file would be at
c:/Documents and Settings/yourlogin/.ptolemyII/UserLibrary.xml
Edit UserLibrary.xml and change:
<entity name="UserLibrary" class="ptolemy.moml.EntityLibrary"/>to:
<entity name="UserLibrary" class="ptolemy.moml.EntityLibrary"> <group> <input source="ptolemy/actor/lib/myactors.xml"/> </group> </entity>Note that you must remove the slash in the first line:
<entity name="UserLibrary" class="ptolemy.moml.EntityLibrary"/>becomes:
<entity name="UserLibrary" class="ptolemy.moml.EntityLibrary">
After changing UserLibrary.xml, restart vergil and the myactors sub-palette will appear under UserLibrary.
The palette and menus are determined by configuration files.
The default configuration for
$PTII/bin/vergil is located at
(For further information about how the configuration is specified, see the
Eventually, we includ
We want to add our new palette,
to the actor library palette so we will add
Note that we want our new palette to be a sub pallet of the actor
library palette, just as the sources palette is. The
input statements below do not cause the palette
named by the
to be a sub palette. Sub-paletting is caused by the
entity statement in the 4th line of your myactors.xml
ptolemy/configs/basicActorLibrary.xml we change
<input source="ptolemy/actor/lib/myactors.xml"/> <input source="ptolemy/actor/lib/sources.xml"/>Then restart vergil, and your myactors sub-palette will appear under 'actor library'.