CURRENT ISSUE

Contests

bottom corner

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

FRAME GRABBER

The DanceBot’s vision is controlled by a small grayscale Electronics123.com C-Cam-2A miniature video camera. It is just 16 × 16 × 16 mm, uses less than 100 mW, and costs less than $20. It has five pins, three of which provide ground and 5-V power, a gamma mode, and an output. The output signal consists of a 1-VPP composite video signal when terminated with a 75-W resistor to ground. To watch the camera’s output, you can simply plug it into the composite input of your TV. It’s that simple! Understanding what the camera sees is a bit harder, so I’ll take it one step at a time.

First, you have to digitize the analog signal. To sample slower waveforms with the Propeller, you would typically use delta-sigma modulation with a capacitor and a resistor. But because you need to resolve the individual pixels in a frame, you need a faster solution.

The ADC08100 is a 20- to 100-Msps, 8-bit ADC. With a clock signal, it will output the digital equivalent of its input voltage on its eight digital outputs. We’ll use one of the Propeller’s 16 hardware counters to clock the ADC at 10 MHz and read the result from the Propeller’s I/O port (see Figure 2).

Figure 2
Figure 2—This is the frame grabber hardware. The C-Cam-2A outputs an NTSC composite signal in pin 3. This is digitized by the ADC08100 whose output D4..D7 is fed to the Parallax Propeller.

At this point, your robot is ready to take its first peak at the world—one scan line at a time (see Photo 2).

Photo 2
Photo 2—ViewPort shows raw NTSC signal from the camera, as digitized by the ADC.

Listing 1 is a short program that uses ViewPort to trigger and display the NTSC waveform generated by the camera.

The program starts by configuring the Propeller’s clock to run at 80 MHz and including the three objects you need. The vp commands register is a component that will quickly sample the state of the I/O port and configure the ViewPort interface. Finally, the Freq.Synth call generates a 10-MHz clock to drive the ADC. Photo 2 shows the oscilloscope with a timescale of 10 µs/division. The waveform represents a horizontal trigger followed by a color burst and 50 µs of data. A pixel’s brightness is proportional to the signal’s value.

To complete your frame grabber object, your algorithm must detect the horizontal and vertical sync marks and then compress the pixel data into memory. Vertical and horizontal sync marks differ in the amount of time the signal stays at the lowest level. After detecting a vertical sync mark, the code initializes a new frame and processes one video line at a time. For each line, it detects the horizontal sync, skips past the color burst, and then samples the ADC’s value every five instructions—for a line length of 240 pixels. To fit a complete video frame into the Propeller’s global memory, I store 4 bits of brightness information for each pixel. This data is accessible by all eight cogs on the Propeller. In the DanceBot, one cog is dedicated to run this program continuously to sample video from the camera at 30 fps with a resolution of 240 pixels × 200 lines × 4 bits/pixel.

Listing 2 is an example program that uses the VideoCapture object. This program configures the clock and imports some objects and then starts the video cog to capture frames. Then, it configures ViewPort to display the streamed video. The Spin code draws a thick black line in the middle of the frame by setting parts of the array to 0. Photo 3 shows the project’s first view of the world.

Photo 3
Photo 3—This is the system’s first picture of a fire truck. Notice the black line at the cross hairs.

Previous | Next                *| Subscription Deals |*

 


bottom corner