Package com.crossbotics.ftchelper.vision
Class DistanceFilter
java.lang.Object
com.crossbotics.ftchelper.vision.DistanceFilter
Keeps camera glitches out of a distance (for example the launcher's speed from the distance). A
camera sometimes gives one picture with a wrong distance: a tag half hidden, a blur, a reflection. Used
as it comes, that one picture changes the flywheel speed (and the hood) for a moment, and a shot fired
then goes long or short. Two checks, one after the other:
- The middle of the last few pictures (the median, default the last 5): sort them and take the one in the middle. One or two bad pictures are then at the ends of the list and never used. It costs about 2 pictures of delay (0.07 s at 30 pictures a second).
- The jump check: a distance more than
jumpIn(default 12 in) from the one in use is only used once it shows up in 3 pictures in a row, each withinagreeIn(default 4 in) of the one before (a camera never gives the exact same number twice). A real move gets there in a moment; a glitch of a few pictures does not.
After a gap it starts over. No new picture for gapSec (0.5 s): the goal was out of
view, and a big change is expected then (the HIVE tipped, the robot drove away for pieces). So the
first distance after it is used without the jump check, as soon as 3 pictures are in (so one glitch
as the goal comes into view is still kept out).
It never waits: add(com.crossbotics.ftchelper.vision.TargetObservation, long) is one quick step. Only NEW pictures count: give each picture once,
with its own time (TargetObservation.timeNanos); the same picture again is ignored.
DistanceFilter filter = new DistanceFilter(5, 12, 4);
// every loop:
TargetObservation goal = camera.target("RED SCORING");
double d = filter.add(goal, System.nanoTime()); // NaN until it has a good distance
if (!Double.isNaN(d)) launcher.setDistance(d); // else keep the speed you have
Docs: docs/modules/vision.md#distancefilter-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleNo new picture for this long (seconds): start over (no jump check for the next distance).static final intPictures in a row a jump needs (each close to the one before) before it is used. -
Constructor Summary
ConstructorsConstructorDescriptionThe defaults: the middle of 5 pictures, jumps over 12 in need 3 pictures within 4 in.DistanceFilter(int medianOf, double jumpIn, double agreeIn) -
Method Summary
Modifier and TypeMethodDescriptiondoubleadd(TargetObservation seen, long nowNanos) One step: give the camera's goal now (null when it is not seen).doubledistance()The distance in use now (inches), NaN if none.booleanTrue while a jump is waiting to be sure (the distance in use is the one from before it).voidreset()Forget everything (a new match, or the goal out of view): the next distance is used without the jump check.
-
Field Details
-
JUMP_PICTURES
public static final int JUMP_PICTURESPictures in a row a jump needs (each close to the one before) before it is used.- See Also:
-
GAP_SEC
public static final double GAP_SECNo new picture for this long (seconds): start over (no jump check for the next distance).- See Also:
-
-
Constructor Details
-
DistanceFilter
public DistanceFilter(int medianOf, double jumpIn, double agreeIn) - Parameters:
medianOf- how many pictures the middle is taken from, 1 to 15 (1 = off: each picture as it comes). Default 5.jumpIn- a change bigger than this (inches) needsJUMP_PICTURESpictures to be used; 0 = no jump check. Default 12.agreeIn- how close (inches) each of those pictures must be to the one before. Default 4.
-
DistanceFilter
public DistanceFilter()The defaults: the middle of 5 pictures, jumps over 12 in need 3 pictures within 4 in.
-
-
Method Details
-
add
One step: give the camera's goal now (null when it is not seen). Returns the distance to use (inches), or NaN when there is none yet: keep what you had (the last speed).- Parameters:
seen- the goal now, or null (no distance: the same as null)nowNanos- the time now (the clock the camera stamps its pictures with)- Returns:
- the filtered distance in inches, or NaN
-
distance
public double distance()The distance in use now (inches), NaN if none. -
jumpWaiting
public boolean jumpWaiting()True while a jump is waiting to be sure (the distance in use is the one from before it). -
reset
public void reset()Forget everything (a new match, or the goal out of view): the next distance is used without the jump check.
-