RoboJDETM v2.0

com.ridgesoft.robotics.sensors.CMUcam
Class CMUcam

java.lang.Object
  extended by com.ridgesoft.robotics.sensors.CMUcam.CMUcamBase
      extended by com.ridgesoft.robotics.sensors.CMUcam.CMUcam

public class CMUcam
extends CMUcamBase

Class to interface with the CMUcam.

This class manages communications with the camera, alleviating the need for to be concerned with the camera's communication protocol.

The documentation for this class describes the programming interface to this class. It does not describe how to use the camera. The camera user guide should be consulted to gain insight into how to use the camera and the purpose of each function provided by the camera.

The class provides for two methods of monitoring tracking data. The simplest method is by putting the camera into a tracking mode, then polling this class as needed to retrieve the latest tracking data and color statistics using the getTrackingData and getStatisticData methods. The second method of monitoring tracking data is to register a listener class using the addCameraListener method. This class will then forward tracking data and statistic data to the listener as it is received from the camera. This method uses an additional thread to interface with the listener. If data arrives from the camera faster than it can be processed by the listener, some data will not be forwarded to the listener.

The open method must be called before calling methods that issue commands to the camera.

The following procedure may be used to receive camera tracking data:

  1. create a CMUcam object
  2. call the open method of the camera object
  3. issue a track command using the trackColor or trackWindow method
  4. poll tracking data using the getTrackingData method

This class creates two threads, one to receive data from the camera and the other to interface with the listener. The listener thread isn't started if the addCameraListener method isn't called.

By default, the camera receive thread runs at (Thread.NORM_PRIORITY + 2) and the listener thread runs at (Thread.NORM_PRIORITY + 1). These priorities may be changed by using the getListenerThread and getReceiveThread methods to get to the Thread objects.


Field Summary
static int FPS_4
          Clock register setting for 4 frames per second.
 
Fields inherited from class com.ridgesoft.robotics.sensors.CMUcam.CMUcamBase
FPS_11, FPS_13, FPS_17, FPS_5, FPS_6, FPS_7, FPS_8, FPS_9, LED_OFF, LED_ON, LED_TRACK
 
Constructor Summary
CMUcam(SerialPort serialPort, int baudRate)
          Constructs a CMUcam object.
 
Method Summary
 void defaultWindow()
          Sets the default camera window (1, 1, 80, 143).
protected  void processMessage(byte[] message)
          Camera version specific message processing method for the original CMUcam.
 void setMiddleMassMode(boolean enabled)
          Enables or disables middle mass mode.
 void setNoiseFilter(boolean noiseFilter)
          Enables or disables the noise filter.
 void setServoPosition(int position)
          Issues a set servo position command to the camera.
 void setServoTracking(boolean servoTracking, boolean reverseDirection, boolean reportPosition)
          Enables or disables servo tracking.
 void setSwitchingMode(boolean enabled)
          Enables or disables switching mode.
 void setTrackingLed(int mode)
          Sets the state of the tracking LED.
 void setWindow(int x, int y, int x2, int y2)
          Sets the window bounds of the camera.
 
Methods inherited from class com.ridgesoft.robotics.sensors.CMUcam.CMUcamBase
addCameraListener, close, getHistogramData, getListenerThread, getMean, getReceiveThread, getRxErrors, getStatisticData, getTrackingData, isTracking, open, removeCameraListener, reset, sendBooleanCommand, sendCommand, sendCommand, setAutoExposure, setBrightness, setCameraRegister, setContrast, setDebug, setFrameRate, setIsTracking, setRGBMode, setTFrameSize, setTrackingLed, setWhiteBalance, stop, trackBlue, trackColor, trackColor, trackGreen, trackRed, trackWindow, updateHistogramData, updateStatisticData, updateTrackingData
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Field Detail

FPS_4

public static final int FPS_4
Clock register setting for 4 frames per second.

See Also:
Constant Field Values
Constructor Detail

CMUcam

public CMUcam(SerialPort serialPort,
              int baudRate)
Constructs a CMUcam object.

Parameters:
serialPort - serial port object for the port the camera attaches to
baudRate - baud rate to use to communicate with the camera
Method Detail

defaultWindow

public void defaultWindow()
                   throws IOException
Sets the default camera window (1, 1, 80, 143).

Throws:
IOException

processMessage

protected void processMessage(byte[] message)
Camera version specific message processing method for the original CMUcam.

Specified by:
processMessage in class CMUcamBase
Parameters:
message - message to process

setMiddleMassMode

public void setMiddleMassMode(boolean enabled)
                       throws IOException
Enables or disables middle mass mode.

In middle mass mode the camera provides coordinates of the middle of the tracked color mass. This is useful when tracking a single point rather than a region is desirable.

Disabling middle mass mode also disables servo tracking.

When in middle mass mode (default), the TrackingData will will be type 'M' or 'N' and will contain mx and my values generated by the camera. When not in middle mass mode, the TrackingData will be type 'C' and the mx, my, and servoPosition values will be 0.

Note: The M, N, and C types correspond to frame types generated by the camera.

See the camera documentation for more detailed information.

Parameters:
enabled - true (default) enables middle mass mode without servo tracking false disables middle mass mode and servo tracking.
Throws:
IOException

setNoiseFilter

public void setNoiseFilter(boolean noiseFilter)
                    throws IOException
Enables or disables the noise filter.

Parameters:
noiseFilter - true (default) enables the noise filter false disables the noise filter
Throws:
IOException

setServoPosition

public void setServoPosition(int position)
                      throws IOException
Issues a set servo position command to the camera.

The camera must be in tracking mode or get mean data mode for the command to be carried out

The servo output can also be used as a digital output.

Parameters:
position - desired position of the servo
  • 0 = servo signaling off, output low
  • 1 - 127 = servo position to set
  • 128 = servo signaling off, output high
Throws:
IOException

setServoTracking

public void setServoTracking(boolean servoTracking,
                             boolean reverseDirection,
                             boolean reportPosition)
                      throws IOException
Enables or disables servo tracking.

When servo tracking is enabled, the camera is put into middle mass mode.

Parameters:
servoTracking - true enables servo tracking false disables servo tracking and puts the camera into middle mass mode. Use setMiddleMassMode(false) to disable servo tracking and middle mass mode.
reverseDirection - reverses the sense of direction for servo commands the camera issues to its servo port
reportPosition - true enables servoPostion reporting via type 'N' tracking data if servo tracking is enabled. When enabled, the servoPostion field in the TrackingData will contain data reported by the camera, otherwise the servoPosition is zero. false disables servoPosition reporting
Throws:
IOException

setSwitchingMode

public void setSwitchingMode(boolean enabled)
                      throws IOException
Enables or disables switching mode.

In switching mode the camera sends StatisticData as well as TrackingData.

Parameters:
enabled - true enables switching mode, false (default) disables switching mode
Throws:
IOException

setTrackingLed

public void setTrackingLed(int mode)
                    throws IOException
Sets the state of the tracking LED.

Parameters:
mode - LED mode
  • LED_OFF - turns the LED off
  • LED_ON - turns the LED on
  • LED_TRACK (default) - gives control to the camera
Throws:
IOException

setWindow

public void setWindow(int x,
                      int y,
                      int x2,
                      int y2)
               throws IOException
Sets the window bounds of the camera.

The parameters must be within the range supported by the camera, 1 <= x <= 80, 1 <= y <= 143.

Parameters:
x - x coordinate of upper left corner of desired window
y - y coordinate of upper left corner of desired window
x2 - x coordinate of lower right corner of desired window
y2 - y coordinate of lower right corner of desired window
Throws:
IOException

RoboJDETM v2.0

Copyright (c) 2003-2009 RidgeSoft, LLC. All rights reserved.
www.ridgesoft.com