// gyro history for timestamp interpolation
private static final int GYRO_HISTORY_SIZE = 50;
- private double[] gyroTimestampsHistory = new double[GYRO_HISTORY_SIZE];
- private double[] gyroYawsHistory = new double[GYRO_HISTORY_SIZE];
- private int gyroHistoryHead = 0;
- private int gyroHistoryCount = 0;
+ private double[] gyroTimestampsHistory = new double[GYRO_HISTORY_SIZE]; // circular buffer of gyro timestamps for interpolation
+ private double[] gyroYawsHistory = new double[GYRO_HISTORY_SIZE]; // circular buffer of gyro yaw angles corresponding to timestamps
+ private int gyroHistoryHead = 0; // index of the most recent entry in the circular buffer
+ private int gyroHistoryCount = 0; // number of valid entries in the history buffer
private final Field2d field = new Field2d();
package frc.robot.util.Vision;
+import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.geometry.Pose3d;
import frc.robot.constants.GyroBiasConstants;
* normalize angle to [-PI, PI]
*/
private double normalizeAngle(double angle) {
- while (angle > Math.PI) {
- angle -= 2 * Math.PI;
- }
- while (angle < -Math.PI) {
- angle += 2 * Math.PI;
- }
- return angle;
+ return MathUtil.angleModulus(angle);
}
/**