Set Context

Using the context to set variables is a useful technique to improve the maintainability of your Xcos models.

The "Set Context" option allows you to define parameters and values that can be used in your Xcos blocks.

For example instead of entering actual P,I & D values for a PID block you could enter variable names like this...

xcoscontext1

And then in the set context configuration you can specify their values.

xcoscontext2

Why use the Set Context approach?

There are several benefits;

xcoscontext3

How to use

Annoyingly you have to have the parameter name specified first in the context configuration before you can use it in an Xcos block so firstly call up the "Set Context" option via the menu bar like this...

xcoscontext4

Or you can right-click anywhere on the Xcos diagram background and select the "Set Context" option.

xcoscontext5

Then enter your parameters and values as shown previously.

You can now use these parameter names in your Xcos blocks.

You can add comments too to improve understanding. Just prefix each line with "//" which is the SciCos programming comment mark-up

xcoscontext6

Be careful because the following is accepted (i.e. without the comment mark-up) but it does not work. I suspect that it generates an error which is automatically handled by an error trap but which results in the values not being set correctly.

xcoscontext7