Class PositionWrite

java.lang.Object
frc.spectrumLib.mechanism.PositionWrite

public final class PositionWrite extends Object
A position written to a motor off the main thread, tracked until the motor's readings show it.

Phoenix's setPosition waits up to 100 ms for the device, and a homing mechanism writes its position in the middle of a match, so the write goes out on another thread and the main loop does not wait for it. The new position then reaches the readings a status frame or more later. Until then they are still measured from the old zero, and logic that treated them as homed would act on the wrong position. While isPending() the mechanism holds its setpoints and the tracking stop does not run.

The write has landed once the reading is nearer to where the new zero puts the mechanism than to where the old one does. Both move with the mechanism's velocity meanwhile. A write the readings still have not shown after RESEND_SECONDS is sent again (a lost CAN frame).

Pure logic on logged inputs and the robot clock, so it replays.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Writes sent again because the readings did not show them, since boot.
    boolean
    A write is out that the readings have not shown yet: the position is not trustworthy.
    void
    sent(double nowSeconds, double position, double reading)
    The mechanism sent a position write this loop.
    double
    update(double nowSeconds, boolean connected, double position, double velocity)
    Advances on one loop's logged readings.

    Methods inherited from class Object

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

    • PositionWrite

      public PositionWrite()
  • Method Details

    • sent

      public void sent(double nowSeconds, double position, double reading)
      The mechanism sent a position write this loop.
      Parameters:
      nowSeconds - the robot clock
      position - the position written, rotations
      reading - this loop's position reading, before the write
    • update

      public double update(double nowSeconds, boolean connected, double position, double velocity)
      Advances on one loop's logged readings.
      Parameters:
      nowSeconds - the robot clock
      connected - the motor answered this loop; a disconnected motor's readings are stale or zero, so they neither confirm the write nor move the frames
      position - this loop's position reading, rotations
      velocity - this loop's velocity reading, rotations per second
      Returns:
      the position to send again this loop, or NaN
    • isPending

      public boolean isPending()
      A write is out that the readings have not shown yet: the position is not trustworthy.
    • getResends

      public int getResends()
      Writes sent again because the readings did not show them, since boot.