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. A webcam or Limelight told its tilt (pitchDeg in its Tunables section, CameraTilt) gives the distance along the floor instead, and a bearing along the floor. 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).
  • rollDeg: how far the tag (or the row of tags) is turned in the picture, in degrees: 0 = right side up, 180 (or -180) = upside down. NaN if the camera could not tell. isUpright() asks "right side up?". BIOBUZZ: a CELL's tags read right side up only while that CELL is the up one, the one you can score in.

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 double
    Which way the target's face points, along the floor, in the camera's frame (the same frame as bearingDeg: for a camera on the robot's front, the robot's): degrees, counterclockwise +, turned to the camera's side.
    final int
    The AprilTag's number, CLUSTER for a group of tags, or ODOMETRY.
    final String
    A name to show on the screen, e.g.
    static final int
    The id of a target worked out from the ODOMETRY (where the robot is and where the goal is on the field), not seen by a camera.
    final double
    How far it is turned in the picture: 0 = right side up, +/-180 = upside down.
    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.
    TargetObservation(int id, String name, double bearingDeg, double distanceIn, long timeNanos, double rollDeg)
    Makes one observation with the tag's turn in the picture.
    TargetObservation(int id, String name, double bearingDeg, double distanceIn, long timeNanos, double rollDeg, double facingDeg)
    Makes one observation with the tag's turn in the picture and which way its face points.
  • 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 this target came from the odometry (ODOMETRY), not from a camera.
    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.
    boolean
    True if the tag reads right side up in the picture (turned less than 90 degrees either way).
    A short line of text for the Driver Station, e.g.
    withBearing(double newBearingDeg)
    The same observation with another bearing (everything else kept).

    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:
    • ODOMETRY

      public static final int ODOMETRY
      The id of a target worked out from the ODOMETRY (where the robot is and where the goal is on the field), not seen by a camera. The five-files robot uses it when the camera loses the goal (see docs/reference/robot-java.md, section "Aim").
      See Also:
    • id

      public final int id
      The AprilTag's number, CLUSTER for a group of tags, or ODOMETRY.
    • 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).
    • rollDeg

      public final double rollDeg
      How far it is turned in the picture: 0 = right side up, +/-180 = upside down. NaN if unknown.
    • facingDeg

      public final double facingDeg
      Which way the target's face points, along the floor, in the camera's frame (the same frame as bearingDeg: for a camera on the robot's front, the robot's): degrees, counterclockwise +, turned to the camera's side. Straight on it is the bearing + 180. NaN if unknown (a camera that cannot tell, or a face that points straight down). Aim's angle aim uses it.
  • 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)
    • TargetObservation

      public TargetObservation(int id, String name, double bearingDeg, double distanceIn, long timeNanos, double rollDeg)
      Makes one observation with the tag's turn in the picture. The camera classes call this for you.
      Parameters:
      rollDeg - how far it is turned in the picture, degrees: 0 = right side up, +/-180 = upside down (NaN if unknown)
    • TargetObservation

      public TargetObservation(int id, String name, double bearingDeg, double distanceIn, long timeNanos, double rollDeg, double facingDeg)
      Makes one observation with the tag's turn in the picture and which way its face points. The camera classes call this for you.
      Parameters:
      facingDeg - which way the face points along the floor, robot frame, degrees, + = counterclockwise (NaN if unknown); see facingDeg
  • Method Details

    • withBearing

      public TargetObservation withBearing(double newBearingDeg)
      The same observation with another bearing (everything else kept). For code that moves the aim point.
      Parameters:
      newBearingDeg - degrees, positive = LEFT
      Returns:
      a new observation
    • 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).
    • isUpright

      public boolean isUpright()
      True if the tag reads right side up in the picture (turned less than 90 degrees either way). False if it is upside down, or if the camera could not tell (NaN).
    • fromOdometry

      public boolean fromOdometry()
      True if this target came from the odometry (ODOMETRY), not from a camera.
    • 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