Interface TargetSource

All Superinterfaces:
Subsystem
All Known Implementing Classes:
LimelightTags, WebcamTags

public interface TargetSource extends Subsystem
A camera that finds targets. WebcamTags and LimelightTags are two kinds; the rest of your code only talks to this interface, so you can switch cameras (or seasons) by changing ONE line. A new kind of camera next year? Write a class with these methods.

An interface is a list of methods that a class promises to have, without saying how they work. Any class that "implements TargetSource" can be used wherever a TargetSource is asked for. It also "extends Subsystem", so a camera can be added to your robot's group of mechanisms and gets update(), stop() and telemetry like the others (see core/Subsystem.java and docs/guides/architecture.md).


 TargetSource camera = useLimelight
         ? LimelightTags.create(hardwareMap, "limelight").pipeline(0)
         : WebcamTags.create(hardwareMap, "Webcam 1");
 camera.start();
 // every loop:
 camera.update();
 TargetObservation goal = camera.target("RED SCORING");   // a tag group, by name (null if not seen)
 TargetObservation tag = camera.target(31);                // one tag, by its number
 
Docs: docs/modules/vision.md. How to write your own: docs/guides/extending.md
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Shows a warning if the camera is not working, and, when debug lines are on (the PRACTICE profile), its status and every target it sees.
    void
    Stops the camera and frees it.
    boolean
    True if the camera is working (connected and streaming).
    void
    Starts the camera.
    A short status for telemetry, e.g.
    default void
    Stopping a camera means closing it, so the next OpMode can use it.
    target(int id)
    The target with this id in the latest picture, or null (nothing: not seen now).
    target(String name)
    The target with this name (e.g.
    Everything seen in the latest picture (empty if nothing, or if the latest picture is too old).

    Methods inherited from interface com.crossbotics.ftchelper.core.Subsystem

    name, update
  • Method Details

    • start

      void start()
      Starts the camera. Call in INIT (a webcam needs about 1-2 s).
    • targets

      Everything seen in the latest picture (empty if nothing, or if the latest picture is too old).
    • target

      default TargetObservation target(int id)
      The target with this id in the latest picture, or null (nothing: not seen now). Always check for null before using it. (default means the interface already gives this method a body, so each camera class gets it for free and does not have to write it.)
    • target

      default TargetObservation target(String name)
      The target with this name (e.g. an AprilTag cluster's name), or null.
    • isWorking

      boolean isWorking()
      True if the camera is working (connected and streaming).
    • status

      String status()
      A short status for telemetry, e.g. "STREAMING 28 fps" or "not connected".
    • close

      void close()
      Stops the camera and frees it. Called by stop().
    • stop

      default void stop()
      Stopping a camera means closing it, so the next OpMode can use it.
      Specified by:
      stop in interface Subsystem
    • addTelemetry

      default void addTelemetry(RobotTelemetry t)
      Shows a warning if the camera is not working, and, when debug lines are on (the PRACTICE profile), its status and every target it sees. @Override means this fills in a method that Subsystem asks for.
      Specified by:
      addTelemetry in interface Subsystem