CMUcam Tutorial

Using the CMUcam on your robot is easy.  This tutorial will detail using the CMUcam1.
Here is the CMUcam manual: http://www.seattlerobotics.com/CMUcamManualv15A.pdf

 

First apply power to the CMUcam as shown in this diagram:

 

Then connect the Data wires as shown in this diagram. Be sure to remove the Max232 chip.

 

Connect the GND wire of the CMUcam to a GND pin on your microcontroller. Connect the SX28 Transmit pin to your Rx pin of the microcontroller( on the Axon I chose to use the Rx of UART0). Connect the SX28 Receive pin to your Tx pin of the microcontroller (on the Axon I chose the Tx of UART0).

 

Now that the electrical connections are set up , we move on to programming.

NOTE: The following code was made for the Axon microcontroller , but can easily be adapted.

UART Initialization:

uartInit();  // initialize the UART (serial port)
    uartSetBaudRate(0, 115200); // set UARTE speed, for Bluetooth  , this is the UART port

 

 

CMUcam Initialization

void CMUcam_Initialize(void)
    {
    rprintfInit(uart0SendByte);//change UART to CMUcam
    rprintf("RS");  // Reset CMUcam
    delay_ms(500);  // wait 500 milliseconds
    rprintf("cr 18 44"); // Set CMUcam to AutoExposure
    delay_ms(500);  // wait 500 milliseconds
    rprintf("RM 1");  // Set CMUcam to Raw Serial Mode
    delay_ms(500);   // wait 500 milliseconds
    rprintfInit(uart1SendByte);//change UART to USB
    rprintf("CMUcam Initialized");  // send out the message through USB
    }


 


Set Tracking of CMUcam
rprintfInit(uart0SendByte);
rprintf("TC 90 250 0 20 0 20");  // set tracking to this specific color

// format is minRed maxRed minGreen maxGreen minBlue maxBlue
delay_us(500); // wait 500 microseconds

 

Get Tracking Data

int CMUcam_MiddleMass(void) //echos # of characters expected for each command
{
int temp;   // set up temporary variable
    int counter=0;  //set the counter to 0
    int echo_counter=0; // set the echo_counter to 0
    int temp1;

    rprintfInit(uart1SendByte);//change UART to bluetooth
    temp = uart0GetByte();  // Get a Byte
    while (temp != 255) {    // Keep on getting new bytes until the byte = 255
        temp = uart0GetByte();
    }
    rprintf("Start= %d  ",temp);
    temp = uart0GetByte();  // Get a Byte
    while (temp != 77) {    // Keep on getting new bytes until the byte = 'M'
        temp = uart0GetByte();
    }   
    rprintf("M= %d ",temp);

    echo_counter = 8; // expect 8 bytes ( 0 thru 7)
        while(1) {
            temp=uart0GetByte();//returns -1 if no data present
       
            response[counter]=temp;//store values into an array
            counter++;  // add one to "counter" array
   
                if(counter == echo_counter)  // once the counter equals the echo_counter        
                {
                // successfully captured the entire M packet
                uartFlushReceiveBuffer(0);//flush out receive camera buffer to stop phase shifting
                delay_us(100);
                         
                temp1 = response[0];
                rprintf("MiddleMassX= %d  ",temp1);


            temp1 = response[1];
                rprintf("MiddleMassY= %d  ",temp1);

 

          temp1 = response[2];

  rprintf("MinimumX= %d  ",temp1);

         temp1 = response[3];
                rprintf("MinimumY= %d  ",temp1);

            temp1 = response[4];
                rprintf("MaximumX= %d  ",temp1);


                temp1 = response[5];
                rprintf("MaximumY= %d  ",temp1);

           temp1 = response[6];
          rprintf("Pixels= %d  ",temp1);

            temp1 = response[7];
                rprintf("Confidence= %d  ",temp1);


                return response[0]; // return MiddleMass of X axis
                } //endif

        } // end while
} // end sub


 

Sample Program

int data;


CMUcam_Initialize();  // Initialize CMUcam
rprintfInit(uart0SendByte);

rprintf("TC 90 250 0 20 0 20");  // set tracking to this specific color

// format is minRed maxRed minGreen maxGreen minBlue maxBlue


delay_us(500); // wait 500 microseconds

while(1) {

data = CMUcam_MiddleMass();   // get the MiddleMass value

if (data > 40) {

// do stuff, turn left, etc.

} //end if


if (data <40) {

// do stuff, turn right, etc.

} // end if

} //end while

 

Heres an example of a robot you can create using my code: