Quote:
Originally Posted by harakiri
Thanks your help. B2Bot is really old. But i see it similiar my project. My project is a robot have 2 wheels controled DC motor,and one custom wheels. I use data from cmucam2 to control robot tracking object. I really don'n make robot before, so i need help. I use DSPIC and mplab. i read Ryan's information, but i didn't know much. If you made successful or know about it, please talk with me.
Thanks.
|
The best way to start is to break the project down into sections:
1. The CMUCam itself
2. The communication channel between the dsPIC and the CMUCam
3. Sending the correct commands to and interpreting the response from the CMUCam
4. The control algorithm to turn the extracted vision information into motor movement
5. Outputting the motors control signals.
Taking them in that order:
1. If you haven't already done so, download the Java GUI for the CMUcam 2 available on the
download page. Hook the CMUCam 2 up to your computer's serial port (or buy a USB-serial converter) and get it so you can connect to the camera from your computer. This will require hooking up power to the camera as well. Once you get communication going, you can experiment with the various capabilities of the camera, and this will help you get your thresholding settings right.
2. If you're already need to purchase a USB-serial converter for step 1, think about getting one that outputs on the TTL level instead of the standard RS-232 levels. The popular model that does this are
FTDI Cables. This will allow you to interface with the camera on the same interface that your microcontroller (a.k.a. uC, this is your dsPIC) will use. Otherwise, you can use the standard Dsub 9 connector connected directly to your RS-232 (serial) port.
If you get a TTL serial module, this will also allow you to test your uC's serial port. Verifying that both ends of the connection are working independently will save you a lot of trouble trying to figure out whether your code, your uC, or the CMUcam is at fault.
To get basic serial communication running, consult the library documentation that came with MPLAB. The serial port on the dsPIC is called the USART port (Universal Synchronous/Asychronous Receiver/Transmitter some models drop the synchronous so it just becomes UART) in the documentation. Using the libraries that Microchip provides will save you a lot of headaches trying to figure out which registers you need to set to which values. To start off, try making a simple program that will echo back on the serial port any characters that it receives, so if you run a terminal program on your computer (I suggest
TeraTerm if you're on Windows) and type in characters, you should see them echoed back to you. If it's not working (and you have local echo turned off), you won't see any characters appear when you type. At this point, if you don't know how serial ports on computers work in general, it would be a good time to go do a Google search, because you'll be very lost if you don't. Once you're sure that you have a working program and that you understand why it works, move on to the next step.
3. Download the
CMUcam 2 manual and read through it. Once you've read all of it, a good place to start working is the "Testing the Firmware" steps on page 12 (numbered as page 11). This will allow you to interface with the camera from your computer, but you'll get to see the interface that your uC will be using instead of the pretty Java interface, and you'll get a sense of which commands you need to send to do what, and what the responses from those commands look like. After you've finished "Testing the Firmware," you can move on to some of the other commands listed on the command glossary starting on page 29. Try to run the same commands in the same order that your program will need to and write down which commands you used and what the expected response from each is.
Then use what you learned about how to use your uC's USART port to write a basic program that does simple interactions with the camera. Try hooking up an LED or some other simple feedback device to the uC that you can turn on in your program once it has successfully sent and received a response to each of the list of commands. If your particular uC happens to have two USART ports (some do, some don't), you can hook one to the camera and the other to the computer, which can be a good way for your uC to give you lots of information about what it's doing. You won't have this luxury, though, if you only have one USART port.
Once you've got communication going between the CMUcam and your uC, and you've essentially written the program that will get the CMUcam to track objects (this is where the settings you found in step 1 will come in), move on to the next step.
4. Assuming you're just doing basic color blob tracking, the target information will be returned to you as two points that form a rectangle that bound the blob, and a centroid, which you can think of as a "center of mass" for the color blob. At least for basic tracking purposes, you can just make use of the centroid and ignore the rest. If all you want to do is just have your robot follow a target around, the easiest control algorithm to use is simply to steer based on the position of the centroid. If the centroid is in the center of the camera's view, drive straight. As the centroid moves more to the left, steer more left, and similarly for turning right. If you have a tilt axis on your camera, you can control that using the vertical position of the centroid. If you're using a simple two motor differential drive (one left, one right), your control algorithm could look something like:
steer = k * (centroid_x - screen_width/2)
left_wheel = speed + steer
right_wheel = speed - steer
where k is a constant that describes how quickly the robot will turn. Now that you have a method to transform your vision data into motion control data, you can move on to controlling the motors.
5. How you control your motors will be very dependent on how you have your system set up. It's probably going to condense down to outputting some a square wave with some parameter that is dependent on the speed you want that motor to go. If you are using a simple H-bridge motor controller, the parameter to
control is the duty cycle of the wave, or what percentage of time the output line stays high. If you're using a modified servo or an RC motor controller that accepts servo control signals, you will encode the desired speed by the amount of time the wave stays high: a 1.5 millisecond pulse is usually off, while 1-1.5 ms is backwards and 1.5-2 ms is forward (1 ms and 2 ms are full backward and full forward). After this pulse, the standard is to wait about 20ms before sending another pulse. If you want some help with this section, you'll have to post more information about your electrical design.
Hopefully that's enough to get you started. As you said, the CMUcam 2 is a fairly old piece of hardware, the dsPIC is newer, and so you will be lucky if you find somebody who's done a similar project on the same hardware. But in the end, you'll have more fun if you actually do it yourself, if you're willing to put in the time. At this point, I'd say you have the choice to either spend time learning how to use the hardware you have, or you can spend money getting new hardware. Don't be afraid to ask questions, but don't expect somebody to hand you a perfect answer fully formed.
Good luck,
--Ryan