Screenshots     Download     Documentation     Tutorials     Partners     Resources     Contact     Forum     Search  

 

VBScript Extension

Please be sure to read the Overview page to get a general sense of if the VBScript RoboRealm Extension is a good fit for you.

The VBScript module provides a way to create custom VB Script programs that can be used to process image statistics and map then toward servo/motor values.

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 provided text box does provide a quick way to enter in text but is NOT meant as a replacement for a full featured text editor as its features are very basic.

Interface

RoboRealm Specific Functions

  • GetVariable("variable_name") - returns an integer value of the specified variable

  • GetStrVariable("variable_name") - returns the string value of the specified variable

  • GetArrayVariable("array_variable_name") - returns the array associated with the specified variable

  • 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.

  • 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

  • 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 the SSC) 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 to (320*240*3)-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"8true)
  
if err.number then
    
fi.writeLine GetVariable("cog_x") & ":" & _
      GetVariable(
"cog_y")
    fi.close
  
end if
  set 
fi = nothing
  set 
fso = nothing

Downloads

If RoboRealm complains about missing components you may need to download the Microsoft Script Control.


© 2008 RoboRealm. All Rights Reserved. | Contact | Glossary | Privacy | Disclaimer | Link to Us | Resources | Site Map