Package com.crossbotics.ftchelper.vision
Class HuskyLensCamera
java.lang.Object
com.crossbotics.ftchelper.vision.HuskyLensCamera
- All Implemented Interfaces:
Subsystem,TargetSource
A DFRobot HuskyLens: a small camera with its own screen, plugged into an I2C sensor port of a hub. It
finds AprilTags, colors or objects by itself. You teach it with its buttons, on the camera.
HuskyLensCamera camera = HuskyLensCamera.create(hardwareMap, "huskylens")
.tag(1, 30).tag(2, 31); // taught number 1 is AprilTag 30, taught number 2 is AprilTag 31
camera.start(); // in INIT
// every loop:
camera.update();
TargetObservation tag = camera.target(30);
Three things are different from a webcam or a Limelight:
- It does not say the AprilTag's real number. It says the number it was TAUGHT: the first tag
you teach is 1, the next is 2. An untaught tag is 0. So tell this class what each taught number means
with
tag(int, int). - It gives only a box in the picture (center, width, height, in pixels of a 320 x 240 picture). The
bearing comes from the box's place and
hfovDeg(the camera's view angle, which you measure). The distance is a rough estimate from the box's size andsizeIn(NaN without it). - A single tag has no "right side up" (
TargetObservation.rollDegis NaN). A tag group (TagGroup) has one, from the order of its taught tags in the picture, as with the Limelight. It needs 2 tags of the group in view.
The SDK's driver gives at most 6 boxes per reading. Reading a HuskyLens is a slow I2C request, so it
runs on a helper thread and update() never waits (docs/guides/non-blocking.md).
Docs: docs/modules/vision.md#huskylenscamera
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe view angle used until you measure yours (a guess: we found no number from the seller).static final intThe picture's size in pixels: the boxes are in the camera's 320 x 240 screen (FTC docs).static final intThe picture's size in pixels: the boxes are in the camera's 320 x 240 screen (FTC docs). -
Constructor Summary
ConstructorsConstructorDescriptionHuskyLensCamera(String name, com.qualcomm.hardware.dfrobot.HuskyLens device) Wraps a HuskyLens you already have. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleananswers(com.qualcomm.hardware.dfrobot.HuskyLens device) Asks the camera "are you there?" and checks its answer.voidclose()Stops reading, forgets its targets and ends the helper thread.static HuskyLensCameraFinds the HuskyLens in the robot configuration and wraps it.com.qualcomm.hardware.dfrobot.HuskyLensThe SDK's HuskyLens object, for anything this class does not cover (e.g.The tag groups reported as one target each (default: this season's,TagGroup.currentSeason()).hfovDeg(double degrees) The camera's view angle from the left edge of the picture to the right edge.booleanTrue while the camera answers: a finished reading within the last second, and no problem.keepTargetsMs(double ms) Targets older than this are dropped (milliseconds, default 500).Gives a taught number a name, fortarget(name).com.qualcomm.hardware.dfrobot.HuskyLens.Block[]The newest reading's boxes as the SDK gives them (empty before the first), for anything else you need.mode()What it looks for now.mode(HuskyLensCamera.Mode newMode) What to look for.name()The name shown in telemetry and in the hardware check.sizeIn(double inches) The real size of what it looks at, in inches: its longest side as the camera sees it (an AprilTag's black square; a ball's width).voidstart()Starts reading.status()e.g.tag(int taughtNumber, int tagNumber) Says which real AprilTag a taught number is.targets()Everything seen in the newest reading (empty if nothing, or if it is too old).voidupdate()Every loop: asks for a new reading on the helper thread and picks up the newest one.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.crossbotics.ftchelper.vision.TargetSource
addTelemetry, stop, target, target
-
Field Details
-
PICTURE_WIDTH
public static final int PICTURE_WIDTHThe picture's size in pixels: the boxes are in the camera's 320 x 240 screen (FTC docs).- See Also:
-
PICTURE_HEIGHT
public static final int PICTURE_HEIGHTThe picture's size in pixels: the boxes are in the camera's 320 x 240 screen (FTC docs).- See Also:
-
GUESSED_HFOV_DEG
public static final double GUESSED_HFOV_DEGThe view angle used until you measure yours (a guess: we found no number from the seller).- See Also:
-
-
Constructor Details
-
HuskyLensCamera
Wraps a HuskyLens you already have. Most teams usecreate(com.qualcomm.robotcore.hardware.HardwareMap, java.lang.String)instead.
-
-
Method Details
-
create
public static HuskyLensCamera create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String deviceName) Finds the HuskyLens in the robot configuration and wraps it.- Parameters:
hardwareMap- the OpMode's hardwareMapdeviceName- its name in the robot configuration, e.g. "huskylens"
-
mode
What to look for. DefaultHuskyLensCamera.Mode.TAGS. You can change it in a running OpMode: the old mode's targets go away at once. -
tag
Says which real AprilTag a taught number is. Thentarget(tagNumber)and the tag groups work.- Parameters:
taughtNumber- the number on the camera's screen (ID1 = 1)tagNumber- the AprilTag's real number
-
label
Gives a taught number a name, fortarget(name). Useful for colors and objects.- Parameters:
taughtNumber- the number on the camera's screentargetName- the name, e.g. "POLLEN"
-
hfovDeg
The camera's view angle from the left edge of the picture to the right edge. Measure yours (docs/modules/vision.md#huskylenscamera). A wrong number makes bearings too big or too small, but a bearing of 0 stays straight ahead.- Parameters:
degrees- the angle, more than 1 and less than 179
-
sizeIn
The real size of what it looks at, in inches: its longest side as the camera sees it (an AprilTag's black square; a ball's width). With it, targets get a ROUGH distance from the box's longer side. Without it, the distance is NaN. -
groups
The tag groups reported as one target each (default: this season's,TagGroup.currentSeason()). An empty list turns groups off. -
keepTargetsMs
Targets older than this are dropped (milliseconds, default 500). -
start
public void start()Starts reading. Call in INIT.- Specified by:
startin interfaceTargetSource
-
update
public void update()Every loop: asks for a new reading on the helper thread and picks up the newest one. Never waits. -
answers
public static boolean answers(com.qualcomm.hardware.dfrobot.HuskyLens device) Asks the camera "are you there?" and checks its answer. A slow I2C request: never call it in the robot's loop. The SDK's ownknock()says true with nothing plugged in: on a REV hub, a read from an empty port gives zeros, and the driver accepts them. A real answer starts with 0x55, 0xAA.- Parameters:
device- the camera- Returns:
- true if it answered
-
targets
Everything seen in the newest reading (empty if nothing, or if it is too old).- Specified by:
targetsin interfaceTargetSource
-
latestBlocks
public com.qualcomm.hardware.dfrobot.HuskyLens.Block[] latestBlocks()The newest reading's boxes as the SDK gives them (empty before the first), for anything else you need. -
mode
What it looks for now. -
isWorking
public boolean isWorking()True while the camera answers: a finished reading within the last second, and no problem.- Specified by:
isWorkingin interfaceTargetSource
-
status
e.g. "TAGS, 2 seen", "not started", or why it is not working.- Specified by:
statusin interfaceTargetSource
-
close
public void close()Stops reading, forgets its targets and ends the helper thread. The camera itself stays on.- Specified by:
closein interfaceTargetSource
-
getHuskyLens
public com.qualcomm.hardware.dfrobot.HuskyLens getHuskyLens()The SDK's HuskyLens object, for anything this class does not cover (e.g. arrows from line tracking). -
name
Description copied from interface:SubsystemThe name shown in telemetry and in the hardware check.
-