C code to get information from CMUcam2

Hello everybody
I am using CMUcam2 that is installed on a robot that uses an Altera Board.
The camera is connecting to the board using a UART port.

I am using Altera NIOS II IDE environment to do the C language to test and run the C code that communicates with the camera.

So it is a C code that runs on the Altera board.

Can anybody help me to know what’s the basci C code that communicates with the camera.

I need to get color and light information from the camera.

Any help will be apreciated.:slight_smile:

http://kevin.org/frc/

You will find the cmucam2 documentation there

Hello and welcome to Chief Delphi. It sounds like you’re using a different system than we all use in our competition, but it’s likely that some people around here will still be able to help you.

If you use the documentation that Max linked to, you should be able to figure out a lot about the CMUcam2 protocol. From the work I’ve done with it, it’s pretty simple. Send a few bytes out your UART, terminate it with a carriage return, and you’ll get back an ACK and/or the data you requested. All of the commands are documented in the CMUcam2 manual, and on Kevin Watson’s site. As for the actual code to read and write to your UART, that’s beyond the scope of my knowledge. Somebody else around here may know, or you can poke around on Google. Once you’ve got that figured out, the CMUcam2 interface is pretty simple. (As somewhat of a side note, you can play around with the commands and see what they do by plugging the CMUcam2 into your computer, and then using a program like Hyperterminal to send and receive the data.)

Thanks for your reply
But what do you think about this code, any notes please.

/* A simple program that sends an order to the CMUcam2 camera and
 reads back from it*/
:confused: :rolleyes: :] 
#include <stdio.h>
#include <string.h>
int main ()
{
FILE* fp;
char prompt = 0;
int Written_Char;

fp = fopen ("/dev/uart1", "r+"); //Open the camera port for reading and writing.
if (fp)
{
Written_Char = fputc(":TC\r",fp); // writing a character to the UART.
prompt = getc(fp); // Get a character from the UART.
fprintf(fp, "Closing the UART file.
");
fclose (fp);
}
return 0;
}

:smiley: :slight_smile:

Written_Char = fputc(":TC\r",fp);

i think you want to take the : out of that… you see a : before all the lines in the manual just because thats how hyperterm prompt is… take out the : and try that

That works fairly well - it looks like you’re using a UNIX-based system. I believe you’d be better off using the read/write syscalls for the UART interface on your device, i.e.:


#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

typedef struct track {
    uint8_t mx, my;
    uint8_t x1, y1;
    uint8_t x2, y2;
    uint8_t pixels, confidence;
} track_t;

int main()
{
    track_t camtrack;
    char buffer[64] = "tc\r";
    int fd = open("/dev/uart1", O_RDWR);
    if(fd == -1) {
        fprintf(stderr, "Error opening UART");
        /* do something */
    }

    write(fd, buffer, strlen(buffer));
    read(fd, &camtrack, sizeof(track_t));

    close(fd);
    return 0;
}

Or something like that.