Intelligent Robotics - CMUcam2
CMUcam2
We use the CMUcam2 vision sensor in the robotics lab - it is made up of a camera and a microcontroller. It can identify and track an object based on colour or movement.
Connections
Communication with the IntelliBrain controller is via the RS232 serial port marked COM2 on the IntelliBrain board. The CMUcam2 is supplied with cable to connect to the board and a mounting kit to fix the camera to the Lego body of the robot.
When connecting to COM2, ensure that the black (ground) cable is on the outer edge of the board and the red cable is nearest the power switch.
In order to focus the camera and setup colour ranges for tracking objects, you will need to connect the camera directly to the PC.
There is a serial adaptor that comes with the camera - attach the standard female serial cable to the serial cable that is connected to the PC. The other end of the adaptor should be connected to the CMUcam2 at the port marked RS232. It should be connected so that the side with the red wire is on the outside of the CMUcam2.
There is a small power switch just above the cable that connects the CMUcam2 to the Intellibrain. Make sure you turn on the CMUcam2 before you use it. Note that the voltage regulator just above the power switch can get very hot. Be careful handling it.
CMUcam2gui
We have a new GUI, developed by David Rees, available for machines that cannot run the old Java GUI. It works in essentially the same way as the older GUI.
Start the CMUcam2gui application - (Which seems to fail to intialise if RoboJDE is loaded). Enter the serial port (1) in the popup box.
Once the camera has been detected, click on the Grab Frame button to the lower right of the application's main window. Iterate between making small adjustments to the camera lens and capturing frames unti you get the image as sharp as possible.
Tracking Objects
The CMUcam2 can track objects in two modes: colour tracking or movement tracking. Colour tracking follows a uniquely coloured object in its field of view by using the built-in microcontroller to scan each video frame pixel by pixel. The microcontroller compares the individual colour components of each pixel - red,green and blue, or Cr, Y, Cb - with a range for each of these colour components that you have defined. Motion tracking looks at the differences between frames. Colour tracking is generally the most useful of the two modes, and so we will concentrate on it here.
Determining the colour range to track is the trickiest aspect of using the CMU2cam sensor. Again, you should use the CMUcam2gui application to help you gather the neccesary readings. Further information and advice on how best to go about it is given in the Ridgesoft "Vision Sensing with the CMUcam" documentation and the CMUcam2 manual.
Example code
import com.ridgesoft.robotics.sensors.CMUcam.*;
import com.ridgesoft.io.Display;
import com.ridgesoft.intellibrain.IntelliBrain;
public class CMUcamTest {
public static void main(String args[]) {
try {
Display display = IntelliBrain.getLcdDisplay();
display.print(0, "CMUcam2Test");
display.print(1, "Starting");
CMUcam2 camera = new CMUcam2(IntelliBrain.getCom2(), 115200);
camera.open();
camera.setRGBMode(false); // switch to CrYCb mode
camera.setWhiteBalance(true);
camera.setAutoExposure(true);
Thread.sleep(5000); // let the sensor adjust
camera.setWhiteBalance(false); // disable further adjustment
camera.setAutoExposure(false);
// tracking parameters vary based on the specific object being
// tracked, the camera s characteristics and the lighting conditions
// configuring the colour range can be quite tricky ...
// camera.trackColor(64, 94, 22, 94, 223, 243); // blue cup, CMUcam
camera.trackColor(119, 179, 24, 114, 34, 94); // red cup ??, CMUcam
while (true) {
Thread.sleep(2000);
CMUcamTrackingData trackingData = camera.getTrackingData();
if (trackingData != null) {
display.print(0, "mx: " + trackingData.mx +
" my: " + trackingData.my);
display.print(1, "c: " + trackingData.confidence +
" p: " + trackingData.pixels);
}
else {
display.print(0, "No camera data");
display.print(1, "");
}
}
}
catch (Throwable t) {
t.printStackTrace();
}
}
}