RoboJDETM v2.0

com.ridgesoft.robotics.sensors.CMUcam
Class CMUcamBase

java.lang.Object
  extended by com.ridgesoft.robotics.sensors.CMUcam.CMUcamBase
Direct Known Subclasses:
CMUcam, CMUcam2

public abstract class CMUcamBase
extends Object

Base class for classes that interface with the CMUcam and CMUcam2.


Field Summary
static int FPS_11
          Clock register setting for 11 frames per second.
static int FPS_13
          Clock register setting for 13 frames per second.
static int FPS_17
          Clock register setting for 17 frames per second.
static int FPS_5
          Clock register setting for 5 frames per second.
static int FPS_6
          Clock register setting for 6 frames per second.
static int FPS_7
          Clock register setting for 7 frames per second.
static int FPS_8
          Clock register setting for 8 frames per second.
static int FPS_9
          Clock register setting for 9 frames per second.
static int LED_OFF
          Tracking LED mode value to turn the LED off.
static int LED_ON
          Tracking LED mode value to turn the LED on.
static int LED_TRACK
          Tracking LED mode value to give the camera control of the LED.
 
Constructor Summary
protected CMUcamBase(SerialPort serialPort, int baudRate)
          Initializes the camera base class.
 
Method Summary
 void addCameraListener(CMUcamDataListener listener)
          Adds a listener for CMUcamData updates.
 void close()
          Closes communication with the camera by issuing an idle command to the camera and terminating the receive and listener threads.
 CMUcamHistogramData getHistogramData()
          Retrieves the latest histogram data reported by the CMUcam2.
 Thread getListenerThread()
          Gets the camera's listener thread.
 void getMean()
          Issues the get mean command to the camera, instructing it to start sending statistic data.
 Thread getReceiveThread()
          Gets the camera's receiver thread.
 int getRxErrors()
          Gets the count of receive errors.
 CMUcamStatisticData getStatisticData()
          Retrieves the latest statistic data reported by the camera.
 CMUcamTrackingData getTrackingData()
          Retrieves the latest tracking data reported by the camera.
 boolean isTracking()
          Returns whether the camera is currently tracking.
 void open()
          Opens communication with the camera and resets the camera.
protected abstract  void processMessage(byte[] message)
          Camera version specific message processing method.
 void removeCameraListener(CMUcamDataListener listener)
          Removes the listener.
 void reset()
          Issues a reset command to the camera.
protected  void sendBooleanCommand(String command, boolean value)
          Sends a command to the camera followed by the boolean value converted to 0 for false and 1 for true.
 void sendCommand(String command)
          Sends a command to the camera and waits for a response.
 void sendCommand(String command, boolean expectPrompt)
          Sends a command to the camera and waits for a response.
 void setAutoExposure(boolean autoExposure)
          Enables or disables auto exposure.
 void setBrightness(int brightness)
          Sets the camera's brightness.
 void setCameraRegister(int register, int value)
          Sets a camera register.
 void setContrast(int contrast)
          Sets the camera's contrast.
 void setDebug(boolean debug)
          Enables or disables debug mode.
 void setFrameRate(int clockRegisterSetting)
          Sets the camera's frame rate.
 void setIsTracking(boolean isTracking)
          Sets the variable this class uses to maintian the tracking state.
 void setRGBMode(boolean rgbModeEnabled)
          Sets the color mode to RGB or YCrCb.
protected  void setTFrameSize(int size)
          Sets the size to expect for a T frame.
 void setTrackingLed(int led, int mode)
          Sets the state of a tracking LED.
 void setWhiteBalance(boolean whiteBalance)
          Enables or disables automatic white balance adjustment.
 void stop()
          Issues an idle command to the camera which will cause it to stop sending tracking data.
 void trackBlue()
          Sets tracking to blue objects.
 void trackColor()
          Issues the track color command to the camera, instructing it to track using existing color tracking parameters.
 void trackColor(int redOrCrMinimum, int redOrCrMaximum, int greenOrYMinimum, int greenOrYMaximum, int blueOrCbMinimum, int blueOrCbMaximum)
          Issues the track color command to the camera, instructing it to track using the specified color tracking parameters.
 void trackGreen()
          Sets tracking to green objects.
 void trackRed()
          Sets tracking to red objects.
 void trackWindow()
          Issues the track window command to the camera, instructing it to track the color found in the center of the current window.
protected  void updateHistogramData(CMUcamHistogramData histogramData)
          Updates histogram data with new data.
protected  void updateStatisticData(CMUcamStatisticData statisticData)
          Updates statistic data with new data.
protected  void updateTrackingData(CMUcamTrackingData trackingData)
          Updates tracking data with new data.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Field Detail

FPS_11

public static final int FPS_11
Clock register setting for 11 frames per second.

See Also:
Constant Field Values

FPS_13

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

See Also:
Constant Field Values

FPS_17

public static final int FPS_17
Clock register setting for 17 frames per second.

See Also:
Constant Field Values

FPS_5

public static final int FPS_5
Clock register setting for 5 frames per second.

See Also:
Constant Field Values

FPS_6

public static final int FPS_6
Clock register setting for 6 frames per second.

See Also:
Constant Field Values

FPS_7

public static final int FPS_7
Clock register setting for 7 frames per second.

See Also:
Constant Field Values

FPS_8

public static final int FPS_8
Clock register setting for 8 frames per second.

See Also:
Constant Field Values

FPS_9

public static final int FPS_9
Clock register setting for 9 frames per second.

See Also:
Constant Field Values

LED_OFF

public static final int LED_OFF
Tracking LED mode value to turn the LED off.

See Also:
Constant Field Values

LED_ON

public static final int LED_ON
Tracking LED mode value to turn the LED on.

See Also:
Constant Field Values

LED_TRACK

public static final int LED_TRACK
Tracking LED mode value to give the camera control of the LED.

See Also:
Constant Field Values
Constructor Detail

CMUcamBase

protected CMUcamBase(SerialPort serialPort,
                     int baudRate)
Initializes the camera base class.

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

addCameraListener

public void addCameraListener(CMUcamDataListener listener)
Adds a listener for CMUcamData updates.

This class currently only supports one listener. If the listener method takes too long to execute some messages may not be reported. Care must be taken to account for the listener being called on a separate thread to avoid synchronization problems. Calls to the listener are serialized so the and the listener method will not be re-entered.

Parameters:
listener - a reference to a class implementing the CMUcamDataListener interface

close

public void close()
Closes communication with the camera by issuing an idle command to the camera and terminating the receive and listener threads.


getHistogramData

public CMUcamHistogramData getHistogramData()
Retrieves the latest histogram data reported by the CMUcam2.

This function is not supported by the original camera.

Returns:
CMUcamHistogramData object containing the last received H packet data received from the CMUcam2 or null if no new data has been received since the last invocation of this method.

getListenerThread

public Thread getListenerThread()
Gets the camera's listener thread.

Returns:
Thread object for the receiver thread

getMean

public void getMean()
             throws IOException
Issues the get mean command to the camera, instructing it to start sending statistic data.

Throws:
IOException

getReceiveThread

public Thread getReceiveThread()
Gets the camera's receiver thread.

Returns:
Thread object for the receiver thread

getRxErrors

public int getRxErrors()
Gets the count of receive errors.

Receive errors may be caused by a poor quality connection, running the camera at a higher baud rate than the microcontroller supports, the camera receive thread running at too low a priority, or bad data from the camera.

Returns:
number of receive errors

getStatisticData

public CMUcamStatisticData getStatisticData()
Retrieves the latest statistic data reported by the camera.

Returns:
CMUcamStatisticData object containing the last received S packet data received from the camera or null if no new data has been received since the last invocation of this method.

getTrackingData

public CMUcamTrackingData getTrackingData()
Retrieves the latest tracking data reported by the camera.

Returns:
CMUcamTrackingData object containing the last received C, M, N or T packet data received from the camera or null if no new data has been received since the last invocation of this method.

isTracking

public boolean isTracking()
Returns whether the camera is currently tracking.

Note: The value returned is based on a this class keeping tracking of the commands it has sent to the camera. If the camera gets reset externally or the sendCommand method is used directly to turn on tracking, the value returned by this method may not be correct.

Returns:
true if the camera is currently tracking, false otherwise

open

public void open()
          throws IOException
Opens communication with the camera and resets the camera.

Throws:
IOException - if communication to the camera fails. This exception will be thrown if the camera is not attached or turned off.

processMessage

protected abstract void processMessage(byte[] message)
Camera version specific message processing method.

Parameters:
message - The message to process.

removeCameraListener

public void removeCameraListener(CMUcamDataListener listener)
Removes the listener.

Parameters:
listener - a reference to a class implementing the CMUcamDataListener interface

reset

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

Throws:
IOException

sendBooleanCommand

protected void sendBooleanCommand(String command,
                                  boolean value)
                           throws IOException
Sends a command to the camera followed by the boolean value converted to 0 for false and 1 for true.

Parameters:
command - command string prefix
value - boolean value to be appended to the command string as 0 or 1
Throws:
IOException

sendCommand

public void sendCommand(String command)
                 throws IOException
Sends a command to the camera and waits for a response.

This method should only be used when no other method is available to configure the camera. Using this method may result in the putting the camera in a mode that is not handled by this class. This method sends the command and waits for the response from the camera.

Parameters:
command - an ASCII command to send to the camera, including all data except the '\r' character
Throws:
IOException

sendCommand

public void sendCommand(String command,
                        boolean expectPrompt)
                 throws IOException
Sends a command to the camera and waits for a response.

This method should only be used when no other method is available to configure the camera. Using this method may result in the putting the camera in a mode that is not handled by this class. This method sends the command and waits for the response from the camera.

Parameters:
command - an ASCII command to send to the camera, including all data except the '\r' character
expectPrompt - true if a prompt (":") should be expected after the command
Throws:
IOException

setAutoExposure

public void setAutoExposure(boolean autoExposure)
                     throws IOException
Enables or disables auto exposure.

Parameters:
autoExposure - true (default) enables auto exposure false disables auto exposure
Throws:
IOException

setBrightness

public void setBrightness(int brightness)
                   throws IOException
Sets the camera's brightness.

Parameters:
brightness - 0 - 255
Throws:
IOException

setCameraRegister

public void setCameraRegister(int register,
                              int value)
                       throws IOException
Sets a camera register.

Other methods are provided for common register setting commands.

This method should only be used when no other method is available.

See the camera documentation for more information regarding the camera registers.

Parameters:
register - number of the register to set
value - value to set in the register (0 - 255)
Throws:
IOException

setContrast

public void setContrast(int contrast)
                 throws IOException
Sets the camera's contrast.

Parameters:
contrast - 0 - 255
Throws:
IOException

setDebug

public void setDebug(boolean debug)
Enables or disables debug mode.

In debug mode this class prints commands to the camera and command responses from the camera to System.out. Tracking and statistic data updates are not displayed.

Parameters:
debug - true turns on debugging mode, false (default) turns off debugging mode

setFrameRate

public void setFrameRate(int clockRegisterSetting)
                  throws IOException
Sets the camera's frame rate.

Slowing the frame rate down reduces the processing overhead for the robotics controller, leaving more computing power to do other things.

Parameters:
clockRegisterSetting - value to write into the camera's clock register

Note: This value is NOT the number of frames per second.

Use one of the following defined constants for this parameter:

  • FPS_50 (CMUcam2 only, CMUcam2 default)
  • FPS_26 (CMUcam2 only)
  • FPS_17 (CMUcam default)
  • FPS_13
  • FPS_11
  • FPS_9
  • FPS_8
  • FPS_7
  • FPS_6
  • FPS_5
  • FPS_4 (CMUcam only)
Throws:
IOException

setIsTracking

public void setIsTracking(boolean isTracking)
Sets the variable this class uses to maintian the tracking state.

If the camera is put into tracking mode directly by using the sendCommand method, this method should be used to set the tracking variable correctly.

Most users should not need to use sendCommand or this method. Using this method from your application should be avoided.

Parameters:
isTracking - true if the camera is in the tracking state

setRGBMode

public void setRGBMode(boolean rgbModeEnabled)
                throws IOException
Sets the color mode to RGB or YCrCb.

Parameters:
rgbModeEnabled - true enables RGB mode, false enables YCrCb mode
Throws:
IOException

setTFrameSize

protected void setTFrameSize(int size)
Sets the size to expect for a T frame.

Parameters:
size - size of T frame not including type byte

setTrackingLed

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

Parameters:
led - number of the LED
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

setWhiteBalance

public void setWhiteBalance(boolean whiteBalance)
                     throws IOException
Enables or disables automatic white balance adjustment.

Parameters:
whiteBalance - true enables automatic white balance adjustment, false (default) disables automatic white balance adjustment
Throws:
IOException

stop

public void stop()
          throws IOException
Issues an idle command to the camera which will cause it to stop sending tracking data.

Throws:
IOException

trackBlue

public void trackBlue()
               throws IOException
Sets tracking to blue objects.

Throws:
IOException

trackColor

public void trackColor()
                throws IOException
Issues the track color command to the camera, instructing it to track using existing color tracking parameters.

Throws:
IOException

trackColor

public void trackColor(int redOrCrMinimum,
                       int redOrCrMaximum,
                       int greenOrYMinimum,
                       int greenOrYMaximum,
                       int blueOrCbMinimum,
                       int blueOrCbMaximum)
                throws IOException
Issues the track color command to the camera, instructing it to track using the specified color tracking parameters. 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

trackGreen

public void trackGreen()
                throws IOException
Sets tracking to green objects.

Throws:
IOException

trackRed

public void trackRed()
              throws IOException
Sets tracking to red objects.

Throws:
IOException

trackWindow

public void trackWindow()
                 throws IOException
Issues the track window command to the camera, instructing it to track the color found in the center of the current window.

Throws:
IOException

updateHistogramData

protected void updateHistogramData(CMUcamHistogramData histogramData)
Updates histogram data with new data.

This method is intended to be called by the processMessage method.

Parameters:
histogramData - new histogram data

updateStatisticData

protected void updateStatisticData(CMUcamStatisticData statisticData)
Updates statistic data with new data.

This method is intended to be called by the processMessage method.

Parameters:
statisticData - new statistic data

updateTrackingData

protected void updateTrackingData(CMUcamTrackingData trackingData)
Updates tracking data with new data.

This method is intended to be called by the processMessage method.

Parameters:
trackingData - new tracking data

RoboJDETM v2.0

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