Go to Home Go to About
Go to Products Go to Contact
Go to News
Go to Services

Scripting

The scripting language in WorldUp is incredibly powerful. However, setting up a script to be interfaced with Simulink is extremely simple.

The lines in red are comments and should not be replicated into your script.


sub bounceball(ObjectStr as string)

Here we have our header line which contains the sub keyword, the name of our script, and the type of input

'input:Ball X

'input:Ball Y

'input:Ball Z

These are comment lines VERY important to MATLAB and Simulink. They must always be of the format

'input:<name of input>

Both MATLAB and Simulink use these lines to determine the correct number of inputs to pass to this subroutine. Also, it is good bookkeeping to have these comments as it helps clarify what values are being passed in.

dim ObjectVal(2) as double

For this example we are going to be passing in 3 values. ObjectVal is dimensioned to 2 as that refers to the 0th, 1st, and 2nd entries. Therefore, if you know you have 18 numbers coming into to control your objects, you would use 17.

dim i as integer

token = ","

for i = 0 to 2

Here, again, if you had 17 objects you would update the 2 to a 17.

ObjectVal(i) = 0

next i

stringlength = Len(ObjectStr)

i = 0

while stringlength > 1

ObjectVal(i) = val(ObjectStr)

position = Instr(ObjectStr, token)

ObjectStr = Mid(ObjectStr, position+1, stringlength - (position))

stringlength = Len(ObjectStr)

i = i + 1

wend

The above lines of code loop over the inputted string and separate out all the numbers and assign them to the ObjectVal variable. Now begins the simple code to control our bouncing ball.

dim Sphere1 as geometry

dim Pos as vect3d

set Sphere1 = getgeometry("Sphere1")

Pos.x = ObjectVal(0)

Pos.y = ObjectVal(1)

Pos.z = ObjectVal(2)

Sphere1.SetTranslation Pos

end sub

That's it! Upon loading the UP file, MATLAB and Simulink automatically determine whether a script is a subroutine that accepts values or not. In Simulink, the inputs you listed above will be added to an input block. No further work is needed other than debugging how your objects move.

MATLAB, Simulink, and Handle Graphics are trademarks of The MathWorks, Inc.