Class QuestNavWrapper

java.lang.Object
yall.VisionCamera
yall.cameras.QuestNavWrapper
All Implemented Interfaces:
AutoCloseable

public class QuestNavWrapper extends VisionCamera
A QuestNav headset: a Meta Quest on the robot that tracks its own pose with its cameras and IMU, through QuestNavLib. It isn't a camera and sees no targets, but it gives robot pose estimates like one, so it works with VisionSystem, the pose filter and telemetry like every other VisionCamera.
QuestNavWrapper quest = new QuestNavWrapper(new QuestNav(),
    new VisionCameraConfig()
        .withRobotToCamera(Inches.of(-10), Inches.of(0), Inches.of(14),   // where the headset is
                           Degrees.of(0), Degrees.of(0), Degrees.of(180)));

// Once the robot's pose is known (at the start of autonomous, or from AprilTags while disabled):
quest.setRobotPose(startingPose);

The config's robot-to-camera transform is where the headset is on the robot. The Quest reports its own pose, and the wrapper moves it back to the robot's origin with that transform, so measure it carefully: an error in the headset's yaw turns every estimate.

The Quest tracks its pose relative to where it was when its tracking started, not on the field, so its poses mean nothing until it is told where the robot is with setRobotPose(Pose2d). Until then, and from each pose reset until the headset confirms it, its estimates are rejected. A reset sent with QuestNav.setPose(Pose3d) directly counts too, once the wrapper exists. If the robot program restarts while the headset keeps tracking (a brownout, for example), trustCurrentPose() accepts the pose the headset already has. If the QuestNav app on the headset restarts, its tracking starts over, so its estimates are rejected again until the next reset.

Estimates are checked with VisionPoseFilter.checkWithoutTags(VisionPoseEstimate, Field, double): the age, field bounds, height, tilt, pose jump and custom checks apply, the tag checks don't. Estimates taken while the headset has lost tracking are rejected. Accepted estimates get the standard deviations from withStdDevs(Distance, Angle), not the filter's.

VisionCamera.update() calls QuestNav.commandPeriodic(), so QuestNav's callbacks still fire, and reads QuestNav.getAllUnreadPoseFrames(). Don't call either elsewhere: each frame is handed out only once. The headset has no pipelines; pipeline settings are ignored.

In simulation, the headset reports the robot's true pose from its VisionSim world in its own tracking frame, which starts where the robot was on the first update, as a real headset's does. setRobotPose(Pose2d) resets it at once. Use the wrapper's setRobotPose(Pose2d) in simulation, since the simulated headset doesn't read QuestNav.setPose(Pose3d). The world's blackouts and dropouts drop the headset's frames too.

No vendor configs are accepted; use getCamera() for QuestNav settings.

  • Field Details

    • NAME

      public static final String NAME
      The camera name QuestNav estimates and telemetry are reported under.
      See Also:
  • Constructor Details

    • QuestNavWrapper

      public QuestNavWrapper(gg.questnav.questnav.QuestNav questNav, VisionCameraConfig config)
      Wraps a QuestNav headset.
      Parameters:
      questNav - The QuestNav object.
      config - The headset's config. Its robot-to-camera transform is where the headset is on the robot.
  • Method Details

    • withStdDevs

      public QuestNavWrapper withStdDevs(Distance xy, Angle heading)
      Sets the standard deviations given to accepted estimates. Defaults to QuestNav's recommended 2 cm for x and y and 2 degrees for the heading.
      Parameters:
      xy - Standard deviation of x and y.
      heading - Standard deviation of the heading.
      Returns:
      This wrapper, for chaining.
    • getStdDevs

      public Matrix<N3,N1> getStdDevs()
      The standard deviations given to accepted estimates.
      Returns:
      Standard deviations of x (meters), y (meters) and heading (radians).
    • setRobotPose

      public void setRobotPose(Pose3d robotPose)
      Tells the headset where the robot is, which puts its poses on the field. Call it when the robot's pose is known: at the start of autonomous, or from AprilTag estimates while disabled. Estimates are rejected until the headset confirms the reset.
      Parameters:
      robotPose - The robot's pose on the field.
    • setRobotPose

      public void setRobotPose(Pose2d robotPose)
      Tells the headset where the robot is, on the floor.
      Parameters:
      robotPose - The robot's pose on the field.
      See Also:
    • trustCurrentPose

      public void trustCurrentPose()
      Accepts the pose the headset already has, without resetting it. Use it when the robot program restarted while the headset kept tracking, such as after a brownout mid-match, so the headset's poses are still on the field from an earlier reset.
    • isPoseSet

      public boolean isPoseSet()
      Whether the headset's poses are on the field: it has confirmed a pose reset (or trustCurrentPose() was called), and no newer reset is waiting for its response.
      Returns:
      true if its estimates can be accepted.
    • isTracking

      public boolean isTracking()
      Whether the headset is tracking its pose. Simulated headsets track unless their world is blacked out.
      Returns:
      true if tracking.
    • readFrames

      protected List<VisionFrame> readFrames()
      Description copied from class: VisionCamera
      Reads the frames the real camera produced since the last call. Call once per loop.
      Specified by:
      readFrames in class VisionCamera
      Returns:
      The frames, oldest first.
    • checkEstimate

      protected Optional<String> checkEstimate(VisionPoseEstimate estimate, VisionPoseFilter filter, Field field, double nowSeconds, double averageTagAreaPercent)
      Description copied from class: VisionCamera
      Runs the pose filter on an estimate. AprilTag cameras use VisionPoseFilter.check(VisionPoseEstimate, Field, double, double); a pose source that doesn't use tags overrides this, for example with VisionPoseFilter.checkWithoutTags(VisionPoseEstimate, Field, double).
      Overrides:
      checkEstimate in class VisionCamera
      Parameters:
      estimate - The estimate.
      filter - The config's pose filter.
      field - The config's field.
      nowSeconds - Current Timer.getMonotonicTimestamp().
      averageTagAreaPercent - Average image area of the frame's AprilTags, or NaN if unknown.
      Returns:
      Why the estimate was rejected, or empty to accept it.
    • applyPipelineIndex

      protected void applyPipelineIndex(int index)
      Description copied from class: VisionCamera
      Switches the real camera's pipeline.
      Specified by:
      applyPipelineIndex in class VisionCamera
      Parameters:
      index - Pipeline index.
    • readPipelineIndex

      protected int readPipelineIndex()
      Description copied from class: VisionCamera
      Reads the real camera's pipeline.
      Specified by:
      readPipelineIndex in class VisionCamera
      Returns:
      Pipeline index.
    • readConnected

      protected boolean readConnected()
      Description copied from class: VisionCamera
      Whether the real camera is sending data.
      Specified by:
      readConnected in class VisionCamera
      Returns:
      true if connected.
    • isSimulated

      public boolean isSimulated()
      Whether this headset is giving simulated poses.
      Overrides:
      isSimulated in class VisionCamera
      Returns:
      true in simulation with simulation enabled in the config.
    • getVisionSim

      public Optional<VisionSim> getVisionSim()
      The simulated world this headset is in, which VisionSystem.updateSimulation(Pose2d) updates.
      Overrides:
      getVisionSim in class VisionCamera
      Returns:
      The world, or empty when not simulating.
    • getCamera

      public gg.questnav.questnav.QuestNav getCamera()
      Description copied from class: VisionCamera
      The vendor's camera object, for settings YALL doesn't cover. Each wrapper narrows the return type to its vendor's class.
      Specified by:
      getCamera in class VisionCamera
      Returns:
      The vendor's camera object.
    • close

      public void close()
      Closes the reset subscribers, then the parts every camera shares.
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class VisionCamera