koala
Class KoreCamera

java.lang.Object
  extended by koala.KoreCamera
All Implemented Interfaces:
KoalaCamera, KoreMotors

public class KoreCamera
extends java.lang.Object
implements KoalaCamera, KoreMotors

Class to control the camera (motors) of the Koala/Korebot. The camera motors are part of the KoreMotorLE module which is interfaced to the Korebot. Throughout the following the terms pan and tilt are used. To clarify, the "pan" motor rotates around a vertical axis, having the effect of panning the camera left to right. The "tilt" motor rotates around a horizontal axis, having the effect of tilting the camera up and down.


Method Summary
 int[] getImage()
          Read a frame from the camera as an array of integers, where each element represents one pixel encoded in RGB.
static KoreCamera getInstance()
          Get a reference to the KoalaCamera.
 KoalaMotorLimits getPanMotorLimits()
          Runs an automated movement which detects the left and right positions which limit how far the pan motor can rotate.
 int getPanMotorPosition()
          Get the position of the pan motor.
 java.awt.Point getSpotPosition(boolean red)
          Find a red or green spot in the current camera view.
 java.awt.Point getSpotPosition(java.awt.Color colour)
          Find a spot of the specified colour in the current camera view.
 java.awt.Point getSpotPosition(java.awt.Color colour, int[] colourLimits)
          Find a spot of the specified colour in the current camera view.
 KoalaMotorLimits getTiltMotorLimits()
          Runs an automated movement which detects the up and down positions which limit how far the tilt motor can rotate.
 int getTiltMotorPosition()
          Get the position of the tilt motor.
 boolean isInitialised()
          Check the motors have initialised.
 boolean isPanMotorBlocked()
          Check if the pan motor has reached its physical limits.
 boolean isTiltMotorBlocked()
          Check if the tilt motor has reached its physical limits.
 void setMotorPosition(int panPos, int tiltPos)
          Set the position of the camera motors.
 void setSpeed(int panSpeed, int tiltSpeed)
          Set the speed of the camera motors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static KoreCamera getInstance()
Get a reference to the KoalaCamera. There is only one instance.


isInitialised

public boolean isInitialised()
Check the motors have initialised. Further methods should not be called if they are not initialised.


setSpeed

public void setSpeed(int panSpeed,
                     int tiltSpeed)
Set the speed of the camera motors. A speed of 1 corresponds to approximately 70 degrees per second.

Specified by:
setSpeed in interface KoreMotors

setMotorPosition

public void setMotorPosition(int panPos,
                             int tiltPos)
Set the position of the camera motors. The pan motor position must be between -90 degrees and +90 degrees. -90 corresponds to turning the camera completely to the left hand side, +90 corresponds to the right. The tilt motor position must be between -30 and 120 degrees. -30 corresponds to turning the camera facing downwards (as far as it will go), and +120 corresponds to turning the camera to face upwards. The position (0,0), therefore, corresponds to the camera facing directly forwards. This method does not block, so the position will not have been reached after the method returns.

Specified by:
setMotorPosition in interface KoreMotors

getPanMotorPosition

public int getPanMotorPosition()
Get the position of the pan motor. The value will be between -90 degrees and +90 degrees. -90 corresponds to turning the camera completely to the left hand side, +90 corresponds to the right.

Specified by:
getPanMotorPosition in interface KoreMotors

getTiltMotorPosition

public int getTiltMotorPosition()
Get the position of the tilt motor. The value will be between -30 and 120 degrees. -30 corresponds to turning the camera facing downwards, and +120 corresponds to turning the camera to face upwards.

Specified by:
getTiltMotorPosition in interface KoreMotors

getPanMotorLimits

public KoalaMotorLimits getPanMotorLimits()
Runs an automated movement which detects the left and right positions which limit how far the pan motor can rotate. Returns the minimum and maximum positions in hardware units (not degrees).

Specified by:
getPanMotorLimits in interface KoreMotors

getTiltMotorLimits

public KoalaMotorLimits getTiltMotorLimits()
Runs an automated movement which detects the up and down positions which limit how far the tilt motor can rotate. Returns the minimum and maximum positions in hardware units (not degrees).

Specified by:
getTiltMotorLimits in interface KoreMotors

isPanMotorBlocked

public boolean isPanMotorBlocked()
Check if the pan motor has reached its physical limits.

Specified by:
isPanMotorBlocked in interface KoreMotors

isTiltMotorBlocked

public boolean isTiltMotorBlocked()
Check if the tilt motor has reached its physical limits.

Specified by:
isTiltMotorBlocked in interface KoreMotors

getImage

public int[] getImage()
Read a frame from the camera as an array of integers, where each element represents one pixel encoded in RGB. The image resolution is 352x288. Thus array[0] is (0,0) and array[101375] is (351,287).

Specified by:
getImage in interface KoalaCamera

getSpotPosition

public java.awt.Point getSpotPosition(java.awt.Color colour,
                                      int[] colourLimits)
Find a spot of the specified colour in the current camera view. Parameter colourLimits defines the range of valid values. It should be a 6-element array of the form {min red, max red, min green, max green, min blue, max blue}. This implementation only works for red or green, and ignores the limits!

Specified by:
getSpotPosition in interface KoalaCamera

getSpotPosition

public java.awt.Point getSpotPosition(java.awt.Color colour)
Find a spot of the specified colour in the current camera view. This implementation only works for red or green!

Specified by:
getSpotPosition in interface KoalaCamera

getSpotPosition

public java.awt.Point getSpotPosition(boolean red)
Find a red or green spot in the current camera view.