Skip to content

Commit

Permalink
replace SwerveDriveWheelPositions
Browse files Browse the repository at this point in the history
  • Loading branch information
JayK445 committed Jan 3, 2025
1 parent 84901f4 commit 88e1905
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
18 changes: 8 additions & 10 deletions src/main/java/frc/robot/RobotState.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Twist2d;
import edu.wpi.first.math.interpolation.TimeInterpolatableBuffer;
import edu.wpi.first.math.kinematics.SwerveDriveWheelPositions;
import edu.wpi.first.math.kinematics.SwerveModulePosition;
import frc.robot.subsystems.swerve.DriveConstants;
import org.littletonrobotics.junction.AutoLogOutput;

/* based on wpimath/../PoseEstimator.java */
public class RobotState {
public record OdometryMeasurement(
SwerveDriveWheelPositions wheelPositions, Rotation2d gyroAngle, double timestamp) {}
SwerveModulePosition[] wheelPositions, Rotation2d gyroAngle, double timestamp) {}

public record VisionMeasurement(Pose2d visionPose, double timestamp) {}

Expand All @@ -28,14 +27,13 @@ public record VisionMeasurement(Pose2d visionPose, double timestamp) {}
private Pose2d odometryPose = new Pose2d(); // motion sensors
private Pose2d estimatedPose = new Pose2d(); // odometry + vision

private SwerveDriveWheelPositions lastWheelPositions =
new SwerveDriveWheelPositions(
new SwerveModulePosition[] {
new SwerveModulePosition(),
new SwerveModulePosition(),
new SwerveModulePosition(),
new SwerveModulePosition()
});
private SwerveModulePosition[] lastWheelPositions =
new SwerveModulePosition[] {
new SwerveModulePosition(),
new SwerveModulePosition(),
new SwerveModulePosition(),
new SwerveModulePosition()
};
private Rotation2d lastGyroAngle = new Rotation2d();

private static RobotState instance;
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/frc/robot/subsystems/swerve/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
import edu.wpi.first.math.kinematics.SwerveDriveWheelPositions;
import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.kinematics.SwerveModuleState;
import edu.wpi.first.wpilibj.DriverStation;
Expand Down Expand Up @@ -68,11 +67,10 @@ public void periodic() {
}

// pass odometry data to robotstate
SwerveDriveWheelPositions wheelPositions =
new SwerveDriveWheelPositions(
Arrays.stream(modules)
.map(module -> module.getModulePosition())
.toArray(SwerveModulePosition[]::new));
SwerveModulePosition[] wheelPositions =
Arrays.stream(modules)
.map(module -> module.getModulePosition())
.toArray(SwerveModulePosition[]::new);
RobotState.getInstance()
.addOdometryMeasurement(
new RobotState.OdometryMeasurement(
Expand Down

0 comments on commit 88e1905

Please sign in to comment.