Skip to content

Commit

Permalink
lol im dumb
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan1522 committed Oct 28, 2024
1 parent f52582a commit bc25888
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ public interface GyroInterface {
public static class GyroInputs {
public boolean isConnected = false;

public Rotation2d yawDegreesRotation2d = new Rotation2d();
public double yawDegrees = 0.0;
public Rotation2d yawDegreesRotation2d = new Rotation2d();
public double yawVelocity = 0.0;
public double pitchDegrees = 0.0;
public double rollDegrees = 0.0;

public Rotation2d[] odometryYawPositions = new Rotation2d[] {};
public double[] accel = new double[] {0, 0, 0};

public Rotation2d[] odometryYawPositions = new Rotation2d[] {};
public double[] odometryYawTimestamps = new double[] {};
}

Expand Down
17 changes: 15 additions & 2 deletions src/main/java/frc/robot/subsystems/swerve/gyroIO/PhysicalGyro.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import frc.robot.extras.util.AllianceFlipper;
import frc.robot.subsystems.swerve.gyroIO.GyroInterface.GyroInputs;
import frc.robot.subsystems.swerve.odometryThread.OdometryThread;
import java.util.Queue;
import java.util.function.Supplier;

public class PhysicalGyro implements GyroInterface {
private final AHRS gyro = new AHRS(SPI.Port.kMXP, (byte) 250);
private final Queue<Angle> yawPositionInput;

public PhysicalGyro() {
OdometryThread.registerInput(getAngle());
yawPositionInput = OdometryThread.registerInput(getAngle());
}

@Override
Expand All @@ -27,12 +29,23 @@ public void updateInputs(GyroInputs inputs) {
inputs.rollDegrees = getRoll().in(Degrees);
inputs.pitchDegrees = getPitch().in(Degrees);
inputs.yawDegrees = getYaw().in(Degrees);

// Handle odometry yaw positions
if (!yawPositionInput.isEmpty()) {
Rotation2d[] odometryYawPositions = new Rotation2d[yawPositionInput.size()];
int index = 0;
for (Angle angle : yawPositionInput) {
odometryYawPositions[index++] = Rotation2d.fromDegrees(angle.in(Degrees));
}
inputs.odometryYawPositions = odometryYawPositions;
yawPositionInput.clear();
}
}

public void zeroHeading() {
gyro.reset();
}

public Supplier<Angle> getAngle() {
return () -> Degrees.of(-gyro.getAngle());
}
Expand Down

This file was deleted.

0 comments on commit bc25888

Please sign in to comment.