Class CameraImage

java.lang.Object
  |
  +--CameraImage

public class CameraImage
extends java.lang.Object

This is the main camera class for the Seeker robot. It is based on the code from the CMUcamGUI demo program.
It has functionality to dump frames and track colors.


Field Summary
(package private) static char a
          Tmp variables used for reading and checking for an ACK from the camera.
(package private) static int blue
          Used to convert the read data from the camera dump from into a single rgb value.
(package private) static char c
          Tmp variables used for reading and checking for an ACK from the camera.
(package private) static int col
          Current position of the data being read from a frame dump.
(package private) static int[][] ColorList
          List of colors and their color ranges.
(package private) static java.lang.String Command
          For preparing a command to send to the camera.
(package private) static int conf
          Holders of the data returned from the camera when tracking a color.
(package private) static int data
          Hold last read byte from the camera.
(package private) static int Dir
          Used for determining the direction we need to move to track the object.
(package private) static int green
          Used to convert the read data from the camera dump from into a single rgb value.
(package private) static char k
          Tmp variables used for reading and checking for an ACK from the camera.
(package private) static int mmx
          Holders of the data returned from the camera when tracking a color.
(package private) static int mmy
          Holders of the data returned from the camera when tracking a color.
(package private) static serialComm mySerial
          javax.com serial interface class used for talking to the camera.
(package private) static int NumColors
          Number of colors the robot can track.
(package private) static int pixColor
          Used to convert the read data from the camera dump from into a single rgb value.
(package private) static int[] pixels
          Array to hold the data returned from a frame dump.
(package private) static char r
          Tmp variables used for reading and checking for an ACK from the camera.
(package private) static int red
          Used to convert the read data from the camera dump from into a single rgb value.
(package private) static int row
          Current position of the data being read from a frame dump.
(package private) static int start
          Flag if we are starting a new command or not.
(package private) static java.util.Date time
          Used to check for timeouts reading data.
(package private) static long wdTimer
          Used to check for timeouts reading data.
(package private) static int x2coord
          Holders of the data returned from the camera when tracking a color.
(package private) static int xcoord
          Holders of the data returned from the camera when tracking a color.
(package private) static int XSize
          Used for determining the direction we need to move to track the object.
(package private) static int y2coord
          Holders of the data returned from the camera when tracking a color.
(package private) static int ycoord
          Holders of the data returned from the camera when tracking a color.
(package private) static int zcoord
          Holders of the data returned from the camera when tracking a color.
 
Constructor Summary
(package private) CameraImage(java.lang.String commPort)
          Here we simply initialized the variables used by the class.

We also initialize the ball color ranges here: (Red Range)(Green Range)(Blue Range) Red = (100 255)(0 50)(0 50) Green = (0 50)(100 255)(0 50) Yellow = (100 255)(100 255)(0 50) White = (150 255)(150 255)(150 255)
 
Method Summary
 int dumpFrame()
          Grabs the image column by column and stores it in a 2d array.
 int FindColorInImage()
          Scan the image looking for one of the colors the robot is searching for.
Search algorithm searches from the bottom to the top of the image, and from the center to the outside (left, then right) to find objects that are closer before ones that are further away.
 void flushBuf()
          Flushes all data out of the serial input buffer
 int GetTrackDirection()
          Gets the current tracking information from the camera and converts it to tracking information.
Reads current tracking information from the camera (which was started by calling trackColor()).
Considers object to be centered when x middle mass is between 30 and 60.
 boolean idle()
          Trys to get the camera to settle down and idle
 boolean sendCommand(java.lang.String command)
          Sends a command and checks for an ACK
 boolean trackColor(int TColor)
          This function initializes the camera to start tracking a certain color.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

pixels

static int[] pixels
Array to hold the data returned from a frame dump.

col

static int col
Current position of the data being read from a frame dump.

row

static int row
Current position of the data being read from a frame dump.

mmx

static int mmx
Holders of the data returned from the camera when tracking a color.

mmy

static int mmy
Holders of the data returned from the camera when tracking a color.

xcoord

static int xcoord
Holders of the data returned from the camera when tracking a color.

ycoord

static int ycoord
Holders of the data returned from the camera when tracking a color.

zcoord

static int zcoord
Holders of the data returned from the camera when tracking a color.

x2coord

static int x2coord
Holders of the data returned from the camera when tracking a color.

y2coord

static int y2coord
Holders of the data returned from the camera when tracking a color.

conf

static int conf
Holders of the data returned from the camera when tracking a color.

start

static int start
Flag if we are starting a new command or not.

wdTimer

static long wdTimer
Used to check for timeouts reading data.

time

static java.util.Date time
Used to check for timeouts reading data.

mySerial

static serialComm mySerial
javax.com serial interface class used for talking to the camera.

pixColor

static int pixColor
Used to convert the read data from the camera dump from into a single rgb value.

red

static int red
Used to convert the read data from the camera dump from into a single rgb value.

green

static int green
Used to convert the read data from the camera dump from into a single rgb value.

blue

static int blue
Used to convert the read data from the camera dump from into a single rgb value.

a

static char a
Tmp variables used for reading and checking for an ACK from the camera.

c

static char c
Tmp variables used for reading and checking for an ACK from the camera.

k

static char k
Tmp variables used for reading and checking for an ACK from the camera.

r

static char r
Tmp variables used for reading and checking for an ACK from the camera.

data

static int data
Hold last read byte from the camera.

Dir

static int Dir
Used for determining the direction we need to move to track the object.

XSize

static int XSize
Used for determining the direction we need to move to track the object.

ColorList

static int[][] ColorList
List of colors and their color ranges.

NumColors

static int NumColors
Number of colors the robot can track.

Command

static java.lang.String Command
For preparing a command to send to the camera.
Constructor Detail

CameraImage

CameraImage(java.lang.String commPort)
Here we simply initialized the variables used by the class.

We also initialize the ball color ranges here: (Red Range)(Green Range)(Blue Range)
Parameters:
commPort - Comm port that the camera is attached to
Method Detail

trackColor

public boolean trackColor(int TColor)
This function initializes the camera to start tracking a certain color. Input is for one of the predefined colors the camera cares about and tells the camera to track the object using predetermined rgb color ranges.
Parameters:
TColor - Color to track. Possible colors are:
  • 1 = Red
  • 2 = Green
  • 3 = Yellow
  • 4 = White
Returns:
True if tracking started. False if an error occured

flushBuf

public void flushBuf()
Flushes all data out of the serial input buffer

idle

public boolean idle()
Trys to get the camera to settle down and idle
Returns:
True if the camera has gone idle.

sendCommand

public boolean sendCommand(java.lang.String command)
Sends a command and checks for an ACK
Returns:
True if ACK else false

dumpFrame

public int dumpFrame()
Grabs the image column by column and stores it in a 2d array.
Returns:
True(1) if frame dump has completed. False(0) if there is still more to come. Error(-1) if we encountered and error reading the data.

FindColorInImage

public int FindColorInImage()
Scan the image looking for one of the colors the robot is searching for.
Search algorithm searches from the bottom to the top of the image, and from the center to the outside (left, then right) to find objects that are closer before ones that are further away.
Returns:
Color found:
  • 0 = No color found
  • 1 = Red
  • 2 = Green
  • 3 = Yellow
  • 4 = White

GetTrackDirection

public int GetTrackDirection()
Gets the current tracking information from the camera and converts it to tracking information.
Reads current tracking information from the camera (which was started by calling trackColor()).
Considers object to be centered when x middle mass is between 30 and 60. In this case it will either move forward, backward, or consider itself done.
If centerd, then if the width of the returnd bounding box is between 19 and 22 then we return that we are done and we need to stop here. Otherwise it returns to move forward or backward.
Returns:
Direction to move to track object:
  • -1 = Color not found (camera confidence was under 20)
  • 0 = Done Tracking. Object is in place to be picked up.
  • 1 = Forward
  • 2 = Right
  • 3 = Left
  • 4 = Back
  • 5 = Large Forward
  • 6 = Large Right
  • 7 = Large Left
  • 8 = Large Back