[wpimath] Add PoseEstimator.sampleAt() (#6426)

This commit is contained in:
Joseph Eng
2024-04-27 21:03:37 -07:00
committed by GitHub
parent 962bf7ff10
commit cdfa2ece6f
10 changed files with 404 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ import edu.wpi.first.math.numbers.N3;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
/**
* This class wraps {@link Odometry} to fuse latency-compensated vision measurements with encoder
@@ -125,6 +126,16 @@ public class PoseEstimator<T extends WheelPositions<T>> {
return m_odometry.getPoseMeters();
}
/**
* Return the pose at a given timestamp, if the buffer is not empty.
*
* @param timestampSeconds The pose's timestamp in seconds.
* @return The pose at the given timestamp (or Optional.empty() if the buffer is empty).
*/
public Optional<Pose2d> sampleAt(double timestampSeconds) {
return m_poseBuffer.getSample(timestampSeconds).map(record -> record.poseMeters);
}
/**
* Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate
* while still accounting for measurement noise.