Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
626bfd6
refactor(hardware/gyro): separate IMUs and single axis gyros
Baconing Oct 2, 2024
a699ec7
feat(hardware/gyro/imu): implement ADIS16448IMU and ADIS16470IMU
Baconing Oct 2, 2024
f2445de
refactor(hardware/gyro/imu): remove NotNull annotations from abstract…
Baconing Oct 3, 2024
1b9402f
refactor(hardware/gyro/imu): use Translation3d instead of Rotation3d …
Baconing Oct 3, 2024
045bb2c
refactor(hardware/gyro/imu): use radians instead of degrees
Baconing Oct 3, 2024
d180bee
feat/refactor(hardware/gyro/imu/adis16*): finish implementations
Baconing Oct 3, 2024
4f91bc7
style(hardware/gyro/imu/adis16470): remove unused import
Baconing Oct 3, 2024
a49c171
chore(build.gradle): add wpiunits dependency
Baconing Oct 3, 2024
2e5b57d
refactor(hardware/gyro/imu/adis16470): use unqualified name instead o…
Baconing Oct 3, 2024
3881104
refactor(hardware/gyro/imu): put unit in method name for IMU.getRotat…
Baconing Oct 3, 2024
e26558e
feat(hardware/gyro/imu): add getAngleRadians(SingleAxisGyroscope.Axis…
Baconing Oct 3, 2024
2b1123a
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
a95c639
refactor(hardware/imu/adis16448): use unqualified name instead of FQD…
Baconing Oct 3, 2024
a39601e
Merge remote-tracking branch 'origin/v2025-1-0-0/gyros' into v2025-1-…
Baconing Oct 3, 2024
77d2f72
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
fe3c8b6
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
6556a2a
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
8dd30a7
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
935a74f
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
426ea9c
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
d4743f9
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
0837d8d
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
73d6fd0
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
f48f6c7
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 3, 2024
648adab
feat/fix(hardware/gyro/imu/adis16*): implement getAngleRadians(Single…
Baconing Oct 4, 2024
28dfa6c
feat(hardware/gyro/imu): finish implementation of IMU and it's subcla…
Baconing Oct 7, 2024
5722c6b
refactor(hardware/gyro/imu): move yaw pitch roll axis assignment to a…
Baconing Oct 7, 2024
213fecf
refactor(hardware/gyro): remove SingleAxisGyroscope, just use IMU.
Baconing Oct 7, 2024
898776e
feat(hardware/gyro): implement KauaiLabs NavX
Baconing Oct 7, 2024
64eb036
docs(hardware/gyro/adis16*): update documentation to reflect changes
Baconing Oct 7, 2024
9ba4834
style(hardware/gyro/imu): remove unnecessary qualifiers in IMU.Cartes…
Baconing Oct 7, 2024
7108bbc
refactor(hardware/gyro): clean up some of the long methods
Baconing Oct 7, 2024
336dd89
Merge branch 'master' into v2025-1-0-0/gyros
Baconing Oct 10, 2024
fa12c52
refactor(hardware/gyro/imu): only use Rotation3d where absolutely nec…
Baconing Oct 10, 2024
9669e48
test(hardware/gyro): implement tests for ADIS16448, ADIS16470, and de…
Baconing Oct 14, 2024
ed1a44c
fix(hardware/gyro): implement getRate() function
Baconing Oct 14, 2024
4e72ffa
fix(hardware/gyro): (re)implement angle rate logic
Baconing Oct 14, 2024
7ae15eb
test(hardware/gyro): finish implementing unit tests for all implement…
Baconing Oct 14, 2024
e6b51db
fix(hardware/gyro/navx): use Gs not m/ss
Baconing Oct 14, 2024
2de1188
docs(hardware/gyro): annotate deprecated members
Baconing Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
compileOnly "edu.wpi.first.wpiutil:wpiutil-java:2024.3.2"
compileOnly "edu.wpi.first.wpilibj:commands:2024.3.2"
compileOnly "edu.wpi.first.wpimath:wpimath-java:2024.3.2"
compileOnly "edu.wpi.first.wpiunits:wpiunits-java:2024.3.2"
compileOnly "edu.wpi.first.wpilibNewCommands:wpilibNewCommands-java:2024.3.2"

// PathPlannerLib
Expand Down
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not just remove single axis gyroscopes. They can be useful for tracking rotating parts like arms or grabbers. In addition, you could "get" a single axis gyroscope from IMUs to allow more adaptability.

This file was deleted.

168 changes: 168 additions & 0 deletions src/main/java/net/frc5183/librobot/hardware/gyro/imu/ADIS16448IMU.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package net.frc5183.librobot.hardware.gyro.imu;

import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.geometry.Translation3d;
import edu.wpi.first.wpilibj.ADIS16448_IMU;
import edu.wpi.first.wpilibj.SPI;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

Check warning on line 9 in src/main/java/net/frc5183/librobot/hardware/gyro/imu/ADIS16448IMU.java

View workflow job for this annotation

GitHub Actions / pmd

Unused import 'java.util.Optional'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. If some imports cannot be resolved, for instance because you run PMD with an incomplete auxiliary classpath, some imports may be conservatively marked as used even if they're not to avoid false positives. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.6.0/pmd_rules_java_codestyle.html#unnecessaryimport

/**
* Represents an ADIS16448 {@link IMU}.
*/
public class ADIS16448IMU extends IMU {
/**
* The ADIS16448 IMU.
*/
@NotNull
private final ADIS16448_IMU imu;

/**
* The yaw axis.
*/
@NotNull
private final IMUAxis yaw;

/**
* The pitch axis.
*/
@NotNull
private final IMUAxis pitch;

/**
* The roll axis.
*/
private final IMUAxis roll;

Check warning on line 36 in src/main/java/net/frc5183/librobot/hardware/gyro/imu/ADIS16448IMU.java

View workflow job for this annotation

GitHub Actions / pmd

Avoid unused private fields such as 'roll'.

Detects when a private field is declared and/or assigned a value, but not used. Since PMD 6.50.0 private fields are ignored, if the fields are annotated with any annotation or the enclosing class has any annotation. Annotations often enable a framework (such as dependency injection, mocking or e.g. Lombok) which use the fields by reflection or other means. This usage can't be detected by static code analysis. Previously these frameworks where explicitly allowed by listing their annotations in the property "ignoredAnnotations", but that turned out to be prone of false positive for any not explicitly considered framework. UnusedPrivateField (Priority: 3, Ruleset: Best Practices) https://docs.pmd-code.org/pmd-doc-7.6.0/pmd_rules_java_bestpractices.html#unusedprivatefield

/**
* Creates a new {@link ADIS16448IMU} using the RIO's Onboard MXP port, 500ms calibration time, and Z axis as yaw.
* @see ADIS16448_IMU#ADIS16448_IMU()
*/
public ADIS16448IMU() {
this(new ADIS16448_IMU());
}

/**
* Creates a new {@link ADIS16448IMU} from an existing ADIS16448 IMU instance.
* @param imu the ADIS16448 IMU to use.
*/
public ADIS16448IMU(@NotNull ADIS16448_IMU imu) {
yaw = toIMUAxis(imu.getYawAxis());

//todo: confirm this is correct i had copilot do it
if (yaw == IMUAxis.X) {
pitch = IMUAxis.Y;
roll = IMUAxis.Z;
} else if (yaw == IMUAxis.Y) {
pitch = IMUAxis.X;
roll = IMUAxis.Z;
} else {
pitch = IMUAxis.X;
roll = IMUAxis.Y;
}

this.imu = imu;
}

/**
* Creates a new {@link ADIS16448IMU} with a specified yaw axis.
* Uses default RIO's Onboard MXP port and 512ms calibration time.
* @param yaw the YAW axis.
*/
public ADIS16448IMU(@NotNull IMUAxis yaw) {
this(yaw, SPI.Port.kMXP);
}

/**
* Creates a new {@link ADIS16448IMU} with a specified yaw axis and SPI port.
* Uses default 512ms calibration time.
* @param yaw the YAW axis.
* @param port the SPI port.
*/
public ADIS16448IMU(@NotNull IMUAxis yaw, @NotNull SPI.Port port) {
this(yaw, port, ADIS16448_IMU.CalibrationTime._512ms);
}

/**
* Creates a new {@link ADIS16448IMU} with a specified yaw axis, SPI port, and calibration time.
* @param yaw the YAW axis.
* @param port the SPI port.
* @param calibrationTime the calibration time.
*/
public ADIS16448IMU(@NotNull IMUAxis yaw, @NotNull SPI.Port port, @NotNull ADIS16448_IMU.CalibrationTime calibrationTime) {
this.yaw = yaw;

//todo: confirm this is correct i had copilot do it
if (yaw == IMUAxis.X) {
pitch = IMUAxis.Y;
roll = IMUAxis.Z;
} else if (yaw == IMUAxis.Y) {
pitch = IMUAxis.X;
roll = IMUAxis.Z;
} else {
pitch = IMUAxis.X;
roll = IMUAxis.Y;
}

imu = new ADIS16448_IMU(fromIMUAxis(yaw), port, calibrationTime);
}

@Override
public @NotNull Rotation3d getRawRotation3d() {
return new Rotation3d(
Math.toRadians(imu.getGyroAngleX()),
Math.toRadians(imu.getGyroAngleY()),
Math.toRadians(imu.getGyroAngleZ())
);
}

@Override
public @NotNull Translation3d getAccelerationMetersPerSecondSquared() {
return new Translation3d(imu.getAccelX(), imu.getAccelY(), imu.getAccelZ());
}

@Override
public void calibrate() {
imu.calibrate();
}

@Override
public void reset() {
imu.reset();
}

@Override
public @NotNull ADIS16448_IMU getRawIMU() {
return imu;
}

/**
* Returns a new {@link ADIS16448_IMU.IMUAxis} from an {@link IMUAxis}.
* @param axis the {@link IMUAxis} to convert.
* @return the converted {@link ADIS16448_IMU.IMUAxis}.
*/
@NotNull
public static ADIS16448_IMU.IMUAxis fromIMUAxis(@NotNull IMUAxis axis) {
return switch (axis) {
case X -> ADIS16448_IMU.IMUAxis.kX;
case Y -> ADIS16448_IMU.IMUAxis.kY;
case Z -> ADIS16448_IMU.IMUAxis.kZ;
};
}


/**
* Returns a new {@link IMUAxis} from an {@link ADIS16448_IMU.IMUAxis}.
* @param axis the {@link ADIS16448_IMU.IMUAxis} to convert.
* @return the converted {@link IMUAxis}.
*/
@NotNull
public static IMUAxis toIMUAxis(@NotNull ADIS16448_IMU.IMUAxis axis) {
return switch (axis) {
case kX -> IMUAxis.X;
case kY -> IMUAxis.Y;
case kZ -> IMUAxis.Z;
};
}
}
148 changes: 148 additions & 0 deletions src/main/java/net/frc5183/librobot/hardware/gyro/imu/ADIS16470IMU.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package net.frc5183.librobot.hardware.gyro.imu;

import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.geometry.Translation3d;
import edu.wpi.first.wpilibj.ADIS16470_IMU;
import edu.wpi.first.wpilibj.SPI;
import org.jetbrains.annotations.NotNull;

/**
* Represents an ADIS16470 {@link IMU}.
*/
public class ADIS16470IMU extends IMU {
/**
* The ADIS16470 IMU.
*/
@NotNull
private final ADIS16470_IMU imu;

/**
* The YAW axis.
*/
private final IMUAxis yaw;

Check warning on line 22 in src/main/java/net/frc5183/librobot/hardware/gyro/imu/ADIS16470IMU.java

View workflow job for this annotation

GitHub Actions / pmd

Avoid unused private fields such as 'yaw'.

Detects when a private field is declared and/or assigned a value, but not used. Since PMD 6.50.0 private fields are ignored, if the fields are annotated with any annotation or the enclosing class has any annotation. Annotations often enable a framework (such as dependency injection, mocking or e.g. Lombok) which use the fields by reflection or other means. This usage can't be detected by static code analysis. Previously these frameworks where explicitly allowed by listing their annotations in the property "ignoredAnnotations", but that turned out to be prone of false positive for any not explicitly considered framework. UnusedPrivateField (Priority: 3, Ruleset: Best Practices) https://docs.pmd-code.org/pmd-doc-7.6.0/pmd_rules_java_bestpractices.html#unusedprivatefield

/**
* The PITCH axis.
*/
private final IMUAxis pitch;

Check warning on line 27 in src/main/java/net/frc5183/librobot/hardware/gyro/imu/ADIS16470IMU.java

View workflow job for this annotation

GitHub Actions / pmd

Avoid unused private fields such as 'pitch'.

Detects when a private field is declared and/or assigned a value, but not used. Since PMD 6.50.0 private fields are ignored, if the fields are annotated with any annotation or the enclosing class has any annotation. Annotations often enable a framework (such as dependency injection, mocking or e.g. Lombok) which use the fields by reflection or other means. This usage can't be detected by static code analysis. Previously these frameworks where explicitly allowed by listing their annotations in the property "ignoredAnnotations", but that turned out to be prone of false positive for any not explicitly considered framework. UnusedPrivateField (Priority: 3, Ruleset: Best Practices) https://docs.pmd-code.org/pmd-doc-7.6.0/pmd_rules_java_bestpractices.html#unusedprivatefield

/**
* The ROLL axis.
*/
private final IMUAxis roll;

Check warning on line 32 in src/main/java/net/frc5183/librobot/hardware/gyro/imu/ADIS16470IMU.java

View workflow job for this annotation

GitHub Actions / pmd

Avoid unused private fields such as 'roll'.

Detects when a private field is declared and/or assigned a value, but not used. Since PMD 6.50.0 private fields are ignored, if the fields are annotated with any annotation or the enclosing class has any annotation. Annotations often enable a framework (such as dependency injection, mocking or e.g. Lombok) which use the fields by reflection or other means. This usage can't be detected by static code analysis. Previously these frameworks where explicitly allowed by listing their annotations in the property "ignoredAnnotations", but that turned out to be prone of false positive for any not explicitly considered framework. UnusedPrivateField (Priority: 3, Ruleset: Best Practices) https://docs.pmd-code.org/pmd-doc-7.6.0/pmd_rules_java_bestpractices.html#unusedprivatefield

/**
* Creates a new {@link ADIS16470IMU} using the RIO's Onboard MXP port and 500ms calibration time, and yaw pitch roll as ZXY respectively.
* @see ADIS16470_IMU#ADIS16470_IMU()
*/
public ADIS16470IMU() {
this(new ADIS16470_IMU());
}

/**
* Creates a new {@link ADIS16470IMU} from an existing ADIS16470 IMU instance.
* @param imu the ADIS16470 IMU to use.
*/
public ADIS16470IMU(@NotNull ADIS16470_IMU imu) {
this.imu = imu;

yaw = toIMUAxis(imu.getYawAxis());
pitch = toIMUAxis(imu.getPitchAxis());
roll = toIMUAxis(imu.getRollAxis());
}

/**
* Creates a new {@link ADIS16470IMU} with a specified yaw, pitch, and roll axis.
* Uses default RIO's Onboard MXP port and 500ms calibration time.
* @param yaw the YAW axis.
* @param pitch the PITCH axis.
* @param roll the ROLL axis.
*/
public ADIS16470IMU(IMUAxis yaw, IMUAxis pitch, IMUAxis roll) {
this(yaw, pitch, roll, SPI.Port.kMXP);
}

/**
* Creates a new {@link ADIS16470IMU} with a specified yaw, pitch, roll axis, and SPI port.
* Uses default 4s calibration time.
* @param yaw the YAW axis.
* @param pitch the PITCH axis.
* @param roll the ROLL axis.
* @param port the SPI port.
*/
public ADIS16470IMU(IMUAxis yaw, IMUAxis pitch, IMUAxis roll, SPI.Port port) {
this(yaw, pitch, roll, port, ADIS16470_IMU.CalibrationTime._4s);
}

/**
* Creates a new {@link ADIS16470IMU} with a specified yaw, pitch, roll axis, SPI port, and calibration time.
* @param yaw the YAW axis.
* @param pitch the PITCH axis.
* @param roll the ROLL axis.
* @param port the SPI port.
* @param calibrationTime the calibration time.
*/
public ADIS16470IMU(IMUAxis yaw, IMUAxis pitch, IMUAxis roll, SPI.Port port, ADIS16470_IMU.CalibrationTime calibrationTime) {
imu = new ADIS16470_IMU(fromIMUAxis(yaw), fromIMUAxis(pitch), fromIMUAxis(roll), port, calibrationTime);

this.yaw = yaw;
this.pitch = pitch;
this.roll = roll;
}

@Override
public @NotNull Rotation3d getRawRotation3d() {
return new Rotation3d(
Math.toRadians(imu.getAngle(fromIMUAxis(IMUAxis.X))),
Math.toRadians(imu.getAngle(fromIMUAxis(IMUAxis.Y))),
Math.toRadians(imu.getAngle(fromIMUAxis(IMUAxis.Z)))
);
}

@Override
public @NotNull Translation3d getAccelerationMetersPerSecondSquared() {
return new Translation3d(imu.getAccelX(), imu.getAccelY(), imu.getAccelZ());
}

@Override
public void calibrate() {
imu.calibrate();
}

@Override
public void reset() {
imu.reset();
}

@Override
public @NotNull ADIS16470_IMU getRawIMU() {
return imu;
}

/**
* Returns a new {@link ADIS16470_IMU.IMUAxis} from an {@link IMUAxis}.
* @param axis the {@link IMUAxis} to convert.
* @return the converted {@link ADIS16470_IMU.IMUAxis}.
*/
public static ADIS16470_IMU.IMUAxis fromIMUAxis(IMUAxis axis) {
return switch (axis) {
case X -> ADIS16470_IMU.IMUAxis.kX;
case Y -> ADIS16470_IMU.IMUAxis.kY;
case Z -> ADIS16470_IMU.IMUAxis.kZ;
};
}

/**
* Returns a new {@link IMUAxis} from an {@link ADIS16470_IMU.IMUAxis}.
* @param axis the {@link IMUAxis} to convert.
* @return the converted {@link ADIS16470_IMU.IMUAxis}.
*/
public static IMUAxis toIMUAxis(ADIS16470_IMU.IMUAxis axis) {
return switch (axis) {
case kX -> IMUAxis.X;
case kY -> IMUAxis.Y;
case kZ -> IMUAxis.Z;
default -> throw new IllegalArgumentException("IMU axis must be one of " + axis);
};
}
}
Loading
Loading