Top Up Prev Next Bottom Contents Index Search

2.8 Using galaxies


In this section we will explain how to create galaxies. Galaxies allow you to use hierarchy to partition your design into more manageable pieces and to re-use designs as components in other designs.

2.8.1 Creating a galaxy

Use the schematic we created in the last example to make a sine wave generator galaxy.

cp -r wave singen
The recursive copy, cp -r, is necessary because oct stores data using a hierarchical directory structure. Of course, if the facet singen exists already, you must remove it with rm -r first before copying.

We now have a galaxy. The fact that a schematic has input or output ports distinguishes it as a galaxy. This galaxy that you just created is similar to the "singen" galaxy in the "Signal Sources" palette. Find it, and look inside, to make the comparison.

2.8.2 Using a galaxy

We have just created a galaxy that we would like to use in another design. In order to do this, we need to create an icon for this galaxy that we will then instantiate in our other design.

Hint: If you place the icons so that their terminals fall on top of one another, then a connection gets made without having to draw a wire.

So far, we have created a galaxy and used it in another universe. But we could also have used our galaxy within another galaxy. In this way, large systems can be broken up into smaller more manageable pieces.

2.8.3 Galaxy and universe parameters

One of the problems with the "singen" galaxy that we just created is that it generates sine waves with a fixed frequency. We would like to make the frequency of the generator parameterizable. That way, we could set the two "singen" galaxies in our "modulation" universe to two different frequencies.

To make a galaxy parameterizable, we create formal parameters in the galaxy and then link the formal parameters to the actual parameters of the instances contained in the galaxy. The terms, "formal" and "actual" parameters, are analogous to formal and actual parameters in any procedural programming language. An example will make this clear.

	name: freq 
	type: float 
	value: PI/50
The value will be the default value. Then click on "OK". Recall that you can use "tab" to move from one field to the next of the dialog box and "Return" instead of "OK". Hence, the dialog can be managed from the keyboard without requiring the mouse.

We just created a new formal parameter called "freq" with a default value of "PI/50". Additional parameters may be added or old ones changed. The default value of a formal parameter can always be changed by executing edit-params in the background of the galaxy. Executing edit-params on the icon representing the galaxy changes the parameter values only for the instance represented by the icon. It overrides the default value specified in the background of the galaxy definition. The possible types for parameters are listed in table

2-6. The syntax for specifying values for parameters is described above in "Changing or setting parameters" on page 2-15. Exactly the same procedure can be used to attach formal parameters to a universe. This allows you to parameterize a complete Ptolemy application.



Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.