Chapter 7. A Look at Plugins and Events
Prev |  | Next

# Chapter 7. A Look at Plugins and Events

We end our journey through KST by looking at two specific data typesplugins and event monitors.

A plugin is a flexible data object whose behaviour depends entirely on the specific plugin file selected. The plugin file can be one that is included with the standard KST distribution, or it can be a third-party plugin file. In fact, the Kst Handbook includes instructions on how to write and compile custom plugin files. Plugins allow KST to perform arbitrary operations on a set of data, as the only requirements for a plugin file are that they receive a set of input vectors and scalars, and output a set of vectors and scalars.

As an example, we will try fitting a simple line to a small set of data points. Start KST with a plot of the first field of the `maxima.dat` data file included in the demo package:

    kst -y 1 -d maxima.dat

The `d` option specifies that only points should be plotted, not lines. The plot of data points should now be displayed:

Now, open the Data Manager. Click Plugin... in the New section to create a new plugin object. Under Plugin Selection, select the Fit linear plugin. This particular plugin requires two input vectorsone containing the x values and one containing the y values of the data points to be fitted. Select V1-INDEX for Input Vector - X Array, and V2-1 for Input Vector - Y Array. Then, click OK. You will notice that the new plugin object has created slave vectors to store its outputs. Click on Curve... to create a new curve from the output vectors. Select V1-INDEX for X axis vector and P1-kstfit_linear_unweighted-Y Fitted for Y axis vector. We want to place the curve on top of the data points in the existing plot, so under Curve Placement, select Place in existing plot and deselect Place in new plot. Finally, click OK to create the curve. Close the data manager to view the fitted line:

A procedure similar to the one you have just followed will allow you to create and plot the outputs of any type of plugin object. However, there is a shortcut for creating fit plugins. Right-clicking on a plot will display the context menu, which contains a Fit... submenu. Selecting a curve from the submenu will bring up the Fit Function dialog with the x and y vectors preselected. After the fit plugin is selected, a click of the OK button will create the plugin object, create the curve from the plugin outputs, and place the curve on the existing plot.

Let us now take a look at events. Event objects usually monitor other vectors or scalars and perform specified actions when certain conditions involving those vectors or scalars are true. Click EventMonitor... in the New section of the Data Manager to create a new event:

Suppose that the pitch gyro data was being updated in real time, and that we wanted to be notified whenever the corrected pitch gyro falls outside the range `[-0.60, -0.40]`. To set up the event in this manner, enter the following in the Expression textbox:

`[C4-cleaned_pitch-sv]>(-0.40) | [C4-cleaned_pitch-sv]<(-0.60)`

Note that anything entered as an expression must be a boolean expression. This particular expression will evaluate to true whenever either of the inequalities is true. Select both Log as and Notify, and enter in your email address to the right of the Notify checkbox. Click OK, and the event will be created.

Now select Debug Kst... from the Help menu. Click the Log tab to view the debug log. If the event was set up correctly, you should see warnings indicating the x values for which the event was triggered. Check that the values roughly match those you would expect from looking at the plot:

If the pitch gyro data was being updated in real-time, the event monitor would be triggered for any new data when appropriate as well.

Once you are done, you can close KST.

Prev |  | Next
Chapter 6. A Brief Overview of Data Objects | Home | Chapter 8. Conclusion