Package trclib.archive
Class TrcPixyCam1
java.lang.Object
trclib.archive.TrcPixyCam1
- Direct Known Subclasses:
FtcPixyCam1
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class implements the pixy camera object block communication protocol.static enum
This is used identify the request type. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate TrcPixyCam1.ObjectBlock
private TrcPixyCam1.ObjectBlock[]
protected final String
private final boolean
private final ArrayList<TrcPixyCam1.ObjectBlock>
private static final byte
private static final byte
private static final byte
private static final int
private static final int
private static final int
private static final byte
private boolean
private final TrcDbgTrace
-
Constructor Summary
ConstructorsConstructorDescriptionTrcPixyCam1
(String instanceName, boolean msbFirst) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionabstract void
asyncReadData
(TrcPixyCam1.RequestId requestId, int length) This method issues an asynchronous read of the specified number of bytes from the device.void
asyncWriteBytes
(byte[] data) This method writes the data to the device one byte at a time.abstract void
asyncWriteData
(TrcPixyCam1.RequestId requestId, byte[] data) This method writes the data buffer to the device asynchronously.void
end()
This method sets the pixy camera to end state so it will start properly next time.This method returns an array of detected object blocks.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.private void
processData
(TrcPixyCam1.RequestId requestId, byte[] data, int length) This method processes the data from the read completion handler.protected void
requestHandler
(Object context) This method is called when the read request is completed.void
setBrightness
(byte brightness) This method sets the camera brightness.void
setLED
(byte red, byte green, byte blue) This method sets the LED to the specified color.void
setPanTilt
(int pan, int tilt) This method sets the pan and tilt servo positions.void
start()
This method starts the pixy camera by queuing the initial read request if not already.toString()
This method returns the instance name.
-
Field Details
-
PIXY_SYNC_HIGH
private static final byte PIXY_SYNC_HIGH- See Also:
-
PIXY_START_WORD
private static final int PIXY_START_WORD- See Also:
-
PIXY_START_WORD_CC
private static final int PIXY_START_WORD_CC- See Also:
-
PIXY_START_WORDX
private static final int PIXY_START_WORDX- See Also:
-
PIXY_CMD_SET_LED
private static final byte PIXY_CMD_SET_LED- See Also:
-
PIXY_CMD_SET_BRIGHTNESS
private static final byte PIXY_CMD_SET_BRIGHTNESS- See Also:
-
PIXY_CMD_SET_PAN_TILT
private static final byte PIXY_CMD_SET_PAN_TILT- See Also:
-
tracer
-
instanceName
-
msbFirst
private final boolean msbFirst -
objects
-
detectedObjects
-
currBlock
-
started
private boolean started
-
-
Constructor Details
-
TrcPixyCam1
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
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
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
This method returns the 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
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
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
This method is called when the read request is completed.- Parameters:
context
- specifies the read request.
-