Learning Roborealm

I have great news! I got roborealm to work. I figured out the problem was when I load the SSC-32 control in roborealm it automatically sets all the servos to “Enable”. So I had to disable the pins i wasn’t using before clicking “Run” again.

I’m having alot of fun with it right now. but I want my P&T to follow something green. I set everything up just fine but I don’t know what calculations I need to use to follow something green.

The code below allows the Pan And Tilt to track something green, but only when the webcam is NOT attached to the pan and tilt. This is because of the servos orientation. For example, If i converted screen coordinates to servo pulses, it works ok. But with webcam connected the panning servo goes nuts. If the a green ball is in the middle of the screen (in front of the webcam), The pulse would be 1500. That would center the servo and move the servo AWAY from the object. if the object is in the center of the view then I don’t want the servo to move anywhere. Get what i’m saying?


' first check that something moving is in view
if GetVariable("COG_BOX_SIZE") > 10 then

  ' get the current screen width so we can calibrate movement 
  width = GetVariable("IMAGE_WIDTH")

  ' get the current center of movement
  x = GetVariable("COG_X")

  ' scale the image space into the servo space
  x = CInt(((x/width)*2000))+500

  ' set the variable for use in the servo controller
  SetVariable "servo_position", x

end if

I had similar problems with servo jitter due to a crapy image. If the picture is grainy, it will cause some issues. You might want to use the blob filter to cut down on some of the image noise to get better results. The script I gave you should cause a servo to pan in the direction of the ball to center it in the screen. The camera if mounted on the pan servo should follow a moving green ball unless it falls out of viewing range.

No it’s not grainy at all. the servo pans perfectly when the camera isn’t connected to the panning servo. Can you confirm that you have used the code and it works?

Confirm? yes, I can youtube.com/watch?v=qB0eN-D689U this video was done back in '07 but its proof that it works. At the end of the video the servo went haywire because when I leaned forward, my body blocked the web cam.

I will have to re-test to see if the code I gave you works as in the video. It’s been a long while, but the code is what I used as a base example.

Um, of course it works in the video. It’s not actually on a pan and tilt, you’re moving it with your hand. Have you tried it when actually on a pan and tilt?

Nope! :smiley:

This is what I don’t understand. You say it works perfectly when the camera is not mounted on the servo but it doesn’t work when the camera is mounted? It shouldn’t make a difference. All I can think of is that the servo is moving:

A. in the wrong direction (away from the object instead of towards it)
B. Servo is moving to fast.

Check that the servo moves the camera to the object. If this is not the issue, then try slowing down the servo. If that doesn’t work, then I really don’t know what else to tell you.

If the servo is moving the camera away from the object then it will never be able to center the object in the image frame. You might have to change the values in the script file so that the servo moves the other direction. From + to - …or… - to +

SN96, it’s really hard to explain but I know why it doesn’t work. You should try it yourself to see what i mean. But for i know will give a better explanation.

Suppose the servo if at position 1190. The object being tracked moves into the center of the camera, which then tells the SSC-32 to move the servo to 1500, when the servo should stay where it is considering the object is already in the Center of the view.

And I have already tried something like servoX = servoX + 10 but it moves SOOO slow and it’s not very accurate.

Hi guys

I have my robot following and rotating around a blue ball. I now want to have a variable showing distance of the object. I presume i need a little script to calculate and i have looked at the calculate distance module. Has anyone successfully worked out the distance of an object?

Thanks for any pointers

Im also thinking maybe a stereo vision system?

:open_mouth:

The distance measurement is based on the variable “COG_SIZE”. Usually the bigger it is the closer an object is, the further away the smaller.

So should i make an array so that say COG_SIZE is 10 - 20 its 15cm away
20-30 20cm 30-40 35cm etc?

And display this as a new variable?

You mean like a table? sure. I think that would work.

Thats a cheating way, i like it. I will produce a long if else statement. I will then rotate the robot to a second object and get that distance. Is it possible thinking plain terms too calculate the position of the robot if i have 2 distances using a simple formula in Vbscript?

I guess if you know the formula. I can’t help you there though, i’m just a high school student. :stuck_out_tongue:

Ill work that out :smiley:

Just seeing if it sounded realistic and not completely potty!

Thanks