Class PositionWrite
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 -
Method Summary
Modifier and TypeMethodDescriptionintWrites sent again because the readings did not show them, since boot.booleanA write is out that the readings have not shown yet: the position is not trustworthy.voidsent(double nowSeconds, double position, double reading) The mechanism sent a position write this loop.doubleupdate(double nowSeconds, boolean connected, double position, double velocity) Advances on one loop's logged readings.
-
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 clockposition- the position written, rotationsreading- 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 clockconnected- the motor answered this loop; a disconnected motor's readings are stale or zero, so they neither confirm the write nor move the framesposition- this loop's position reading, rotationsvelocity- 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.
-