Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
fixing gyro
Browse files Browse the repository at this point in the history
  • Loading branch information
Rango813 committed Jan 27, 2024
1 parent b6f34bc commit 3747393
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/main/java/frc/robot/subsystems/swerve/Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Optional;
import org.littletonrobotics.junction.AutoLogOutput;
import org.littletonrobotics.junction.Logger;
import com.kauailabs.navx.frc.AHRS;
import com.pathplanner.lib.auto.AutoBuilder;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
Expand All @@ -26,8 +25,7 @@
public class Swerve extends SubsystemBase {
public SwerveDriveOdometry swerveOdometry;
public SwerveModule[] swerveMods;
public AHRS gyro = new AHRS(Constants.Swerve.navXID);
private double fieldOffset = gyro.getYaw();
private double fieldOffset;
private SwerveInputsAutoLogged inputs = new SwerveInputsAutoLogged();
private SwerveIO swerveIO;
private boolean hasInitialized = false;
Expand All @@ -38,6 +36,7 @@ public class Swerve extends SubsystemBase {
public Swerve(SwerveIO swerveIO) {
this.swerveIO = swerveIO;
swerveIO.updateInputs(inputs);
fieldOffset = inputs.yaw;
swerveMods = new SwerveModule[] {
swerveIO.createSwerveModule(0, Constants.Swerve.Mod0.DRIVE_MOTOR_ID,
Constants.Swerve.Mod0.ANGLE_MOTOR_ID, Constants.Swerve.Mod0.CAN_CODER_ID,
Expand Down Expand Up @@ -173,7 +172,7 @@ public Rotation2d getHeading() {
* @return Current rotation/yaw of gyro as {@link Rotation2d}
*/
public Rotation2d getGyroYaw() {
float yaw = gyro.getYaw();
float yaw = inputs.yaw;
return (Constants.Swerve.INVERT_GYRO) ? Rotation2d.fromDegrees(-yaw)
: Rotation2d.fromDegrees(yaw);
}
Expand Down

0 comments on commit 3747393

Please sign in to comment.