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. A webcam or Limelight told its tilt (pitchDegin 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 theSystem.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
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 doubleWhich way the target's face points, along the floor, in the camera's frame (the same frame asbearingDeg: for a camera on the robot's front, the robot's): degrees, counterclockwise +, turned to the camera's side.final intfinal StringA name to show on the screen, e.g.static final intThe 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 doubleHow far it is turned in the picture: 0 = right side up, +/-180 = upside down.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.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 TypeMethodDescriptiondoubleageMs(long nowNanos) Milliseconds since the picture was taken: how old the picture is.booleanTrue if this target came from the odometry (ODOMETRY), not from a camera.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.booleanTrue if the tag reads right side up in the picture (turned less than 90 degrees either way).toString()A short line of text for the Driver Station, e.g.withBearing(double newBearingDeg) The same observation with another bearing (everything else kept).
-
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:
-
ODOMETRY
public static final int ODOMETRYThe 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 -
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). -
rollDeg
public final double rollDegHow far it is turned in the picture: 0 = right side up, +/-180 = upside down. NaN if unknown. -
facingDeg
public final double facingDegWhich way the target's face points, along the floor, in the camera's frame (the same frame asbearingDeg: 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
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)
-
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); seefacingDeg
-
-
Method Details
-
withBearing
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, 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). -
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
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.
-