PDA

View Full Version : Interfacing the CMUCAM2 to the Prop chip



Bryan K.
10-23-2006, 01:26 PM
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.

kerryw
10-24-2006, 10:05 AM
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[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[x] := uart.rx 'get current color tracking results from camera

__LONG[cx] := cambuffer[2]

__LONG[cy] := cambuffer[3]

__LONG[cpixels] := cambuffer[8]

__LONG[confidence] := cambuffer[9]

El Paisa
10-24-2006, 11:09 AM
kerryw,
I have a avrcam.

How close to the cmucam?

Any help will be greatly appreciated.

Bryan K.
10-24-2006, 01:32 PM
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 Paisa
10-24-2006, 10:33 PM
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.

kerryw
10-24-2006, 11:02 PM
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


и

acantostega
10-26-2006, 07:50 AM
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.
10-26-2006, 11:22 PM
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.

kerryw
10-26-2006, 11:26 PM
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

acantostega
10-27-2006, 02:32 PM
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.
04-04-2007, 08:29 AM
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?