Class CameraPoseFix

java.lang.Object
com.crossbotics.ftchelper.odometry.CameraPoseFix

public final class CameraPoseFix extends Object
ALPHA, NOT TESTED ON A ROBOT. Corrects the odometry's x and y with the field position a Limelight works out from AprilTags (MegaTag2). Off by default. Not for BIOBUZZ: its only field tags are under the CELLs, and the HIVEs tip, so the tags move during the match; a position worked out from them is wrong whenever a HIVE tips. It is for a season with fixed wall tags.

Built from last season's lessons (docs/from-last-season.md): the odometry must be right on its own; only the camera's correction is smoothed, never the wheel moves; each camera position is compared with where the robot was when the picture was taken (not now); old and repeated pictures are skipped; a big jump is refused; nothing is used while the robot moves fast. Every decision is said on a debug line: "used +1.2, -0.4 in" or "refused: moving".

The Limelight's field frame is the field's own; ours is from the drivers' wall (x right, y away, heading 0 = facing away). turnDeg turns one into the other (a multiple of 90 for a square field, found with the Camera Fix Check in Tune and check): our (x, y) = the Limelight's turned turnDeg counterclockwise, and our heading = the Limelight's yaw + turnDeg - 90.

It never waits and never moves anything: the robot in five files calls record(long, double, double) every loop and offer(double, double, long, long, int, double, double) for each new picture, and applies what it returns. Docs: docs/modules/odometry.md, "Camera fix (alpha)"

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    What one picture did: the correction to add (0, 0 when refused) and the words for the debug line.
    static final class 
    The settings, all from Tunables.CameraFix.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applied(double dxIn, double dyIn)
    A correction was applied to the odometry: the recorded poses move with it, so a later picture (taken before it) does not count the same error again.
    The last picture's decision (for the debug line).
    double
    limelightYaw(double ourHeadingDeg)
    The heading to send the Limelight (its yaw, degrees) for our heading: ours - turnDeg + 90.
    offer(double llXIn, double llYIn, long pictureNanos, long nowNanos, int tags, double speedInPerSec, double turnDegPerSec)
    One NEW picture's position (the Limelight's frame, inches): the correction to add to the odometry, or why not.
    double
    ourHeading(double limelightYawDeg)
    Our heading for a Limelight yaw: yaw + turnDeg - 90.
    void
    record(long nanos, double xIn, double yIn)
    Every loop: the odometry's pose now (our frame, inches), so a picture can be compared with its own moment.
    static double
    suggestTurn(double ourHeadingDeg, double limelightYawDeg)
    The turnDeg that makes a Limelight yaw match our heading, to the nearest 90: for the Camera Fix Check (the robot standing still, its heading right).
    double[]
    toOurs(double llXIn, double llYIn)
    Our frame from the Limelight's: (x, y) turned turnDeg counterclockwise.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • record

      public void record(long nanos, double xIn, double yIn)
      Every loop: the odometry's pose now (our frame, inches), so a picture can be compared with its own moment.
    • toOurs

      public double[] toOurs(double llXIn, double llYIn)
      Our frame from the Limelight's: (x, y) turned turnDeg counterclockwise.
      Returns:
      {x, y} in inches
    • limelightYaw

      public double limelightYaw(double ourHeadingDeg)
      The heading to send the Limelight (its yaw, degrees) for our heading: ours - turnDeg + 90.
    • ourHeading

      public double ourHeading(double limelightYawDeg)
      Our heading for a Limelight yaw: yaw + turnDeg - 90.
    • suggestTurn

      public static double suggestTurn(double ourHeadingDeg, double limelightYawDeg)
      The turnDeg that makes a Limelight yaw match our heading, to the nearest 90: for the Camera Fix Check (the robot standing still, its heading right).
    • offer

      public CameraPoseFix.Result offer(double llXIn, double llYIn, long pictureNanos, long nowNanos, int tags, double speedInPerSec, double turnDegPerSec)
      One NEW picture's position (the Limelight's frame, inches): the correction to add to the odometry, or why not.
      Parameters:
      pictureNanos - when the picture was taken (System.nanoTime clock)
      nowNanos - now
      tags - tags in the picture
      speedInPerSec - the robot's speed now
      turnDegPerSec - its turn rate now
    • applied

      public void applied(double dxIn, double dyIn)
      A correction was applied to the odometry: the recorded poses move with it, so a later picture (taken before it) does not count the same error again.
    • last

      public CameraPoseFix.Result last()
      The last picture's decision (for the debug line).