Embedded Eye

Give your gizmo the gift of sight

OVERVIEW:

This is a quick start set of instructions to demonstrate a simple optical flow sensor using an ArduEye and a Tam4 (4x32) chip. Note that in order to view images or sense optical flow, you need a lens on or above the Tam chip! Note that you need to provide the 5V Arduino board.

We will be updating this page as people ask more questions.

Pricing/Ordering: Refer to the products page on Centeye for pricing / ordering information. Look for the "ArduEye Shields".

 

FILES:

Below are the first release files for the Arduino:

Eagle CAD files for the Rox1 board: ArduEye_Rox1_v1.zip

Arduino script (compile Tam4_OpticFlowExample_r1): Tam4_OpticFlowExample_r1.zip

Tam series chip documentation (including chip schematic diagram!): Tam_Chip_Instructions_2011-02-28.pdf

Bonding diagram between Tam chip and Rox1 board: BondingDiagram_Rox1_Tam.pdf

 

HARDWARE INSTRUCTONS (FULL SIZED ARDUINO):

You will need to break apart the 5-pin header into three parts and solder them to the ArduEye Rox1 board. Please visit this forum post for instructions.


SOFTWARE INSTRUCTIONS:

0) Preparation:

First of all, since this posting deals with Arduinos, it assumes that you are familiar with both the Arduino hardware and the Arduino development environment. It is an easy platform to learn, so you should very easily master the preliminary material needed for this post. You should already have an Arduino board working with your computer, and be able to write programs that manipulate the Arduino's IO pins and send/receive data to the PC using the serial link.

Second, you should look through the above included files, in particular the instructions for using the Tam chip and the source code (e.g. "Arduino sketch") for this demonstration program. The code is quite extensively documented- many questions you may have can be answered in the code itself. You should also have a level of sophistication in C programming and elementary data processing that you can look at existing code and understand what is happening. An elementary background in image or signal processing is also helpful, though not required.

1) Hooking up the Rox1 board to a full-sized Arduino:

The board plugs into the Arduino as shown below. You will need to make 5 connections between the Rox1 board and the Arduino: VDD and GND which connect respectively to the 5V and GND Arduino lines on the lower left in the picture, ANA which connects to the Arduino ANALOG 0 line on the lower right, and IO6 and IO7 which connect respectively to DIGITAL 6 and DIGITAL 7 Arduino lines on the top. You will need a soldering iron to do this- use the 5 headers that came with the Rox1 board. You may now plug the Arduino into your computer. NOTE: These instructions assume use of a 5V Arduino board- the Tam chips need 5V for optimal operation.

2) Compiling and uploading the code:

Unpack Tam4_OpticFlowExample_r1 into it's own folder and compile the sketch file of the same name. (You will see three other sketch files as well.) Upload it to the Arduino.

3) Start the serial monitor:

Start the serial monitor in the Arduino environment. You should see the following welcome message appear:

 

Sample code for grabbing an image from a 4x32 Tam4 chip
Choose command from list below
 
Press 0 to turn off optical flow
Press 1 (number) to select IIA optical flow
Press 2 to select HR-on-edge optical flow
Press 3 to select simple gradient algorithm
Press a to dump an image using ASCII rendering
Press c to grab calibration image
Press C to dump the calibration pattern in MATLAB format
Press f to output frame counter
Press m to dump MATLAB image
Press r to retrieve calibration pattern from EEPROM
Press s to store calibration pattern to EEPROM

 

At the top of the serial monitor is a command area where you can enter simple commands that get sent to Arduino via the USB link. To enter a command, click in the command area, press the letter corresponding to the command, and press <enter>.

 

4) Calibration:

The first thing you need to do is to calibrate the sensor and acquire a fixed pattern noise mask. The best way to do this is to expose the sensor to a uniform background- you can hold it right up to an LCD screen displaying a uniform color, or you could simply place a white sheet of paper over or on top of the lens.

Enter the command "c" (lower case) to calibrate the sensor. This causes the calibration mask to be grabbed. You can now stop covering the sensor with white paper or holding it up to a monitor or whatever you were doing to give it a uniform background.

Enter the command "s" to save the mask to the Arduino's EEPROM. The two commands produce the following output on the serial monitor.

 

Calibration pattern grabbed from image sensor
Calibration pattern stored to EEPROM

 

Note that once you have saved the calibration mask to EEPROM, you can recall it at later times with the "r" command.

If you use MATLAB, you can dump the calibration pattern to the serial monitor using the "C" (UPPER case) command. The output should be something like this:

 

---Calibration Mask----------
Data = [
14 31 ... 15 21 31 7
15 17 ... 14 20 30 8
22 9 ... 7 10 15 2
16 16 ... 13 14 32 9
];
-----------------------------

 

5) Grab and display an image

Now that the sensor is calibrated, you can grab and display an image. If you aim the sensor towards a bright light, or hold a flashlight high over it, and enter the "a" command, you might get something like this:

 

---Image---------------------
.,,,,............               
          ..,=@##*,,...         
           .,-=*=-...    ..,---.
                                
-----------------------------

 

Alternatively, you can dump the image in a MATLAB readable form using the "m" command, which will produce an output similar to that below:

 

-----------------------------
Data = [
310 306 307 307 ... 321 322 322 322
319 319 319 319 ... 316 316 317 319
319 318 318 318 ... 311 311 312 316
319 318 319 318 ... 322 322 322 323
];
-----------------------------


6) Optical Flow

The sample sketch includes three different optical flow algorithms, which may be correspondingly selected using the "1", "2", or "3" commands. If you enter one of these commands, and move the sensor around, you will get an output much like this:

 

*           #                               
                *#                               
             *  #                                
              * #                                
             * #                                 
                 #     *                         
                     #            *              
                        #       *                
                           #         *           
                             #    *              
                                #       *        
                                 # *             
                                 #               
                                *#               
                           *   #                 
                     *       #                   
                  *       #                      
                  *     #                        
                  *    #                         
          *         #                            
          *      #                               
          *    #                                 
            *  #                                 
                #     *                          
                  #      *                       
                      #         *                
                        #     *                  
                           #        *            
                            #   *                
                               #          *      
                               #                 
                                #  *             
                          *    #

 

The * symbols plot instantaneous frame-by-frame optical flows. The # symbols plot a running average of the optical flow.

You can turn off the plotting of optical flow by entering the "0" command.

The three optical flow modes are summarized as follows:

Mode 1: One dimensional version of Prof. Mandyam Srinivasan's Image Interpolation Algorithm (IIA).

Mode 2: Variation of the biologically in spired Hassenstein Reichardt algorithm.

Mode 3: Simple implementation of the classic Gradient method.


7) How can I speed up the algorithm?

There is some room for optimization in the code itself, in particular in the selection of variables for the arithmetic operations. We leave that as an exercise for the reader, as the best optimization depends on the particular application. However another quick optimization is also possible- the above optical flow calculations use only one of the four rows of pixels. However all four rows of pixels are read out. Thus if the code were modified to just digitize the needed row of pixels, fewer ADC cycles will be required. The implementation is straight forward and left to the reader as an exercise.

 

Views: 611

Reply to This

© 2012   Created by Geoffrey L. Barrows.   Powered by .

Badges  |  Report an Issue  |  Terms of Service