Package com.crossbotics.ftchelper.vision
Class TargetObservation
java.lang.Object
com.crossbotics.ftchelper.vision.TargetObservation
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 theSystem.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
FieldsModifier and TypeFieldDescriptionfinal doubleDegrees to turn to face the target.static final intThe id used for AprilTag clusters (they have a name instead of a number).final doubleInches from the camera to the target, flat in the camera's own view (see above).final intThe AprilTag's number, orCLUSTERfor a group of tags.final StringA name to show on the screen, e.g.final longWhen the picture was taken (System.nanoTime()clock, nanoseconds). -
Constructor Summary
ConstructorsConstructorDescriptionTargetObservation(int id, String name, double bearingDeg, double distanceIn, long timeNanos) Makes one observation. -
Method Summary
Modifier and TypeMethodDescriptiondoubleageMs(long nowNanos) Milliseconds since the picture was taken: how old the picture is.booleanTrue if the camera worked out a bearing (some detections have only an id).booleanTrue if the camera worked out a distance.booleanisFresh(long nowNanos, double maxAgeMs) True if the picture is newer thanmaxAgeMs.toString()A short line of text for the Driver Station, e.g.
-
Field Details
-
CLUSTER
public static final int CLUSTERThe id used for AprilTag clusters (they have a name instead of a number).static finalmeans one shared value for the whole program that never changes.- See Also:
-
id
public final int idThe AprilTag's number, orCLUSTERfor a group of tags. -
name
A name to show on the screen, e.g. "Tag 20" or a cluster's name. -
bearingDeg
public final double bearingDegDegrees to turn to face the target. Positive = target is to the LEFT. NaN if unknown. -
distanceIn
public final double distanceInInches from the camera to the target, flat in the camera's own view (see above). NaN if unknown. -
timeNanos
public final long timeNanosWhen the picture was taken (System.nanoTime()clock, nanoseconds).
-
-
Constructor Details
-
TargetObservation
Makes one observation. The camera classes call this for you.- Parameters:
id- the tag number, orCLUSTERname- a name to showbearingDeg- 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, fromSystem.nanoTime()
-
isFresh
public boolean isFresh(long nowNanos, double maxAgeMs) True if the picture is newer thanmaxAgeMs. 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, fromSystem.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
A short line of text for the Driver Station, e.g. "Tag 20: bearing 3.5 deg, 48.2 in".@Overridemeans this replaces Java's built-in version of the method.
-