Recent Changes - Search:

edit SideBar

CreatingNewActors

Back to mbed

This is a high level overview about creating actors in Ptolemy, to get started quickly and design actors similar to what we did in the mbed code generation project. The best place to start, is to read chapter 12.4 of System Design, Modeling, and Design Using Ptolemy II which covers this topic more clearly and in more detail. In order to add the actor to the list in vergil, see this page.

File Structure

Within the ptolemy tree, there are several places where the java file for actors are located. (Note, there may be more, but these are the two main areas that I have seen). The main location where ours are located, are in ptolemy/actor/lib/ and these are organized into several sub catagories, for instance my GPIOWriter actor is located under "io". To make the actor show up in the search area of vergil, then the actors for these are located under ptolemy/vergil/actor/lib (at least that is what I am guessing where they will show up).

In order to Instantiate an actor that is not indexed in vergil, go to Graph->Instantiate Entity in vergil, and enter the actor name. This name will be similar to the path for your actor. For example, the GPIOWriter actor has a class name of ptolemy.actor.lib.io.GPIOWriter.

Getting started with a new actor

After creating a new java file under one of the locations mentioned above, (don't forget to add the new file to the java makefile), create a new class with your new actor's name. Most new actors will extend TypedAtomicActor, but if another actor exists that you want to do something similar when the model is run, then extend that actor instead. Copy the constructor arguments from another file, they are always the same, and make sure to start with calling the parent constructor (super(container, name) will be the first line of code). In the constructor, you can create and initialize the ports and parameters, as well as add new artwork for the actor.

  • _attachText() is used in the constructor to make the artwork, how this can be generated more easily is still unknown to me.

Port and Parameters

There are several types of ports and parameters that can be made in the java file, a quick overview of the ones I have used are listed below. These can be accessed for code generation as variables in your program. The most common ones are:

  • TypedIOPort
    • Create a new one, takes in arguments (this, port name, isInput?, isOutpu?). input = new TypedIOPort(this, "input", true, false); would create an input. input would be a member variable with type TypedIOPort.
  • Parameter
    • Takes in parameters (this, parameter name). Ex: myParam = new Parameter(this, "myParam");
  • PortParameter
    • This be a port if there is an input connected, otherwise it is a parameter set in the actor.

Then there are more specialized ones, such as:

  • StringParameter
    • A Parameter that is always a string (so the user will not have to type in quotes to make this a string)
  • FilePortParameter
    • Used for writing to a file in LineWriter

Override functions

You can override functions such as the fire or initialize code from the super class, and make your actor do what you want. I will go into more detail here about each of the functions I have done this with, but right now this is blank.

Creating the adapter file

Edit - History - Print - Recent Changes - Search
Page last modified on April 19, 2015, at 09:41 pm