Class TrcPixyCam1

java.lang.Object
trclib.archive.TrcPixyCam1
Direct Known Subclasses:
FtcPixyCam1

public abstract class TrcPixyCam1 extends Object
This class implements a platform independent pixy camera 1. This class is intended to be extended by a platform dependent pixy class which provides the abstract methods required by this class. This class provides the parser to read and parse the object block from the pixy camera 1. It also provides access to the last detected objects reported by the pixy camera asynchronously.
  • Field Details

  • Constructor Details

    • TrcPixyCam1

      public TrcPixyCam1(String instanceName, boolean msbFirst)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      msbFirst - specifies true if a word has MSB first.
  • Method Details

    • asyncReadData

      public abstract void asyncReadData(TrcPixyCam1.RequestId requestId, int length)
      This method issues an asynchronous read of the specified number of bytes from the device.
      Parameters:
      requestId - specifies the ID to identify the request for the request handler. Can be null if none was provided.
      length - specifies the number of bytes to read.
    • asyncWriteData

      public abstract void asyncWriteData(TrcPixyCam1.RequestId requestId, byte[] data)
      This method writes the data buffer to the device asynchronously.
      Parameters:
      requestId - specifies the ID to identify the request for the request handler. Can be null if none was provided.
      data - specifies the data buffer.
    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • start

      public void start()
      This method starts the pixy camera by queuing the initial read request if not already.
    • end

      public void end()
      This method sets the pixy camera to end state so it will start properly next time.
    • asyncWriteBytes

      public void asyncWriteBytes(byte[] data)
      This method writes the data to the device one byte at a time.
      Parameters:
      data - specifies the buffer containing the data to be written to the device.
    • setLED

      public void setLED(byte red, byte green, byte blue)
      This method sets the LED to the specified color.
      Parameters:
      red - specifies the red value.
      green - specifies the green value.
      blue - specifies the blue value.
    • setBrightness

      public void setBrightness(byte brightness)
      This method sets the camera brightness.
      Parameters:
      brightness - specifies the brightness value.
    • setPanTilt

      public void setPanTilt(int pan, int tilt)
      This method sets the pan and tilt servo positions.
      Parameters:
      pan - specifies the pan position between 0 and 1000.
      tilt - specifies the tilt position between 0 and 1000.
    • getDetectedObjects

      public TrcPixyCam1.ObjectBlock[] getDetectedObjects()
      This method returns an array of detected object blocks.
      Returns:
      array of detected object blocks, can be null if no object detected or result of the next frame not yet available.
    • processData

      private void processData(TrcPixyCam1.RequestId requestId, byte[] data, int length)
      This method processes the data from the read completion handler.
      Parameters:
      requestId - specifies the ID to identify the request. Can be null if none was provided.
      data - specifies the data read.
      length - specifies the number of bytes read.
    • getWord

      private int getWord(byte firstByte, byte secondByte, boolean msbFirst)
      This method combines the two byte into a 16-bit word according to whether the MSB is first.
      Parameters:
      firstByte - specifies the first byte.
      secondByte - specifies the second byte.
      msbFirst - specifies true if first byte is the MSB.
      Returns:
      combined 16-bit word.
    • requestHandler

      protected void requestHandler(Object context)
      This method is called when the read request is completed.
      Parameters:
      context - specifies the read request.