Class HuskyLensCamera

java.lang.Object
com.crossbotics.ftchelper.vision.HuskyLensCamera
All Implemented Interfaces:
Subsystem, TargetSource

public class HuskyLensCamera extends Object implements 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 and sizeIn (NaN without it).
  • A single tag has no "right side up" (TargetObservation.rollDeg is 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
    Modifier and Type
    Class
    Description
    static enum 
    What the camera looks for.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    The view angle used until you measure yours (a guess: we found no number from the seller).
    static final int
    The picture's size in pixels: the boxes are in the camera's 320 x 240 screen (FTC docs).
    static final int
    The picture's size in pixels: the boxes are in the camera's 320 x 240 screen (FTC docs).
  • Constructor Summary

    Constructors
    Constructor
    Description
    HuskyLensCamera(String name, com.qualcomm.hardware.dfrobot.HuskyLens device)
    Wraps a HuskyLens you already have.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    answers(com.qualcomm.hardware.dfrobot.HuskyLens device)
    Asks the camera "are you there?" and checks its answer.
    void
    Stops reading, forgets its targets and ends the helper thread.
    create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String deviceName)
    Finds the HuskyLens in the robot configuration and wraps it.
    com.qualcomm.hardware.dfrobot.HuskyLens
    The SDK's HuskyLens object, for anything this class does not cover (e.g.
    groups(List<TagGroup> tagGroups)
    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.
    boolean
    True 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).
    label(int taughtNumber, String targetName)
    Gives a taught number a name, for target(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.
    What it looks for now.
    What to look for.
    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).
    void
    Starts reading.
    e.g.
    tag(int taughtNumber, int tagNumber)
    Says which real AprilTag a taught number is.
    Everything seen in the newest reading (empty if nothing, or if it is too old).
    void
    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, wait

    Methods inherited from interface com.crossbotics.ftchelper.vision.TargetSource

    addTelemetry, stop, target, target
  • Field Details

    • PICTURE_WIDTH

      public static final int PICTURE_WIDTH
      The 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_HEIGHT
      The 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_DEG
      The view angle used until you measure yours (a guess: we found no number from the seller).
      See Also:
  • Constructor Details

  • 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 hardwareMap
      deviceName - its name in the robot configuration, e.g. "huskylens"
    • mode

      public HuskyLensCamera mode(HuskyLensCamera.Mode newMode)
      What to look for. Default HuskyLensCamera.Mode.TAGS. You can change it in a running OpMode: the old mode's targets go away at once.
    • tag

      public HuskyLensCamera tag(int taughtNumber, int tagNumber)
      Says which real AprilTag a taught number is. Then target(tagNumber) and the tag groups work.
      Parameters:
      taughtNumber - the number on the camera's screen (ID1 = 1)
      tagNumber - the AprilTag's real number
    • label

      public HuskyLensCamera label(int taughtNumber, String targetName)
      Gives a taught number a name, for target(name). Useful for colors and objects.
      Parameters:
      taughtNumber - the number on the camera's screen
      targetName - the name, e.g. "POLLEN"
    • hfovDeg

      public HuskyLensCamera hfovDeg(double degrees)
      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

      public HuskyLensCamera 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). With it, targets get a ROUGH distance from the box's longer side. Without it, the distance is NaN.
    • groups

      public HuskyLensCamera groups(List<TagGroup> tagGroups)
      The tag groups reported as one target each (default: this season's, TagGroup.currentSeason()). An empty list turns groups off.
    • keepTargetsMs

      public HuskyLensCamera keepTargetsMs(double ms)
      Targets older than this are dropped (milliseconds, default 500).
    • start

      public void start()
      Starts reading. Call in INIT.
      Specified by:
      start in interface TargetSource
    • update

      public void update()
      Every loop: asks for a new reading on the helper thread and picks up the newest one. Never waits.
      Specified by:
      update in interface Subsystem
    • 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 own knock() 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

      public List<TargetObservation> targets()
      Everything seen in the newest reading (empty if nothing, or if it is too old).
      Specified by:
      targets in interface TargetSource
    • 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

      public HuskyLensCamera.Mode 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:
      isWorking in interface TargetSource
    • status

      public String status()
      e.g. "TAGS, 2 seen", "not started", or why it is not working.
      Specified by:
      status in interface TargetSource
    • close

      public void close()
      Stops reading, forgets its targets and ends the helper thread. The camera itself stays on.
      Specified by:
      close in interface TargetSource
    • 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

      public String name()
      Description copied from interface: Subsystem
      The name shown in telemetry and in the hardware check.
      Specified by:
      name in interface Subsystem