Table of Contents
To provide simple, error-free state connections between objects, OmeChron provides a “signal/slot” mechanism whereby the output state of one object is tied to one or more input state “slots” in other objects. The value of an input state slot is never changed through a connected signal until the signaled state is valid. Since OmeChron state signals can be connected to any other object state slot, objects can be coupled freely without regard to type as occurs when using OmeChron references. In this tutorial, we'll walk through creating and connecting models with signals and slots in the OmeChronGUI. A simple output sine wave will be connected to a slot, and the value of the signal plotted on a strip chart. Then we'll go through the details of programming the models in C++ and building the example plugin library.
We'll demonstrate OmeChron signals and slots using the signal_generator project under the $OMECHRON/examples/signal_generator directory. To build the plugin, follow the usual qmake/make command sequence in that directory.
Start the OmeChron GUI and load the signal_generator plugin library. Drag and drop an examples::SignalGenerator object onto the top-level system palette. Do the same to create an examples::SamplePort object. Click right on the SignalGenerator object and select to start the Signal/Slot Editor dialog shown below.
Select to start the Add Connection dialog shown below.
Under the selector, choose and on the selector choose the slot. Then, select to create the connection. A signal/slot connection appears as a green line between two objects in the OmeChron GUI as shown below. On each update of the signal generator, the current value of the sine wave is "fired" or sent out through the signal to all its connected ports. (A signal can be connected to any number of slots.) On each update of the sample port, it stores the current value in its input slot into a member attribute variable. Next, we'll create and configure a strip chart object to monitor and plot the sample port's value.
This example has the OmeChron plotting package built into it, so we can add a strip chart to visualize the signal as the simulation runs. Drag and drop a StripChart onto the system pallet and set its reference to point to the SamplePort. Double-click on the StripChart to open the inspector and edit plotattrs[0]. This will display the available SamplePort attributes for plotting. Choose the value attribute. The StripChart inspector should appear as shown below.
Save your system and run the simulation. You should see the sine wave plotted on the strip chart as shown below.
![]() | Note |
|---|---|
This section assumes that your are familiar with the basics of building OmeChron plugins and C++ programming. |
In the section, we'll walk through coding, compiling, and linking the Signal/Slot example using the OmeChron framework. We'll skip the details on building plugin classes since that has already been covered elsewhere. Like attributes and references, signals and slots are exported to the OmeChron system by overriding special base-class functions inherited from the SimModel base class. Let's examine how the SignalGenerator defines and exports its output signal. The SignalGenerator class declaration appears in the following code listing.
class SignalGenerator : public SimModel
{
public:
....
/// Return this object's signals.
SignalMap getSignals();
private:
sim::StateSignal m_output_signal;
};// end class SignalGenerator
Note the following features..
The implementation of the getSignals function appears below.
SignalMap SignalGenerator::getSignals()
{
// Get any base class signals...
SignalMap ans = SimModel::getSignals();
// Add ours...
add_signal( ans, &m_output_signal );
return ans;
}// end getSignals() ~~~~~~~~~~~~~~~~~~~~~~~
Note the following features..
Call the base class | |
Add the member signal to the returned signal map. |
Input slots are handled in the similar manner as shown below in the listing for the SamplePort declaration.
class SamplePort : public SimModel
{
public:
...
/// Default constructor.
SamplePort();
/// Get this object's slots.
SlotMap getSlots();
private:
sim::StateSlot m_input_slot;
};// end class SamplePort
Note the following features..
Declare a constructor to initialize all members including the initial value of the slot. | |
Override the | |
Declare the slot as a member variable. |
SlotMap SamplePort::getSlots()
{
// Get any base class slots...
SlotMap ans = SimModel::getSlots();
/// Add ours...
add_slot( ans, &m_input_slot );
return ans;
}// end getSlots() ~~~~~~~~~~~~~~~~~~~~~~~~~
Note the following features..
Call the base class getSlots to return any inherited slots. |
|
Add the local slot to the return slot map. |
CONFIG += ome_pluginTEMPLATE = lib TARGET = signal_generator DESTDIR = $(OMECHRON)/bin/plugins HEADERS = SignalGenerator.h \ SamplePort.h SOURCES = SignalGenerator.cpp \ SamplePort.cpp ## ## Make the OmeChron plotting classes part of this plugin model... ## NOTE: must be included *before* omechron.conf ## include( $(OMECHRON)/oplot/oplot.pri ) include( $(OMECHRON)/config/omechron.conf ) OBJECTS_DIR = ./obj
Note the following features of the qmake build file for plugin libraries: