Author Topic: Need help with interfacing CMUCam3 with the Axon  (Read 6475 times)

0 Members and 1 Guest are viewing this topic.

Offline u0607843Topic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Need help with interfacing CMUCam3 with the Axon
« on: February 24, 2009, 04:06:28 AM »
Sorry for the double post, I just realised I posted this question in the wrong forum section... :-[

-----------------

Hi all!

Would like to ask for some help regarding the interfacing of the CMUCam3 with the Axon mcu. For now, the plan is to have the Axon send over a byte via the uart2 port to the serial port for the CMUCam3, and have the red LED on the CMUCam blink a couple times.

This is what I've done so far:
 1. Editted the CMUCam camera emulation program so that when I typed in a '9' on the CMUCam Frame Grabber (its terminal program), the LED will start blinking.

 2. Connect the UART2 pins on the Axon to those corresponding on the CMUCam3 (i.e ground to ground, TX to RX and vice versa).

 3. Initialised the UART ports on the Axon and wrote a simple program to continuously send a '9' byte via the uartSendByte function. Just to double check, I'm sending both this 9 byte to the CMUCam and the PC itself. Below is the sample code:

Code: [Select]
while(1)
{
         uart1SendByte('9');
         uart2SendByte('9');
         delay_ms(200);
}


But when the code is being run on the Axon, nothing happens on the CMUCam itself. The '9' is being printed continuously on hyperterminal though, so it means that uart1 should be working properly. Testing the program manually on the CMUCam's terminal program (i.e. typing '9') yields the desired results though. Even tried sending the ASCII character instead to test but it didn't work as well. Checked the baud rates too and made sure they were the same. So I'm not sure what's the issue here, and therefore would like to seek advice from people who may have had experience with the CMUCam3 before  ;D


My background is that of (pretty much) a noob though, in both robotics and programming (studied enough C before though to have some basic understanding of how the code works). Just that the company I'm doing this for wanted me to use the CMUCam, although they don't mind it being simple at the beginning.

Thanks!  ;D

Offline u0607843Topic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #1 on: February 24, 2009, 04:11:45 AM »
On a side note, there's another problem I seem to be facing, although its unrelated to this topic.

Is there a limit to the array size that can be created? I've tried creating a 2-D array of 4x10 and it can store and print values just fine, but when I increase the array size to 88x100 nothing seems to appear on the hyperterminal. I will be using this array to store values taken from a sensor to be transmitted back to the PC, so I hope the experts out there could comment on this as well...thanks!  :)


Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #2 on: February 24, 2009, 05:14:10 AM »
The Axon is an Atmega640 MCU and it has 8Kilobytes of SRAM. Your 88x100 array takes up 88 x 100 = 8800 kilobytes (if it's an array of char, more if it's an array of int). 8800 = 8.8K > 8K so that's why it's not working, you exceeded the maximum amount of SRAM on the MCU!

Why would you want to store that amount of data on the MCU? If your planning on sending it to the PC then just send it as soon as it's available, don't buffer it locally: let the PC do that, it's ram is measured in Gigabytes, not Kilobytes!

Offline u0607843Topic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #3 on: February 25, 2009, 02:02:42 AM »
I see...I guess it'd be better for me to directly send the info over to the PC to be logged then.

Thanks for the reply!

Now as for the CMUCam...anyone?  ;D

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #4 on: February 25, 2009, 07:35:46 AM »
You can also use a I2C EEPROM and store there your array and send it to the PC only when it is convenient.
Check out the uBotino robot controller!

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #5 on: February 25, 2009, 10:15:11 AM »
Hmmmm do you have the baud rates set properly? (sorry, but its a common mistake people make)

Offline u0607843Topic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #6 on: February 25, 2009, 08:57:37 PM »
Yes, I've checked the baud rates to make sure they were set properly (at 115.2kbps).

On closer inspection of the CMUCam code, I believe that perhaps its not the fault of the UART but perhaps the nature of the coding itself. Here's an excerpt of the CMUCam code with regards to (what I believe) is the data capturing:

Code: [Select]
  while (true) {
    cc3_channel_t old_coi;

    print_prompt ();
    error = false;
    if (demo_mode == true) {
      n = 0;
      command = TRACK_WINDOW;
    }
    else if (raw_mode_input) {
      n = cmucam2_get_command_raw (&command, arg_list);
    }
    else {
      n = cmucam2_get_command (&command, arg_list);
    }
    if (n != -1) {
      switch (command) {

...


      case LED_0: // The case editted such that the LED will blink
int led_blink; // when I type a '9' into the terminal program
for (led_blink=0; led_blink<5; led_blink++) //
{ //
cc3_led_set_state (0, true); //
cc3_timer_wait_ms (500); //
} //
        if (n != 1 || arg_list[0] > 2) { //
          error = true; //
          break; //
        } //

        print_ACK ();
        auto_led = false;
        if (arg_list[0] == 0)
          cc3_led_set_state (0, false);
        if (arg_list[0] == 1)
          cc3_led_set_state (0, true);
        if (arg_list[0] == 2)
          auto_led = true;
        break;

...


  return 0;
}


// And below are the functions for getting commands to be input into the switch command

int32_t cmucam2_get_command (cmucam2_command_t * cmd, uint32_t * arg_list)
{
  char line_buf[MAX_LINE];
  int c;
  char *token;
  bool fail = false;
  uint32_t length, argc;
  uint32_t i;

  length = 0;
  c = 0;
  while (c != '\r') {
    c = getchar ();

    if (length < (MAX_LINE - 1) && c != EOF) {
      line_buf[length] = c;
      length++;
    }
    else {
      // too long or EOF
      return -1;
    }
  }
  // null terminate
  line_buf[length] = '\0';

  // check for empty command
  if (line_buf[0] == '\r' || line_buf[0] == '\n') {
    *cmd = RETURN;
    return 0;
  }

  // start looking for command
  token = strtok (line_buf, " \r\n");

  if (token == NULL) {
    // no command ?
    return -1;
  }

  // get name of the command
  for (i = 0; i < strlen (token); i++) {
    token[i] = toupper (token[i]);
  }

  // do lookup of command
  fail = true;
  for (i = 0; i < CMUCAM2_CMDS_COUNT; i++) {
    if (strcmp (token, cmucam2_cmds[i]) == 0) {
      fail = false;
      *cmd = i;
      break;
    }
  }
  if (fail) {
    return -1;
  }

  // now get the arguments
  argc = 0;
  while (true) {
    // extract string from string sequence
    token = strtok (NULL, " \r\n");
    // check if there is nothing else to extract
    if (token == NULL) {
      // printf("Tokenizing complete\n");
      return argc;
    }

    // make sure the argument is fully numeric
    for (i = 0; i < strlen (token); i++) {
      if (!isdigit (token[i]))
        return -1;
    }

    // we have a valid token, add it
    arg_list[argc] = atoi (token);
    argc++;
  }

  return -1;
}

int32_t cmucam2_get_command_raw (cmucam2_command_t * cmd, uint32_t * arg_list)
{
  bool fail;
  int c;
  unsigned int i;
  uint32_t argc;

  char cmd_str[3];
  cmd_str[2] = '\0';

  // read characters
  for (i = 0; i < 2; i++) {
    c = getchar ();
    if (c == EOF) {
      return -1;
    }

    cmd_str[i] = c;
  }

  // do lookup of command
  fail = true;
  for (i = 0; i < CMUCAM2_CMDS_COUNT; i++) {
    if (strcmp (cmd_str, cmucam2_cmds[i]) == 0) {
      fail = false;
      *cmd = i;
      break;
    }
  }
  if (fail) {
    return -1;
  }

  // read argc
  c = getchar ();
  if (c == EOF) {
    return -1;
  }
  argc = c;
  if (argc > MAX_ARGS) {
    return -1;
  }

  // read args
  for (i = 0; i < argc; i++) {
    c = getchar ();
    if (c == EOF) {
      return -1;
    }

    arg_list[i] = toupper (c);
  }

  // done
  return argc;
}


I've left out code which I think isn't relevant to this problem, but my apologies if I end up leaving something important out. In any case it seems that maybe the issue lies with the "cmucam2_get_command_raw" or "cmucam2_get_command" functions? Maybe I have to edit those instead so that it reads directly from the UART pins?

Thx!

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #7 on: February 26, 2009, 05:24:51 AM »
I haven't fully read through your code but . . . the code I supply I know works. Look at the UART section of my Axon code tutorial page, it'll show you how to read in data streams (such as for the Blackfin camera, gps, CMUcam, etc).

Offline u0607843Topic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #8 on: March 19, 2009, 02:49:12 AM »
Been a while since I was working on this issue to concentrate on other stuff, but its coming back to haunt me :p

Thx for the link to the uart section, followed it pretty diligently!

Anyway, updates on the problem so far:

1. Had tested the uart2 port with a bluesmirf gold bluetooth module, and hyperterminal can read the output from the rprintf functions, so nothing wrong with the uart port.

2. Tested the CMUCam3 with the bluesmirf as well, the cmucam software and hyperterminal can both read the output and write in input to trigger reactions, like blinking the LEDs, and get the string outputs from the CMUCam.


These 2 cases seem to show that bluetooth connections between the PC and the axon/cmucam3 yield no problems. So no problems with the uart ports of both the CMUCam and Axon.


However, the main issue is when I connect the pins from the uart port of the Axon straight to the corresponding uart port of the CMUcam. I'm having the Axon print the same string onto the CMUCam3 (in this case, "L0"), but while doing the same thing on the PC triggers a response, doing it from the Axon triggers no response.

So my question is, is there something different about sending an input from a terminal console on the PC to the CMUCam, and getting the Axon to print the trigger function onto the CMUCam directly that is causing this lack of response to the latter? Like maybe hardware settings or something along that line that is lacking...

Would appreciate any help on this issue. Thx!  ;D

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #9 on: March 19, 2009, 03:22:59 AM »
There is the possibility that you are getting the data into the Axon properly, but processing it wrong. Do this:

CMUcam3 -> Axon UART3 -> USB -> hyperterminal

Basically read in data from the CMUcam3, and immediately spit it right back out to USB:
Code: [Select]
int data;
rprintfInit(uart1SendByte);//output to USB

while(1)
    {
    data=uart3GetByte();//read UART3
    if (data!=-1)//check for data
        rprintf("%c",data);//use %d to output ints
    }

That should help you debug the problem!

Offline u0607843Topic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #10 on: March 19, 2009, 11:24:18 PM »
Thx for the input! Will be testing it out shortly  :)

Offline u0607843Topic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #11 on: March 20, 2009, 01:13:06 AM »
After testing it out, it seems that there are communication problems (which I'm still unable to resolve) between the CMUCam3 and the Axon uart ports.

Using the code kindly provided by Admin, I've tested the connection between the axon and cmucam3 uart ports, testing with all 3 uart ports and even varying the baud rates to mismatching values to test the results. In all cases, rubbish data was printed out by the axon, even when changing from char to decimal values.

The CMUCam datasheet says that the cmucam print output is in ASCII format, so there should be nothing wrong with the code. And in any case it works all fine when connected to the PC itself, so my conclusion is that it has to be something in between that is causing the data to corrupt...

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #12 on: March 20, 2009, 01:24:04 AM »
The CMUCam datasheet says that the cmucam print output is in ASCII format, so there should be nothing wrong with the code. And in any case it works all fine when connected to the PC itself, so my conclusion is that it has to be something in between that is causing the data to corrupt...
Oh! ASCII format! That's the problem. You need to strip ASCII off.

Do this:
Code: [Select]
data = data & 0x0F; //&0x0F converts ascii to char

Offline u0607843Topic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #13 on: March 20, 2009, 01:56:29 AM »
Thx for the fast replies Admin! Great to be in the same time zone (SEA)  :P

I believe this is the code i'm supposed to be inputting?

Code: [Select]
int data;
rprintfInit(uart1SendByte);//output to USB

while(1)
    {
    data=uart3GetByte();//read UART3

    if (data!=-1)//check for data
           {
           data = data & 0x0F; //&0x0F converts ascii to char
           rprintf("%c",data);//use %d to output ints
           }
    }

Hm well I'm still not getting the desired result, but if there's any consolation the line feed commands from the CMUCam are actually printing out correctly now.

Will look through the datasheets again in more detail...

Offline u0607843Topic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: Need help with interfacing CMUCam3 with the Axon (solved)
« Reply #14 on: May 26, 2009, 07:17:12 PM »
Sorry to dig up an old thread.

Been a while since this problem was resolved (with the help of a great partner), so I'd thought I should share the solution to getting the CMUCam3 to talk with the Axon for those who might be in a similar situation.

I'll try to summarise the essential keypoints in a checklist:

1. Make sure to connect the CMUCam3 TTL pins to the Axon UART pins (check the datasheet for the pin locations). Also REMEMBER to remove the level shifted serial jumper on the CMUCam3 TTL pins.

If you don't do so, the CMUCam3 can receive commands nicely from the Axon, but will send out rubbish data to the Axon (probably since the voltage levels are different or something, not too sure)


2. The baud rate for the connection between both items will have to be set to 57600 bps, somehow if you use the default setting of 115200 for the CMUCam3, the 6th data bit will always be mysteriously corrupted (although it works fine with bluetooth modules or RS232 connection to PC).

Lower baud rates do work as well, but if you're concerned about capturing the JPEG images, anything below 57600bps will cause it to take more than 1s to transfer the entire byte array over.


3. If you are programming a GUI to send a command to the CMUCam3 to take an image and send the JPEG data back to display on your GUI, you will have to ensure the following, otherwise the JPEG data will be corrupted:

            a. Change the rprintf.c source on the Axon side, under
Code: [Select]
void rprintfChar(unsigned char c)
{
// do LF -> CR/LF translation
//if(c == '\n')                                     //comment out these two lines that cause the LF -> CR/LF
// rputchar('\r');                             //translation, it will corrupt the JPEG data
// send character
rputchar(c);
}

      But take note that this means that if you were printing out other stuff from the Axon you would have to manually append a /r/n to every new line you intend to print out.


            b. On the GUI side, save the char array received from the Axon as a byte/binary format to prevent the same LF -> CR/LF problem from occurring too (depends on compiler I believe). VB does it easily, I used C++ and had to scour for the appropriate source code to convert it. Saw a thread about someone asking about doing it in C not too sure if it's the same as C++. Save the file as a .jpg file and it should be all ok!



Doing the above should allow a clean data transfer between the Axon and CMUCam3. Hope this information would be helpful to those facing similar problems!  :)
« Last Edit: May 26, 2009, 07:19:41 PM by u0607843 »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #15 on: May 27, 2009, 06:38:30 AM »
Quote
2. The baud rate for the connection between both items will have to be set to 57600 bps, somehow if you use the default setting of 115200 for the CMUCam3, the 6th data bit will always be mysteriously corrupted (although it works fine with bluetooth modules or RS232 connection to PC).
I suspect this has to do with the error rates. The Axon UART, at 115.2kbps, has a -3.5% error rate. I'm not sure what the error rate on the CMUcam is, but if the error is too far off from the Axon, it'll make sense that it gets corrupted like this.

Perhaps try 76.8k?

(to know error rates, see page 231 of the ATmega640 datasheet)

Offline u0607843Topic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: Need help with interfacing CMUCam3 with the Axon
« Reply #16 on: June 01, 2009, 12:25:53 AM »
I suspect this has to do with the error rates. The Axon UART, at 115.2kbps, has a -3.5% error rate. I'm not sure what the error rate on the CMUcam is, but if the error is too far off from the Axon, it'll make sense that it gets corrupted like this.

Perhaps try 76.8k?

(to know error rates, see page 231 of the ATmega640 datasheet)

After some testing, 76.8K does work, but values that are any higher do not.

Thx!

 


Get Your Ad Here