Repository navigation
Feature/canandgyro #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/canandgyro #375
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import edu.wpi.first.math.geometry.Rotation2d; | ||
| import frc.robot.Robot; | ||
| import frc.robot.subsystems.drive.DriveConstants; | ||
|
|
||
| import java.util.function.DoubleSupplier; | ||
|
|
||
|
|
@@ -46,7 +47,7 @@ public default void setOffset(double offset) { | |
|
|
||
| public static GyroIO getIOByMode(DoubleSupplier simRotRate) { | ||
| return switch (Robot.getMode()) { | ||
| case REAL -> new GyroIONavX(); | ||
| case REAL -> new GyroIOCanandgyro(DriveConstants.canandgyroId); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUCH CRAPPY NAME |
||
| case SIM -> new GyroIOSim(simRotRate); | ||
| case REPLAY -> new GyroIO() { | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package frc.robot.sensors.gyro; | ||
|
|
||
| import java.util.Queue; | ||
|
|
||
| import com.reduxrobotics.sensors.canandgyro.Canandgyro; | ||
|
|
||
| import edu.wpi.first.math.geometry.Rotation2d; | ||
| import frc.robot.sensors.odometry.SparkOdometryThread; | ||
|
|
||
| public class GyroIOCanandgyro implements GyroIO { | ||
| private final Canandgyro gyro; | ||
|
|
||
| double offset = 0; | ||
| private final Queue<Double> yawPositionQueue; | ||
| private final Queue<Double> yawTimestampQueue; | ||
| private final Queue<Double> rate; | ||
|
|
||
| double pitchOffset = 0; | ||
| double rollOffset = 0; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they see me rolling on my front lawn, |
||
|
|
||
| public GyroIOCanandgyro(int gyroId) { | ||
| gyro = new Canandgyro(gyroId); | ||
| rate = SparkOdometryThread.getInstance() | ||
| .registerSignal(() -> Math.toRadians(gyro.getAngularVelocityYaw() * 360)); | ||
| yawTimestampQueue = SparkOdometryThread.getInstance().makeTimestampQueue(); | ||
| yawPositionQueue = SparkOdometryThread.getInstance().registerSignal(() -> gyro.getYaw() * 2 * Math.PI); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateInputs(GyroIOInputs inputs) { | ||
|
|
||
| inputs.isConnected = gyro.isConnected(); | ||
| inputs.isCalibrating = gyro.isCalibrating(); | ||
| inputs.angleRadiansRaw = gyro.getYaw() * 2 * Math.PI; | ||
| inputs.angularVelocityDegreesPerSecond = gyro.getAngularVelocityYaw() * 360; | ||
| inputs.angleDegreesRaw = Math.toDegrees(inputs.angleRadiansRaw); | ||
|
|
||
| inputs.roll = new Rotation2d(gyro.getRoll() * 2 * Math.PI - rollOffset); | ||
| inputs.pitch = new Rotation2d(gyro.getPitch() * 2 * Math.PI - pitchOffset); | ||
|
|
||
| inputs.displacementX = 0; | ||
| inputs.displacementY = 0; | ||
| inputs.odometryYawRate = rate.stream().mapToDouble((Double value) -> value).toArray(); | ||
| inputs.odometryYawTimestamps = yawTimestampQueue.stream().mapToDouble((Double value) -> value).toArray(); | ||
| inputs.odometryYawPositions = yawPositionQueue.stream().map((Double value) -> Rotation2d.fromRadians(value)) | ||
| .toArray(Rotation2d[]::new); | ||
|
|
||
| inputs.accelX = gyro.getAccelerationX(); | ||
| inputs.accelY = gyro.getAccelerationY(); | ||
| inputs.accelZ = gyro.getAccelerationZ(); | ||
| yawTimestampQueue.clear(); | ||
| yawPositionQueue.clear(); | ||
| rate.clear(); | ||
| } | ||
|
|
||
| @Override | ||
| public double getActual(GyroIOInputs inputs) { | ||
| return inputs.angleRadiansRaw - offset; | ||
| } | ||
|
|
||
| @Override | ||
| public double getOffset() { | ||
| return offset; | ||
| } | ||
|
|
||
| @Override | ||
| public void setOffset(double offset) { | ||
| this.offset = offset; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,8 @@ public static enum PivotId { | |
| public static final SwerveDriveKinematics kinematics = new SwerveDriveKinematics(frontLeftLocation, | ||
| frontRightLocation, backLeftLocation, backRightLocation); | ||
|
|
||
| public static final int canandgyroId = 17; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 16 17 |
||
|
|
||
| public static final ModuleInfo FL = new ModuleInfo(PivotId.FL, SwitchableCANID.of(1).get(), | ||
| SwitchableCANID.of(2).get(), | ||
| Switchable.of(0).addAlt(RobotTypes.frank25, 2).addAlt(RobotTypes.prime25, 2).get(), 45); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| { | ||
| "fileName": "ReduxLib-2026.1.2.json", | ||
| "name": "ReduxLib", | ||
| "version": "2026.1.2", | ||
| "frcYear": "2026", | ||
| "uuid": "151ecca8-670b-4026-8160-cdd2679ef2bd", | ||
| "mavenUrls": [ | ||
| "https://maven.reduxrobotics.com/" | ||
| ], | ||
| "jsonUrl": "https://frcsdk.reduxrobotics.com/ReduxLib_2026.json", | ||
| "javaDependencies": [ | ||
| { | ||
| "groupId": "com.reduxrobotics.frc", | ||
| "artifactId": "ReduxLib-java", | ||
| "version": "2026.1.2" | ||
| } | ||
| ], | ||
| "jniDependencies": [ | ||
| { | ||
| "groupId": "com.reduxrobotics.frc", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. who even is this redux person. never heard of her |
||
| "artifactId": "ReduxLib-fifo", | ||
| "version": "2026.1.2", | ||
| "isJar": false, | ||
| "skipInvalidPlatforms": true, | ||
| "validPlatforms": [ | ||
| "linuxathena", | ||
| "linuxx86-64", | ||
| "linuxarm64", | ||
| "osxuniversal", | ||
| "windowsx86-64" | ||
| ] | ||
| } | ||
| ], | ||
| "cppDependencies": [ | ||
| { | ||
| "groupId": "com.reduxrobotics.frc", | ||
| "artifactId": "ReduxLib-cpp", | ||
| "version": "2026.1.2", | ||
| "libName": "ReduxLib", | ||
| "headerClassifier": "headers", | ||
| "sourcesClassifier": "sources", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "linuxathena", | ||
| "linuxx86-64", | ||
| "linuxarm64", | ||
| "osxuniversal", | ||
| "windowsx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.reduxrobotics.frc", | ||
| "artifactId": "ReduxLib-fifo", | ||
| "version": "2026.1.2", | ||
| "libName": "reduxfifo", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "linuxathena", | ||
| "linuxx86-64", | ||
| "linuxarm64", | ||
| "osxuniversal", | ||
| "windowsx86-64" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOT ENOUGH SPACING