VBScript Plugin
Please be sure to read the Plugins page to get a general sense of
if the VBScript module is a good fit for your project.
The VBScript module provides a way to create custom
Visual Basic scripts that can be used to process image statistics and map then
toward servo/motor values. This module is intented to be used as a way to quickly perform custom
operations without needing to implement a Plugin or use the API which typically require external
tools.
The interface allows two methods for specifying your code. One technique requires that you specify a text file as the
source of the program. You can use your favorite text editor to edit/create
this file. The file should be a regular text file containing VBScript
commands/functions/operators. The program interface displays the current file
being used, available system or user variables (and their values) and any messages
the program produces.
The alternate way is to include the VBScript text within the provided text box (see below). Using this technique
allows you to include the VBScript code within the .robo program and not require another user to save
the code and reference a text file as needed by the above file based technique. Using the text
box provides a quick way to enter in text but is NOT meant as a replacement for a full featured
text editor as its editing features are very basic.
Interface
RoboRealm Specific Functions
- VariableExists("variable_name") - returns true or false depending on if the specified variable exists in RoboRealm. Several of the variable
return functions below will return a valid value regardless of if the variable exists or not. You can use this function
to determine if the value returned from one of these functions is a valid value.
- GetVariable("variable_name") - returns an integer value of the specified variable. Zero is returned when the variable does not exist.
- GetFloatVariable("variable_name") - returns the float value of the specified variable. A zero is returned when the variable does not exist.
- GetStrVariable("variable_name") - returns the string value of the specified variable. An empty string "" is returned when the variable does not exist.
- GetArrayVariable("array_variable_name") - returns the array associated with the specified variable. An array is ALWAYS returned but the length (ubound) will
be zero if the array does not exist.
- SetArrayVariable "array_variable_name", array_variable - sets an array associated with the specified variable name; for example
ReDim points(4)
points(0) = 100
points(1) = 100
points(2) = 150
points(3) = 200
SetArrayVariable "waypoints", points
- SetVariable "variable_name", variable_value - sets the variable value to the specified variable
- SetTimedVariable "variable_name", variable_value, timeout - sets the variable value to the specified variable after the timeout (milliseconds) has passed
- GetPixels - returns an array of RGB values of the current image
- SetPixels pixel_data_array - sets the current image to the specified pixel RGB data
- SetParameter "module_name", index, "param_name", "param_value" - changes the specified parameter in the specified module to the specified value. This is useful when
a GUI dialog does not have a variable selection as part of the dropdown. Avoid using this function unless necessary as it is slow to update the
GUI.
- GetParameter("module_name", index, "param_name") - returns the specified parameter in the specified module. This is useful when
a GUI dialog does not expose a value within a variable.
- GetFloatParameter("module_name", index, "param_name") - the float version of the above routine.
- GetStrParameter("module_name", index, "param_name") - the string version of the above routine.
- Write "text" - sends text to the VBScript module message output area in the dialog interface (used for debugging)
- StopProcessing - stops RoboRealm from continuing to process the images with the remaining modules
- CameraOff - switches off the image capturing from the current camera
- CameraOn - switches on the image capturing using the current camera
- PushButton "Module_Name", Module_Index, "Button" - automates pushing a button in one of the
RoboRealm GUI windows. For example:
if GetStrVariable("test") <> "pushed" then
SetVariable "test", "pushed"
PushButton "Read_AVI", 0, "Start"
end if
will cause the Read_AVI module (assuming one exists in the pipeline) to start playback.
PushButton "RoboRealm", 0, "Snap"
will cause RoboRealm to create a snapshot of the current image.
- atan2(x,y) - arc tangent function not present in VBScript but useful for trigonometric calculations
- sqrt(x) - square root function not present in VBScript but useful for trigonometric calculations
Examples
To access variables from your VBScript file/script use the
following commands:
MyVar = GetVariable("variable_name")
Or to create a new variable use
SetVariable "variable_name", variable_value
Once a new variable is created this variable becomes available
to control functions (such as in the SSC module) that can be used to automatically
control a servo/motor.
You can also get variable arrays using
MyVar = GetArrayVariable("variable_array_name")
or get individual entries in an array using
MyVar = GetVariable("variable_array_name:2")
which would return the second entry in an array.
To change a variable's value in X milliseconds you can use
SetTimedVariable "variable_name", variable_value, timeout_in_milliseconds
which is very useful for resetting motor values after a period of time.
All regular VB Script commands and operators are available for
use in the VBScript file. See Microsoft
Scripting for complete documentation on how to use these commands or view
the sample files for examples.
For example the following program (assuming you have added the Center Of Gravity module) will map COG to servo motors:
cogx = GetVariable("cog_x")
cogy = GetVariable("cog_y")
if cogx < 140 then
left_motor = 60
right_motor = 128
else
if cogx > 180 then
left_motor = 128
right_motor = 60
else
left_motor = 128
right_motor = 128
end if
end if
SetVariable "left_motor", left_motor
SetVariable "right_motor", right_motor
Note that the COGX values range from 0 to 320. COGY ranges from 0 to 160. These values are
bounded by the current image size. These values may
change if you crop, shrink, etc. the image dimensions.
You could then use a module like the SSC module to map the "left_motor" and "right_motor" variables to actual servos.
You can also process the image pixels directly using VBScript. This is useful
for prototyping but not recommended due to performance reasons for actual usage.
The VBScript module supports two routines to get and set the image pixels. Following
is the example SwapColor module but in VBScript.
Dim pixels
pixels = GetPixels()
for i = 0 to (320*240*3)-1 step 3
tmp = pixels(i)
pixels(i) = pixels(i+2)
pixels(i+2) = tmp
next
SetPixels(pixels)
To write variables or debug statements to a log file you can use
Dim fi
Dim fso
set fso = CreateObject("Scripting.FileSystemObject")
set fi = fso.OpenTextFile("c:\temp\test.txt", 8, true)
if err.number = 0 then
fi.writeLine GetVariable("cog_x") & ":" & _ GetVariable("cog_y")
fi.close
end if
set fi = nothing
set fso = nothing
If you need to wait for a specific condition in a loop you will have to setup a trigger variable.
You can't really sleep, wait or loop in the VBScript module as that would stop all image processing while it is waiting for the
loop or sleep to finish. As the pipeline is essentially
an infinite loop (i.e. grab an image, process it, then grab another, etc) adding a sleep would cease all
execution which is usually not desired.
If you prevent the ending of the loop by putting a while loop in the code it will not allow the system to
capture new images and continue processing.
So instead you can use the SetTimedVariable to cause the variable
to change value after X number of milliseconds. Your script would look something like
period = 2000
step = GetVariable("step")
if step = 0 then
SetVariable "data", 2
SetVariable "step", 1
SetTimedVariable "step", 2, period
else
if step = 2 then
SetVariable "data", 4
SetVariable "step", 3
SetTimedVariable "step", 0, period
end if
end if
which would cause the variable data to oscillate between 2 and 4 with a period of 2000 seconds. Note that usage of step and
setting it to 1 and 3 which are dummy steps where nothing is done.
Note that VBScript can access external activeX objects such as the Microsoft XML Http
object. The following example shows this technique to issue a custom URL to a
remote machine. Be sure to also have a look at the HTTP module for such tasks.
' Show Status Output 1
Dim a
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "GET", "http://172.17.42.54/axis-cgi/io/output.cgi?check=1", False
objHTTP.send ("")
a = Split(objHTTP.responseText, "=")
SetVariable("Output1"),a(1)
' Activate Output 1
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "GET", "http://172.17.42.54/axis-cgi/io/output.cgi?action=1:/", False
objHTTP.send ("")
' Deactivate Output 1
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "GET", "http://172.17.42.54/axis-cgi/io/output.cgi?action=1:\", False
objHTTP.send ("")
Variables
On each successful run of the script the SCRIPT_COUNT variable is incremented. Thus you can use this variable to
indicate a first run state where variables can be initialized to default values. Note that the Reload and Run button
will reset this count to 0.
Downloads
If RoboRealm complains about missing components you may need to
download the Microsoft Script Control.
See Also
CScript Program
Python Program
| VBScript_Program Related Forum Posts | Last post | Posts | Views |
Working with Arrays
STeven-
I was wondering what would be the best way to store and reverse an array in RR? ... |
28 days |
4 |
119 |
Regarding my program
Hi, i wonder if someone could take a look at my robo file here and see what is set wrong, i cant understand why it wont do what... |
1 month |
2 |
90 |
Changing Modules in the Stream
Is there any way from the VBScript module, or another module, to enable/disable modules running in the video stream?
| 2 months |
5 |
149 |
VBScript Blob Count and Display Text
Hi,
I have a VBScript Problem.
I'm developing a counting program, whe... |
3 months |
2 |
242 |
pololu miro-maestro is not discerned
Hi,
I bought the licence of the last roborealm version and I have a problem with pololu micro-maestro.
| 4 months |
32 |
777 |
reading values after time lapse
How do i read a variable (exp COG_X) value at Time = 1second ago and compare this with the current value (Time = current)
| 5 months |
3 |
297 |
Roborealm and hexapod
Hi,
I am trying to run this tutorial:
... |
6 months |
71 |
852 |
Servo movement deadband
I have a question, I'm not sure how to go about this.
This is the code in the vb script program:
<... |
9 months |
9 |
629 |
script
hi there i just wanted to tell you that i redownloaded the microsoft script that you told me i needed but roborealm still says i... |
9 months |
3 |
413 |
Changing Servo speed from VBScript
HI, I’m working with VBScript module sending variables to Lynxmotion_SSC but I don’t know how to change the servomotor speed fro... |
10 months |
3 |
771 |
VBScript to Keyboard Send
I am trying to make a usb missile launcher follow a red blob and then shoot it when it centers on it. (see attached) I am using... |
11 months |
3 |
640 |
problem
Hi! I have a problem : How we can have time in VBSCRIPT PROGRAM variables like other variables.Is there any module to... |
11 months |
2 |
510 |
Performing an operation for a set amount of time
STeven,
I am using a servo motor to pull the trigger of a paintball gun. So that I don't waste too... |
11 months |
6 |
643 |
Pause Function in VbScript
Hey I am wondering if anyone knows how to pause using VbScript? I need to pause between servo movements using Sparkfun Arduino a... |
2 years |
2 |
1295 |
Using Roborealm to control robot working on OpenWRT Linux
Hello!
Thank you for developing such great program, wich gives robotbuilders the huge variety of po... |
2 years |
5 |
1352 |
about the I2C bus on the serializer board
Steven what variables are they on the I2C bus to read from
mostly TPA81 and how do i write them... |
2 years |
10 |
3302 |
SetTimedVariable
Hello,
I am using the SetTimedVariable to turn a motor for certain period of time. THe scenario is... |
2 years |
9 |
4075 |
|