RoboJDETM v2.0

com.ridgesoft.robotics.sensors.CMUcam
Class CMUcam2

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

public class CMUcam2
extends CMUcamBase

Class to interface with the CMUcam2.

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, color statistics data or histogram data using the getTrackingData, getStatisticData and getHistogramData 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 CMUcam2 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_26
          Clock register setting for 13 frames per second.
static int FPS_50
          Clock register setting for 50 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
CMUcam2(SerialPort serialPort, int baudRate)
          Constructs a CMUcam object.
 
Method Summary
 void defaultVirtualWindow()
          Sets the default camera window (1, 1, 80, 143).
 void getHistogram(int channel)
          Issues the get histogram command.
 void loadFrame()
          Loads a baseline frame for motion differencing and motion tracking.
protected  void processMessage(byte[] message)
          Camera version specific message processing method for the CMUcam2.
 void readFrame()
          Reads a new frame into the buffer when using buffer mode.
 void reset()
          Issues a reset command to the camera.
 void setBufferMode(boolean enabled)
          Enables or disables buffer mode.
 void setCameraPower(boolean enabled)
          Turns the camera power on or off.
 void setDifferencingChannel(int channel)
          Sets the channel used for frame differencing.
 void setDownSampling(int xFactor, int yFactor)
          Sets down sampling factors.
 void setHighResolutionDifferencing(boolean enabled)
          Enables or disables high resolution differencing.
 void setHighResolutionMode(boolean enabled)
          Enables or disables high resolution mode.
 void setHistogramTracking(boolean enabled)
          Enables or disables histogram tracking.
 void setNoiseFilter(int threshold)
          Sets the noise filtering threshold.
 void setPacketFiltering(boolean enabled)
          Enables or disables packet filtering mode.
 void setPacketSkip(int number)
          Sets the number of packets to skip sending when tracking.
 void setPixelDifferencing(boolean enabled)
          Enables or disables pixel difference mode.
 void setPixelFiltering(boolean enabled)
          Enables or disables pixel filtering mode.
 void setServoMask(boolean panEnabled, boolean tiltEnabled)
          Enables or disables pan and tilt servos.
 void setServoParameters(int panRangeFar, int panRangeNear, int panStep, int tiltRangeFar, int tiltRangeNear, int tiltStep)
          Sets parameters to control the behavior of the pan and tilt servos.
 void setServoPosition(int servo, int position)
          Sets the servo position.
 void setTracking(int redOrCrMinimum, int redOrCrMaximum, int greenOrYMinimum, int greenOrYMaximum, int blueOrCbMinimum, int blueOrCbMaximum)
          Sets color tracking parameters, similar to trackColor but without initiating tracking.
 void setTrackInverted(boolean enabled)
          Enables or disables track inverted mode.
 void setVirtualWindow(int x, int y, int x2, int y2)
          Sets the window bounds of the camera using the virtual window command.
 void sleep()
          Puts the camera's CPU to sleep.
 void sleepDeeply()
          Puts the camera into deep sleep mode to save power.
 void trackWithFrameDifferencing(int threshold)
          Starts tracking with frame differencing using the specified threshold.
 void trackWithMaskedDifferencing(int threshold)
          Starts tracking with masked differencing using the specified threshold.
 void wake()
          Wakes the camera up after a sleep.
 
Methods inherited from class com.ridgesoft.robotics.sensors.CMUcam.CMUcamBase
addCameraListener, close, getHistogramData, getListenerThread, getMean, getReceiveThread, getRxErrors, getStatisticData, getTrackingData, isTracking, open, removeCameraListener, 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_26

public static final int FPS_26
Clock register setting for 13 frames per second.

See Also:
Constant Field Values

FPS_50

public static final int FPS_50
Clock register setting for 50 frames per second.

See Also:
Constant Field Values
Constructor Detail

CMUcam2

public CMUcam2(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

defaultVirtualWindow

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

Throws:
IOException

getHistogram

public void getHistogram(int channel)
                  throws IOException
Issues the get histogram command.

The CMUcam2 will continually send updates to the histogram data.

Parameters:
channel - channel to use
  • 0 use red (Cr) channel
  • 1 use green (Y) channel (default)
  • 2 use blue (Cb) channel
Throws:
IOException

loadFrame

public void loadFrame()
               throws IOException
Loads a baseline frame for motion differencing and motion tracking.

Throws:
IOException

processMessage

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

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

readFrame

public void readFrame()
               throws IOException
Reads a new frame into the buffer when using buffer mode.

Throws:
IOException

reset

public void reset()
           throws IOException
Issues a reset command to the camera.

Overrides:
reset in class CMUcamBase
Throws:
IOException

setBufferMode

public void setBufferMode(boolean enabled)
                   throws IOException
Enables or disables buffer mode.

Parameters:
enabled - false frame buffer continuously updates (default) true a single frame is buffered in the frame buffer
Throws:
IOException

setCameraPower

public void setCameraPower(boolean enabled)
                    throws IOException
Turns the camera power on or off.

Parameters:
enabled - false power off true power on
Throws:
IOException

setDifferencingChannel

public void setDifferencingChannel(int channel)
                            throws IOException
Sets the channel used for frame differencing.

Parameters:
channel - channel to use
  • 0 use red (Cr) channel
  • 1 use green (Y) channel (default)
  • 2 use blue (Cb) channel
Throws:
IOException

setDownSampling

public void setDownSampling(int xFactor,
                            int yFactor)
                     throws IOException
Sets down sampling factors.

Parameters:
xFactor - horizontal down sampling (default = 1, no down sampling)
yFactor - vertical down sampling factor
Throws:
IOException

setHighResolutionDifferencing

public void setHighResolutionDifferencing(boolean enabled)
                                   throws IOException
Enables or disables high resolution differencing.

Parameters:
enabled - high resolution differencing enable flag
  • false 8x8 differencing (default)
  • true 16x16 differencing
Throws:
IOException

setHighResolutionMode

public void setHighResolutionMode(boolean enabled)
                           throws IOException
Enables or disables high resolution mode.

This is only supported with the OV6620 camera module.

Parameters:
enabled - high resolution mode enable flag
  • false 88x143 resoultion (default)
  • true 176x255 resolution
Throws:
IOException

setHistogramTracking

public void setHistogramTracking(boolean enabled)
                          throws IOException
Enables or disables histogram tracking.

When histogram tracking is enabled, only values that are within the color tracking bounds will be displayed in the histograms.

Parameters:
enabled - false disabled (default) true enabled
Throws:
IOException

setNoiseFilter

public void setNoiseFilter(int threshold)
                    throws IOException
Sets the noise filtering threshold.

Parameters:
threshold - the number of consecutive active pixels before the current pixel are required before the pixel should be detected
  • range: 0-255
  • default: 2
Throws:
IOException

setPacketFiltering

public void setPacketFiltering(boolean enabled)
                        throws IOException
Enables or disables packet filtering mode.

Parameters:
enabled - false disabled (default) true enabled
Throws:
IOException

setPacketSkip

public void setPacketSkip(int number)
                   throws IOException
Sets the number of packets to skip sending when tracking.

This is useful for slowing down the data rate from the camera.

Parameters:
number - the number of packets to skip before sending the next packet
  • default: 0, send all packets
Throws:
IOException

setPixelDifferencing

public void setPixelDifferencing(boolean enabled)
                          throws IOException
Enables or disables pixel difference mode.

Parameters:
enabled - false disabled (default) true enabled
Throws:
IOException

setPixelFiltering

public void setPixelFiltering(boolean enabled)
                       throws IOException
Enables or disables pixel filtering mode.

Parameters:
enabled - false disabled (default) true enabled
Throws:
IOException

setServoMask

public void setServoMask(boolean panEnabled,
                         boolean tiltEnabled)
                  throws IOException
Enables or disables pan and tilt servos.

Each position reporting field in tracking data objects are enabled when the associated servo is enabled.

Parameters:
panEnabled - true - panning enabled
tiltEnabled - true - tilting enabled
Throws:
IOException

setServoParameters

public void setServoParameters(int panRangeFar,
                               int panRangeNear,
                               int panStep,
                               int tiltRangeFar,
                               int tiltRangeNear,
                               int tiltStep)
                        throws IOException
Sets parameters to control the behavior of the pan and tilt servos. Short steps are half of long steps.

Parameters:
panRangeFar - pixel distance needed to do a large pan step
panRangeNear - pixel distance needed to do a small pan step
panStep - servo position change for a long pan step
tiltRangeFar - pixel distance needed to do a large tilt step
tiltRangeNear - pixel distance needed to do a small tilt step
tiltStep - servo position change for a long tilt step
Throws:
IOException

setServoPosition

public void setServoPosition(int servo,
                             int position)
                      throws IOException
Sets the servo position.

See the camera User Guide for more information.

Parameters:
servo - number of the servo (1 - 5)
position - position to set
  • range: 48 to 210
  • 128 = centered
Throws:
IOException

setTracking

public void setTracking(int redOrCrMinimum,
                        int redOrCrMaximum,
                        int greenOrYMinimum,
                        int greenOrYMaximum,
                        int blueOrCbMinimum,
                        int blueOrCbMaximum)
                 throws IOException
Sets color tracking parameters, similar to trackColor but without initiating tracking.

The values are either specified as ranges for RGB or CrYCb values. The default is RGB, but it may be changed by using the setRGBMode method.

Parameters:
redOrCrMinimum - minimum red or Cr color component
redOrCrMaximum - maximum red or Cr color component
greenOrYMinimum - minimum green or Y color component
greenOrYMaximum - maximum green or Y color component
blueOrCbMinimum - minimum blue or Cb color component
blueOrCbMaximum - maximum blue or Cb color component
Throws:
IOException

setTrackInverted

public void setTrackInverted(boolean enabled)
                      throws IOException
Enables or disables track inverted mode.

When enabled, the camera will track colors outside of the color range, rather than inside the range.

Parameters:
enabled - true - enables track inverted false - normal mode
Throws:
IOException

setVirtualWindow

public void setVirtualWindow(int x,
                             int y,
                             int x2,
                             int y2)
                      throws IOException
Sets the window bounds of the camera using the virtual window command.

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

sleep

public void sleep()
           throws IOException
Puts the camera's CPU to sleep.

Use the wake method to wake the camera up.

Throws:
IOException

sleepDeeply

public void sleepDeeply()
                 throws IOException
Puts the camera into deep sleep mode to save power.

Supporting circuitry must be added to the camera module to support this feature. See the camera User Guide for more information.

Throws:
IOException

trackWithFrameDifferencing

public void trackWithFrameDifferencing(int threshold)
                                throws IOException
Starts tracking with frame differencing using the specified threshold.

Differences are based on the last frame loaded using the loadFrame command.

Parameters:
threshold - the threshold
Throws:
IOException

trackWithMaskedDifferencing

public void trackWithMaskedDifferencing(int threshold)
                                 throws IOException
Starts tracking with masked differencing using the specified threshold.

Differences are based on the last frame loaded using the loadFrame command.

Parameters:
threshold - masked differencing threshold
Throws:
IOException

wake

public void wake()
          throws IOException
Wakes the camera up after a sleep.

Throws:
IOException

RoboJDETM v2.0

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