diff --git a/wpimath/src/main/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimator.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimator.java index c78716a910..45dbf23cd2 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimator.java @@ -19,6 +19,7 @@ import edu.wpi.first.math.numbers.N1; import edu.wpi.first.math.numbers.N3; import edu.wpi.first.util.WPIUtilJNI; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Objects; /** @@ -190,7 +191,11 @@ public class DifferentialDrivePoseEstimator { */ public void addVisionMeasurement(Pose2d visionRobotPoseMeters, double timestampSeconds) { // Step 0: If this measurement is old enough to be outside the pose buffer's timespan, skip. - if (m_poseBuffer.getInternalBuffer().lastKey() - kBufferDuration > timestampSeconds) { + try { + if (m_poseBuffer.getInternalBuffer().lastKey() - kBufferDuration > timestampSeconds) { + return; + } + } catch (NoSuchElementException ex) { return; } diff --git a/wpimath/src/main/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimator.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimator.java index b6f11c44a4..c61a915952 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimator.java @@ -20,6 +20,7 @@ import edu.wpi.first.math.numbers.N1; import edu.wpi.first.math.numbers.N3; import edu.wpi.first.util.WPIUtilJNI; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Objects; /** @@ -178,7 +179,11 @@ public class MecanumDrivePoseEstimator { */ public void addVisionMeasurement(Pose2d visionRobotPoseMeters, double timestampSeconds) { // Step 0: If this measurement is old enough to be outside the pose buffer's timespan, skip. - if (m_poseBuffer.getInternalBuffer().lastKey() - kBufferDuration > timestampSeconds) { + try { + if (m_poseBuffer.getInternalBuffer().lastKey() - kBufferDuration > timestampSeconds) { + return; + } + } catch (NoSuchElementException ex) { return; } diff --git a/wpimath/src/main/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimator.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimator.java index a36bf71e15..78d4cdf8da 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimator.java @@ -21,6 +21,7 @@ import edu.wpi.first.math.numbers.N3; import edu.wpi.first.util.WPIUtilJNI; import java.util.Arrays; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Objects; /** @@ -180,7 +181,11 @@ public class SwerveDrivePoseEstimator { */ public void addVisionMeasurement(Pose2d visionRobotPoseMeters, double timestampSeconds) { // Step 0: If this measurement is old enough to be outside the pose buffer's timespan, skip. - if (m_poseBuffer.getInternalBuffer().lastKey() - kBufferDuration > timestampSeconds) { + try { + if (m_poseBuffer.getInternalBuffer().lastKey() - kBufferDuration > timestampSeconds) { + return; + } + } catch (NoSuchElementException ex) { return; } diff --git a/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp b/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp index 590991cd03..55118fde14 100644 --- a/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp +++ b/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp @@ -96,8 +96,9 @@ void DifferentialDrivePoseEstimator::AddVisionMeasurement( const Pose2d& visionRobotPose, units::second_t timestamp) { // Step 0: If this measurement is old enough to be outside the pose buffer's // timespan, skip. - if (m_poseBuffer.GetInternalBuffer().front().first - kBufferDuration > - timestamp) { + if (!m_poseBuffer.GetInternalBuffer().empty() && + m_poseBuffer.GetInternalBuffer().front().first - kBufferDuration > + timestamp) { return; } diff --git a/wpimath/src/main/native/cpp/estimator/MecanumDrivePoseEstimator.cpp b/wpimath/src/main/native/cpp/estimator/MecanumDrivePoseEstimator.cpp index dcb668fcd5..b32ce831ca 100644 --- a/wpimath/src/main/native/cpp/estimator/MecanumDrivePoseEstimator.cpp +++ b/wpimath/src/main/native/cpp/estimator/MecanumDrivePoseEstimator.cpp @@ -107,8 +107,9 @@ void frc::MecanumDrivePoseEstimator::AddVisionMeasurement( const Pose2d& visionRobotPose, units::second_t timestamp) { // Step 0: If this measurement is old enough to be outside the pose buffer's // timespan, skip. - if (m_poseBuffer.GetInternalBuffer().front().first - kBufferDuration > - timestamp) { + if (!m_poseBuffer.GetInternalBuffer().empty() && + m_poseBuffer.GetInternalBuffer().front().first - kBufferDuration > + timestamp) { return; } diff --git a/wpimath/src/main/native/include/frc/estimator/SwerveDrivePoseEstimator.h b/wpimath/src/main/native/include/frc/estimator/SwerveDrivePoseEstimator.h index bff45cc05f..aaad4a559a 100644 --- a/wpimath/src/main/native/include/frc/estimator/SwerveDrivePoseEstimator.h +++ b/wpimath/src/main/native/include/frc/estimator/SwerveDrivePoseEstimator.h @@ -172,8 +172,9 @@ class SwerveDrivePoseEstimator { units::second_t timestamp) { // Step 0: If this measurement is old enough to be outside the pose buffer's // timespan, skip. - if (m_poseBuffer.GetInternalBuffer().front().first - kBufferDuration > - timestamp) { + if (!m_poseBuffer.GetInternalBuffer().empty() && + m_poseBuffer.GetInternalBuffer().front().first - kBufferDuration > + timestamp) { return; }