Sandbox variables monitor

Previous tutorial: Sandbox scripting threads

 

As it was demonstrated in the previous article, different scripts running within a sandbox may communicate by setting/reading host variables. Those can be arbitrary variables, which need to be shared between scripts to implement desired application. For example, some variables may store readings from different sensors, which values may affect running video processing algorithms. Other variables may store results of those algorithms and can be used to guide different devices' actuators. Or it may have nothing to do with devices at all, but simply something which needs to be shared between scripts.

In some cases it may be required to inspect values of sandbox variables for debugging purpose, etc. One way to do so is to output their values on camera's image using ImageDrawing plug-in, for example. However, very often we may prefer to keep video clean from debugging information. Or it may be too much to display. Or we simply may not need it to be always there. Starting from version 2.0.0, Computer Vision Sandbox provides sandbox variables monitor (available from View menu), which can be used to inspect current values of sandbox variable. The widget can be open when needed only and stay hidden the rest of time.

In fact, the variables monitor can get useful not only in the scenarios of debugging communication between several scripts running within a sandbox. A single video processing script can be debugged as well. Simply set different variables with results of performed image processing algorithms, variables showing arbitrary status information, etc. and check it when needed from the variable monitor.

To remind, host variables are set from scripts using Host.SetVariable() and read using Host.GetVariable() APIs.

counter = 1

-- Set some initial value of host variables
Host.SetVariable( 'distance', 20.5 )
Host.SetVariable( 'leftMotor', 100 )
Host.SetVariable( 'rightMotor', 50 )
Host.SetVariable( 'connected', true )
Host.SetVariable( 'inputs', { 1, 1, 0, 0, 1, 1, 0 } )

function Main( )
    -- Periodically update the counter variable
    Host.SetVariable( 'counter', counter )
    counter = counter + 1
    
    -- ...
end

Introduction of variables monitor brings a useful tool as for scripts' debugging, as for displaying different status information. Plus, it can be easily shown/hidden to make sure user interface is not cluttered.