Class Camera

java.lang.Object
com.crossbotics.ftchelper.robot.Module<Camera>
com.crossbotics.ftchelper.robot.Camera
All Implemented Interfaces:
Subsystem

public final class Camera extends Module<Camera>
A camera that finds AprilTags: a Limelight 3A, a webcam or a HuskyLens. Other modules use it: a Turret that follows the goal, a Launcher whose speed comes from the distance.

 camera = add(Camera.limelight("limelight").goal("BLUE SCORING", "RED SCORING"));   // Robot.java
 

goal(String, String) names this season's goal for each alliance (the tag group's name); goal() then gives the target for the alliance chosen in autonomous. BIOBUZZ: the goal is always that alliance's HIVE's CELL that reads right side up (the up CELL, the one you can score in), whichever of its two CELLs that is now; a CELL whose tags read upside down is never the goal (TagGroup.goalTarget(com.crossbotics.ftchelper.vision.TargetSource, java.lang.String)). Tunables (Tunables.Limelight for device "limelight"): pipeline (Limelight only, default 0), pitchDeg (webcam or Limelight: its tilt up in degrees, 0 = level: then bearings and distances are along the floor, see CameraTilt). A webcam mounted upside down: upsideDown(). No usual buttons. It starts in INIT (a webcam needs a second or two). A camera missing from the robot configuration never stops the OpMode: it warns on the Driver Station and sees nothing.

Venue lighting: autoPipelines (Limelight) or autoExposure() (webcam) tries a few camera settings in INIT and keeps the one that sees the most AprilTags; the Driver Station shows the result at INIT. Its numbers are optional Tunables: autoLighting (true; false = skip the test and use pipeline, or the webcam's exposureMs and gain), lightingSettleMs (300), lightingPictures (10), lightingMinPictures (3), lightingAfterStartMs (0 = stop at START with the best so far), and for a webcam gain (-1 = the camera's highest).

A HuskyLens (huskyLens(java.lang.String)) says the number it was TAUGHT, not the tag's real number: list them with tag(int, int). It can also look for taught colors or an object (colors(), objects(), label(int, java.lang.String)). Tunables: hfovDeg (its view angle: measure it) and sizeIn (for a rough distance). No lighting test. Docs: docs/reference/robot-java.md (section "Camera"), docs/modules/vision.md

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    The part's telemetry line; each module adds its own.
    Venue lighting for a webcam: tries the camera's own automatic exposure, then 3, 6 and 12 ms, in INIT and keeps the one that sees the most AprilTags.
    autoExposure(long... exposuresMs)
    Venue lighting for a webcam: tries these exposures (milliseconds; 0 = the camera's own automatic exposure) in INIT and keeps the one that sees the most AprilTags.
    autoPipelines(int... pipelines)
    Venue lighting for a Limelight: tries these pipelines in INIT and keeps the one that sees the most AprilTags (set each one up on the Limelight's web page for a kind of light).
    void
    TeleOp's INIT work for this camera, for an OpMode that does not run the robot's INIT loop (the Shot Tuner): it reads the camera, so the lighting test runs, and shows its lines.
    HuskyLens: look for the colors you taught it, not AprilTags.
    The goal for this match's alliance (see goal(String, String)), or null if it is not seen now (or no goal was named).
    goal(String blueGroup, String redGroup)
    The goal's tag group for each alliance, e.g.
    static Camera
    A DFRobot HuskyLens on an I2C port (configure it as "HuskyLens").
    boolean
    True for a HuskyLens.
    boolean
    True for a Limelight.
    boolean
    True if upsideDown() is set in Robot.java.
    boolean
    True for a webcam.
    boolean
    True if Robot.java gives this camera a goal(...): goal() can find the alliance's goal.
    label(int taughtNumber, String name)
    HuskyLens: a name for a taught number, for target(name).
    The venue-lighting test (status and result), or null when it is off.
    static Camera
    A Limelight 3A.
    boolean
    True when the webcam's live view is on (PRACTICE profile, Tunables liveView not false).
    HuskyLens: look for the ONE object you taught it, not AprilTags.
    boolean
    Does the lighting test again, now: for a button.
    The camera inside (a LimelightTags, WebcamTags or HuskyLensCamera), for anything this module does not offer.
    void
    TeleOp's START work for this camera (an unfinished lighting test stops and keeps the best setting so far), for an OpMode that does not run the robot's START (the Shot Tuner).
    void
    Stops all motion.
    tag(int taughtNumber, int tagNumber)
    HuskyLens: which real AprilTag a taught number is.
    target(int id)
    The tag with this number, or null if not seen now.
    target(String name)
    The target with this name (a tag group or a tag's name), or null if not seen now.
    void
    Called once every loop.
    The webcam is mounted upside down.
    static Camera
    webcam(String name)
    A webcam (USB).

    Methods inherited from class com.crossbotics.ftchelper.robot.Module

    deviceName, isOptional, isPresent, looks, name, optional, part, partId, tunables, zone, zoneAbove, zoneBelow

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • limelight

      public static Camera limelight(String name)
      A Limelight 3A.
    • webcam

      public static Camera webcam(String name)
      A webcam (USB).
    • huskyLens

      public static Camera huskyLens(String name)
      A DFRobot HuskyLens on an I2C port (configure it as "HuskyLens"). It looks for AprilTags unless you say colors() or objects().
      
       camera = add(Camera.huskyLens("huskylens").tag(1, 30).tag(2, 31).goal("BLUE SCORING", "RED SCORING"));
       
    • tag

      public Camera tag(int taughtNumber, int tagNumber)
      HuskyLens: which real AprilTag a taught number is. Teach the tags with "Learn Multiple" on: the first is ID1, the next ID2. Needed for target(tagNumber) and for goal(String, String).
      Parameters:
      taughtNumber - the number on the camera's screen (ID1 = 1)
      tagNumber - the AprilTag's real number
    • label

      public Camera label(int taughtNumber, String name)
      HuskyLens: a name for a taught number, for target(name).
      Parameters:
      taughtNumber - the number on the camera's screen
      name - the name, e.g. "POLLEN"
    • colors

      public Camera colors()
      HuskyLens: look for the colors you taught it, not AprilTags.
    • objects

      public Camera objects()
      HuskyLens: look for the ONE object you taught it, not AprilTags.
    • goal

      public Camera goal(String blueGroup, String redGroup)
      The goal's tag group for each alliance, e.g. "BLUE SCORING" and "RED SCORING" in BIOBUZZ. For BIOBUZZ each name stands for that alliance's HIVE: the aim goes to its CELL that reads right side up now (the up CELL), "RED SCORING" or "RED AUDIENCE", and never to a CELL that reads upside down.
      Parameters:
      blueGroup - the group the BLUE alliance aims at
      redGroup - the group the RED alliance aims at
    • autoPipelines

      public Camera autoPipelines(int... pipelines)
      Venue lighting for a Limelight: tries these pipelines in INIT and keeps the one that sees the most AprilTags (set each one up on the Limelight's web page for a kind of light). Your usual pipeline FIRST: it wins ties and is kept if no tag is seen. See docs/modules/vision.md.
      
       camera = add(Camera.limelight("limelight").autoPipelines(0, 1, 2).goal("BLUE SCORING", "RED SCORING"));
       
      Parameters:
      pipelines - the pipeline numbers to try, usual one first
    • autoExposure

      public Camera autoExposure()
      Venue lighting for a webcam: tries the camera's own automatic exposure, then 3, 6 and 12 ms, in INIT and keeps the one that sees the most AprilTags. See autoExposure(long...).
    • autoExposure

      public Camera autoExposure(long... exposuresMs)
      Venue lighting for a webcam: tries these exposures (milliseconds; 0 = the camera's own automatic exposure) in INIT and keeps the one that sees the most AprilTags. Usual one FIRST.
      Parameters:
      exposuresMs - the exposures to try, usual one first
    • upsideDown

      public Camera upsideDown()
      The webcam is mounted upside down. Without this, an upside-down webcam turns the robot the wrong way when it aims, and it never sees the goal: every tag reads upside down (a down CELL, in BIOBUZZ). With it, left is left again and the tags read right side up. The live view on the Driver Station stays upside down. Webcam only: a Limelight has its own setting on its web page (Settings, Orientation).
      
       camera = add(Camera.webcam("Webcam 1").upsideDown().goal("BLUE SCORING", "RED SCORING"));
       
    • isUpsideDown

      public boolean isUpsideDown()
      True if upsideDown() is set in Robot.java.
    • isLimelight

      public boolean isLimelight()
      True for a Limelight.
    • isWebcam

      public boolean isWebcam()
      True for a webcam.
    • isHuskyLens

      public boolean isHuskyLens()
      True for a HuskyLens.
    • liveViewOn

      public boolean liveViewOn()
      True when the webcam's live view is on (PRACTICE profile, Tunables liveView not false).
    • lighting

      public LightingSweep lighting()
      The venue-lighting test (status and result), or null when it is off.
    • relight

      public boolean relight()
      Does the lighting test again, now: for a button. Aim the camera at a tag, then press. In the match it takes up to 5 s (or Tunables lightingAfterStartMs when that is set), and the camera sees no targets until it is done (so do not press while you aim to shoot). If no setting sees a tag, it keeps the setting it had. Needs autoExposure() or autoPipelines, and Tunables autoLighting not false; without them it does nothing, and the TeleOp screen says so for 5 s.
      Returns:
      true if the test started again
    • checkInInit

      public void checkInInit(RobotTelemetry t)
      TeleOp's INIT work for this camera, for an OpMode that does not run the robot's INIT loop (the Shot Tuner): it reads the camera, so the lighting test runs, and shows its lines. Call it every INIT loop.
      Parameters:
      t - the Driver Hub screen
    • started

      public void started()
      TeleOp's START work for this camera (an unfinished lighting test stops and keeps the best setting so far), for an OpMode that does not run the robot's START (the Shot Tuner). Call it once, at START.
    • knowsGoal

      public boolean knowsGoal()
      True if Robot.java gives this camera a goal(...): goal() can find the alliance's goal.
    • goal

      public TargetObservation goal()
      The goal for this match's alliance (see goal(String, String)), or null if it is not seen now (or no goal was named). BIOBUZZ: that alliance's HIVE's CELL that reads right side up; null when only an upside-down CELL is in view. Always check for null.
    • target

      public TargetObservation target(String name)
      The target with this name (a tag group or a tag's name), or null if not seen now.
    • target

      public TargetObservation target(int id)
      The tag with this number, or null if not seen now.
    • source

      public TargetSource source()
      The camera inside (a LimelightTags, WebcamTags or HuskyLensCamera), for anything this module does not offer.
    • update

      public void update()
      Description copied from interface: Subsystem
      Called once every loop. Do the hardware work here. Must be quick: no sleep, no waiting. While update() waits, the whole robot is frozen (no driving, no limits, no STOP).
    • stop

      public void stop()
      Description copied from interface: Subsystem
      Stops all motion. Called at the end of every OpMode.
    • addTelemetry

      public void addTelemetry(RobotTelemetry t)
      Description copied from class: Module
      The part's telemetry line; each module adds its own.
      Specified by:
      addTelemetry in interface Subsystem
      Overrides:
      addTelemetry in class Module<Camera>