Class TargetObservation

java.lang.Object
com.crossbotics.ftchelper.vision.TargetObservation

public final class TargetObservation extends Object
One target the camera sees, in the same form for every camera (webcam or Limelight). Because both cameras give you this same object, the rest of your code (aiming, the shot table) does not care which camera you have.
  • bearingDeg: how far to turn to face it, in degrees. Positive = it is to the LEFT (counterclockwise, like the IMU). The library converts the Limelight's opposite sign for you.
  • distanceIn: distance from the camera to the target in inches, measured flat in the camera's own view (sideways and forward from the lens, its up/down left out), or NaN ("not a number": the camera could not tell) if unknown. It equals the distance along the floor only when the camera is level; a camera tilted up reads more (with the camera 20 degrees up and the target 2 ft higher: about 51 in instead of 46 in). So make the shot table with the camera mounted as it will be on the robot. Same meaning for every camera.
  • timeNanos: when the camera took the picture, on the System.nanoTime() clock (a stopwatch that counts nanoseconds, billionths of a second).

All the values are final: they are set once when the object is made and never change, so one observation always describes the same picture. The signs are in docs/conventions.md. Docs: docs/modules/vision.md

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final double
    Degrees to turn to face the target.
    static final int
    The id used for AprilTag clusters (they have a name instead of a number).
    final double
    Inches from the camera to the target, flat in the camera's own view (see above).
    final int
    The AprilTag's number, or CLUSTER for a group of tags.
    final String
    A name to show on the screen, e.g.
    final long
    When the picture was taken (System.nanoTime() clock, nanoseconds).
  • Constructor Summary

    Constructors
    Constructor
    Description
    TargetObservation(int id, String name, double bearingDeg, double distanceIn, long timeNanos)
    Makes one observation.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    ageMs(long nowNanos)
    Milliseconds since the picture was taken: how old the picture is.
    boolean
    True if the camera worked out a bearing (some detections have only an id).
    boolean
    True if the camera worked out a distance.
    boolean
    isFresh(long nowNanos, double maxAgeMs)
    True if the picture is newer than maxAgeMs.
    A short line of text for the Driver Station, e.g.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • CLUSTER

      public static final int CLUSTER
      The id used for AprilTag clusters (they have a name instead of a number). static final means one shared value for the whole program that never changes.
      See Also:
    • id

      public final int id
      The AprilTag's number, or CLUSTER for a group of tags.
    • name

      public final String name
      A name to show on the screen, e.g. "Tag 20" or a cluster's name.
    • bearingDeg

      public final double bearingDeg
      Degrees to turn to face the target. Positive = target is to the LEFT. NaN if unknown.
    • distanceIn

      public final double distanceIn
      Inches from the camera to the target, flat in the camera's own view (see above). NaN if unknown.
    • timeNanos

      public final long timeNanos
      When the picture was taken (System.nanoTime() clock, nanoseconds).
  • Constructor Details

    • TargetObservation

      public TargetObservation(int id, String name, double bearingDeg, double distanceIn, long timeNanos)
      Makes one observation. The camera classes call this for you.
      Parameters:
      id - the tag number, or CLUSTER
      name - a name to show
      bearingDeg - degrees to turn to face it, positive = LEFT (NaN if unknown)
      distanceIn - inches, flat in the camera's own view (NaN if unknown)
      timeNanos - when the picture was taken (System.nanoTime() clock)
  • Method Details

    • ageMs

      public double ageMs(long nowNanos)
      Milliseconds since the picture was taken: how old the picture is.
      Parameters:
      nowNanos - the time now, from System.nanoTime()
    • isFresh

      public boolean isFresh(long nowNanos, double maxAgeMs)
      True if the picture is newer than maxAgeMs. Old pictures must not be used to aim: the robot (or the target) has moved since, so the old bearing points the wrong way.
      Parameters:
      nowNanos - the time now, from System.nanoTime()
      maxAgeMs - the oldest picture you accept, in milliseconds
    • hasBearing

      public boolean hasBearing()
      True if the camera worked out a bearing (some detections have only an id).
    • hasDistance

      public boolean hasDistance()
      True if the camera worked out a distance.
    • toString

      public String toString()
      A short line of text for the Driver Station, e.g. "Tag 20: bearing 3.5 deg, 48.2 in". @Override means this replaces Java's built-in version of the method.
      Overrides:
      toString in class Object