Robotics.Pixel Following .*;
I won't show all the source code for this project simply because some of it wouldn't make sense. I used activeX controls for video capture, and a lengthy wrapper class for the RS232 serial communications (both of which I'm not the author of). The parts I'll show below are straightforward and best describe the process of translating image pixels to servo movements.
I devised this project to see how a camera turret could be programmed to shift the center of focus to targeted areas of the camera's view.
It works like this:
- grab a frame from the camera's video input
- display that frame on the user's monitor
- the user clicks on any place within the image with the mouse pointer
- the camera turret repositions the camera, centering the view on the place the user clicked.
- take a range-to-target measurement with the sonar ranger.
This was a quick-and-dirty project I did just for the sake of seeing how difficult the concept would be. It actually turned out to be very simple.
I made the camera turret out of two hobby servos, some aluminum scraps, and a handful of hardware. All I needed was two degrees of freedom: vertical and horizontal.
Figure 1. Yeah, that's an old Lego Cam from the original Lego Vision Command (a little dusty, but it still works). The side of the camera is mounted directly to one of the servo arms. The sonar ranging module is attached to the other side of the camera (upper-left).
Figure 2. Two different Basic Stamp 2 boards were used for control. At this time I'm still having trouble figuring out how to send AND receive serial communications with the same Stamp board (though I'm sure I'll figure it out eventually). Toward the bottom of this figure is a MiniSSC2 servo controller board. And yes, my favorite beer mug is a chemistry beaker.
Figure 3. Told ya' it was quick and dirty.
Figure 4. Well, I took four pictures.
I found the trick to this project was in translating the camera's view angle into discrete units of movement for the servos.
With this information, I came up with the formula for moving the servos:
f(x) = (x coordinate / image width) * horizontal view angle
and similarly with the y-axis:
f(y) = (y coordinate / image height) * vertical view angle
In this case, the formulas would look like:
f(x) = (x / 352) * 47
f(y) = (y / 288) * 38
The results of the formulas were sent to the servo controller to reposition the servos.