Class FieldMapHash

java.lang.Object
frc.spectrumLib.vision.FieldMapHash

public final class FieldMapHash extends Object
A short fingerprint of an AprilTag field map, so the robot and each coprocessor can tell whether they solve with the same tags. Every side computes it the same way (the SpectrumJetson code implements this exact text), so change nothing here without changing them too:
  1. Tags sorted by ID, one line each: id,x,y,z,qw,qx,qy,qz (meters, and the quaternion of the tag's pose).
  2. A last line field,<length m>,<width m>.
  3. Every number with four decimals, String.format(Locale.ROOT, "%.4f"); lines joined with "\n", no trailing newline. Java rounds the shortest decimal form half-up (0.55245 gives 0.5525), where C and Python's "%.4f" round the exact binary value (0.5524): another implementation must round like Java, e.g. Python's Decimal(repr(x)).quantize(Decimal("0.0001"), ROUND_HALF_UP).
  4. SHA-256 of the UTF-8 bytes, lowercase hex, the first LENGTH characters.

Four decimals is a tenth of a millimeter: well under what any solve can see, and coarse enough that the same map read by two JSON parsers hashes the same.

  • Field Details

  • Method Details

    • of

      public static String of(AprilTagFieldLayout layout)
      The canonical hash of a layout.
      Parameters:
      layout - the field map
      Returns:
      LENGTH lowercase hex characters
    • canonicalText

      public static String canonicalText(AprilTagFieldLayout layout)
      The text that is hashed, for tests and for comparing with another implementation.
      Parameters:
      layout - the field map
      Returns:
      the canonical lines, joined with "\n"