CURRENT ISSUE
Contests
FEATURE ARTICLE
|
|
Issue #224 March 2009
Vision-Guided Robotics
A Next-Generation Balancing Robot
by Hanno Sander
Start | Parallax Propeller | ViewPort | The DanceBot | Frame Grabber | Real-Time Tracking | Line Following With A Camera | Track A Pattern | Find A Beer Bottle | Wrap Up | Sources & PDF
REAL-TIME TRACKING
You know how to create the infrastructure to digitize video from a camera into the Propeller’s memory using an ADC and one of the Propeller’s eight cogs. You have 24 KB of visual data updated 30 times per second. Now you need a filter that can analyze the video and give you just two variables to control the robot.
Start by implementing a filter that identifies the location of the brightest spot in each frame. It’s easy to search for the maximum value in your array of pixel brightness values. Just remember that you’re working on 4-bit pixel values compressed into 32-bit longs (A 32-bit long on the Propeller is the basic unit of memory space) (see Listing 3).
This filter processes one pixel every five instructions. Because the filter processes only data, not sync marks or color bursts, you can process video at 40 fps. So the filter can easily keep up with the frame grabber object and update the position of the brightest spot in real time.
To integrate this code with the rest of your DanceBot, simply keep this filter code running in its own cog. The cog will continually filter the data provided by the frame grabber and write the x,y location of the brightest spot into the main memory.
You now have two channels of information updated at 30 times/second with which you can drive the two control channels of your robot—speed and direction. Use the x position of the spot to control the turning rate of the robot. If the spot is in the middle, you don’t need to do anything. However, if it’s on the left side of the image, the algorithm tells the robot to turn left, until the spot is in the center and the robot is facing the source of the spot. A similar technique controls the robot’s speed using the vertical position of the spot. The algorithm’s goal is to keep the spot’s position centered in the image. So, when the spot is too low, the robot is instructed to move forward, which brings the robot closer to the spot’s source. Because your camera is looking up at the spot, it will raise the spot in the image. Conversely, if the spot is too high, your robot is too close, so it’s commanded to drive backwards. Translating this algorithm into code is simple, just scale and offset the x,y location of the spot to control the robot. The complete control program for the robot is posted on the Circuit Cellar FTP site.
To illustrate the tracking ability of this filter, I can use ViewPort to display the streamed video with a superimposed trail showing the position returned from the filter over the last minute. Photo 4 shows the grayscale image, as seen by the camera, with a yellow trail showing the path the bright source took.
![]() |
| Photo 4—The DanceBot is tracking the path of a flashlight in real time. |
Previous | Next *| Subscription Deals |*
|
