Shop OBEX P1 Docs P2 Docs Learn Events
Interfacing the CMUCAM2 to the Prop chip — Parallax Forums

Interfacing the CMUCAM2 to the Prop chip

Bryan K.Bryan K. Posts: 47
edited 2007-04-04 00:29 in Propeller 1
Is there any way to interface the CMUCAM2 to the Propeller 1 controller? I have been trying for the past several weeks, using different serial commands, defining the baud rate, and mode, but no luck. Any thoughts on compiling a serial communications program? I have gotten the CMUCAM2 to interface to the BASIC STAMP, however, the codes are COMPLETLY different.

Comments

  • kerrywkerryw Posts: 61
    edited 2006-10-24 02:05
    I have done this, so yes it is possible. After reading your post I'm not sure where you are having troubles. Have you been able to get any serial communications code to work from the prop? Does your circuit have resistors in the communications lines coming from the CMUCAM (to handle the difference between the prop's 3.3v and the CMUCAMs 5volts)? Here is my CMUCAM.spin code. Sorry about using the '_' characters to show indentation. I wrote this some months ago, and it wasn't meant for public consumption, so the comments are a bit sparse. This is also for the CMUCAM, not the CMUCAM2, but it is mostly the same. Your main code will just call the 'start' routine, then the 'track' routine as needed. If you need to change your tracking colors just set up the appropriate 'sendcommand' call as listed in the CMUCAM manual (I have a hardcoded one in the 'start' routine that was there just to get me started). I hope this is helpful.

    Kerry



    OBJ

    __uart : "FullDuplex"

    VAR

    ·__byte cambuffer[noparse][[/noparse]11]



    PUB start(rxpin, txpin)· 'the receive and the transmit pins that the prop chip uses to communication with the CMUCAM

    __uart.start(rxpin, txpin, 115_200) 'start uart

    __sendcommand(string("RS",13))

    __sendcommand(string("PM 1",13))

    __sendcommand(string("MM 1",13))

    __sendcommand(string("CR 19 33 18 44",13)) 'Auto White Balance and Auto Exposure both ON

    __waitcnt((clkfreq * 5) + cnt) 'Let WB and AE settle for 5 seconds before disabling

    __sendcommand(string("CR 19 32 18 40",13)) 'Auto White Balance and Auto Exposure both OFF

    __sendcommand(string("TC 100 255 0 40 0 40",13)) 'track for a RED object

    __sendcommand(string("RM 3",13))



    PUB sendcommand(stringptr)

    __uart.str(stringptr)

    __waitforprompt 'wait for camera to respond with a ":" prompt



    PUB waitforprompt

    __repeat until (uart.rx == ":") 'wait for camera to respond with a ":" prompt



    PUB track(cx,cy,cpixels,confidence) | x

    __uart.str(string("TC",13)) 'send Track Color command

    __repeat x from 0 to 10

    ____cambuffer[noparse][[/noparse]x] := uart.rx 'get current color tracking results from camera

    __LONG[noparse][[/noparse]cx] := cambuffer[noparse][[/noparse]2]

    __LONG[noparse][[/noparse]cy] := cambuffer[noparse][[/noparse]3]

    __LONG[noparse][[/noparse]cpixels] := cambuffer[noparse][[/noparse]8]

    __LONG[noparse][[/noparse]confidence] := cambuffer[noparse][[/noparse]9]

  • El PaisaEl Paisa Posts: 375
    edited 2006-10-24 03:09
    kerryw,
    I have a avrcam.

    How close to the cmucam?

    Any help will be greatly appreciated.
  • Bryan K.Bryan K. Posts: 47
    edited 2006-10-24 05:32
    kerryw,
    thanks for the coding. I will try it soon, to see if it works. m not sure if it will work with the avrcam,i dont know anything about it. I have always used the Parallax controllers, and was successful with the BS2.
  • El PaisaEl Paisa Posts: 375
    edited 2006-10-24 14:33
    Kerry,
    Never mind my question.

    The format of the program I am sure it will work with the avrcam, the only difference·is the command set which is different.
    I will try this afternoon.
  • kerrywkerryw Posts: 61
    edited 2006-10-24 15:02
    Here is some of the main code where I call the CMUCAM object:



    CON

    __CMUCam_tx_pin = 4
    __CMUCam_rx_pin = 5

    OBJ

    __cmucam : "CMUCam"

    PUB start | cx,cy,cpixels,confidence

    __cmucam.start(CMUCam_rx_pin,CMUCam_tx_pin)······················································· 'start the CMUCam using assigned recieve pin and transmit pin
    __repeat
    ____cmucam.track(@cx,@cy,@cpixels,@confidence)
    ____if(confidence < 8 OR cpixels < 2)
    ______cx := cy := cpixels := confidence := 0
    ____else······································································· 'found a color tracking target
    ______'YOUR CODE HERE


    ·
  • acantostegaacantostega Posts: 105
    edited 2006-10-25 23:50
    I have used the cmucam2 to do color tracking "succesfully", in that I can communicate and receive "TC" packets ok. Alas, the sensitivity of the cam to ambient light conditions has made contnuous tracking of an object difficult. I haven't grouped the routines as an object yet, but as simple functions. I'll post them when I grab them from my laptop.
    The FullDuplexSerial object has no problem in dealing with the 115200 bauds of the default cmucam2.
    Tip: use the binary format to transmit packet values as single bytes.
    Edit: I just read kerryw's code and mine's pretty much the same. It's pretty generic code!
    It'd be nice if someone grouped this stuff into "object" format.

    Post Edited (acantostega) : 10/25/2006 11:54:02 PM GMT
  • Bryan K.Bryan K. Posts: 47
    edited 2006-10-26 15:22
    I was talking to a programming consultant who used the CMUCAM2 in his work, he said it was hard to track color because of the ambient light. In sending the packets of data, the camera sends color and luminance in the tracking values. The CMUCAM2 cannot send just RGB values, it has to use the White balance to compensate. I don't know about other cameras, though.
  • kerrywkerryw Posts: 61
    edited 2006-10-26 15:26
    I had a lot more success with tracking colors after I changed the white balance and auto exposure settings.

    __sendcommand(string("CR 19 33 18 44",13)) 'Auto White Balance and Auto Exposure both ON

    __waitcnt((clkfreq * 5) + cnt) 'Let WB and AE settle for 5 seconds before disabling

    __sendcommand(string("CR 19 32 18 40",13)) 'Auto White Balance and Auto Exposure both OFF


    Basically I turned them on for 5 seconds, this lets the CMUCAM settle on a good value, then I turned them both off. Try this if you haven't already.

    Kerry
  • acantostegaacantostega Posts: 105
    edited 2006-10-27 06:32
    Yeah, the white balance and autoexposure settings help, but yout got be careful about what the cam's looking at when it does the WB. Another thing that helps to decrease sensitivity to intensity of ambient light is using YCrCb space instead of RGB space. It looks pretty funky in the Cam PC interface, too. In my code I do this with:

     lcd_cls
      uart_lcd.str(string("WB, AG on       "))
      uart_cam.str(string("CR 18 36 19 33",CR))
      c:=0
      repeat while c <> ":"
        c := uart_cam.rx
        uart_lcd.tx(c)
      timing.pause1s(3)
    
      lcd_cls
      uart_lcd.str(string("WB, AG off      "))
      uart_cam.str(string("CR 18 32 19 32",CR))
      c:=0
      repeat while c <> ":"
        c := uart_cam.rx
        uart_lcd.tx(c)
    
    
  • Bryan K.Bryan K. Posts: 47
    edited 2007-04-04 00:29
    I have sucessfully got serial communication with the camera, but only in rs232 mode. I am trying to get it to do TTL, but no luck. Is there anything programming related to change when making the switch from rs232 to TTL?
Sign In or Register to comment.