loading
 
Variable Math
Anonymous
17 year
Can I do var = "var"-"var" in vbscript? I cannot figure out how to do this, but maybe I'm just missing it.
Anonymous 17 year
I'm not sure what you would expect the result to be? Would it not be ""? Or are you trying to remove a substring from one variable to the next? Perhaps if you describe what you are trying to do we can provide the needed script.

STeven.
Variable MAth
Anonymous
17 year
Well, the end result would be a ratio of pixels to servo position. The range is the same as in my laser and circle detection posts. I would hard-code the values for the boundaries of the box, and similarly for the servo max values. For Example: The maximum X Pixel Value is 160, and the maximum x Servo value is 200. The minimum X values are Pixel: 20 Serov0:50. What I would like to do is subtract the min. servo X from the Max servo X, and do the same for the pixels. Then I could divide the pixel difference by the servo difference, and I would end up with a number that I could multiply by a pixel value to get a servo value.

Sorry if that is confusing, I hope you catch my drift.
Anonymous 17 year
Ok, so the math would be something like:

servoMax = 200
servoMin = 50
pixelMax = 160
pixelMin = 20

scaleFactor = (servoMax-servoMin)/(pixelMax-pixelMin)

SetVariable "servo_pos", CInt((GetVariable("cog_x") - pixelMin) * scaleFactor) + servoMin

which would create the scaleFactor you are talking about and would then scale the cog_x (as an example variable) that is in pixel space to servo space.

Was that what you were thinking about? Note that the above should execute in the VBScript module.

STeven.
Thanks
Anonymous
17 year
That seems to be working. I have uploaded my modified code below.
program.robo

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index