loading
 
VB script help needed
from United States  [36 posts]
11 year
Hello Steven
I am trying to make a intelligent spray boom which spray only if it sees weeds. I used RGB filter then blob filter of plants. Now I have blob array for all plant. I can see X  & Y values of all blobs in VB Script massage.

list = GetArrayVariable("BLOBS")
if isArray(list) then
  ' we have an array - write out the size
  write "The size is " & ubound(list) & vbCRLF
  ' now write out all the elements
  for i = 0 to ubound(list) step 2
    write "X: " & list(i) & " Y:" & list(i+1) & vbCRLF
SetVariable "COG_X", X
SetVariable "COG_Y", Y
SetVariable "Trigger", 1500
  next
end if

Up to this point, things are running fine. But when in next step I want to scale these X Y values for Pololu maestro servo controller. I can't because values of X Y not transferring in 'scale variable. I doubled check in watch variables. Can you please help me out here. All I want to direct XY servos at each blob center position and trigger. Then move to next, exclude blobs which are already been triggered. I am not good in VB scripts. Any help will be appreciated. Thanks in advance.
Steven Gentner from United States  [1446 posts] 11 year
Aman,

I'm assuming that you are using a stationary camera NOT attached to the boom otherwise you are looking at a visual servoing solution instead.

If the camera stays stable and you just need to  scale the image coordinates to the servo coordinates you can start with a simple scale factor and then modify it from there. That would look like

SetVariable "servo1", ((GetVariable("COG_X") * 2000) / GetVariable("IMAGE_WIDTH"))+ 500

assuming you servo ranges from 500 to 2500. Naturally this straight mapping will only work if your extreme servo positions would be left of screen and right of screen, which will rarely be the case. Instead you may find that the left and right positions of the servo is 800 and 2100 which would change the forumla to

SetVariable "servo1", ((GetVariable("COG_X") * 1300) / GetVariable("IMAGE_WIDTH")) + 800

and then you may find that everything is offset by a bit so adjust the 800 up or down until things align correctly.

If anything moves relative to the camera then all this gets uncalibrated again so be sure to have your boom and camera not move relative to each other.

STeven.

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