-
Notifications
You must be signed in to change notification settings - Fork 0
feat(hardware/gyro): implement gyroscopes #9
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
Open
Baconing
wants to merge
40
commits into
master
Choose a base branch
from
v2025-1-0-0/gyros
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 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 a699ec7
feat(hardware/gyro/imu): implement ADIS16448IMU and ADIS16470IMU
Baconing f2445de
refactor(hardware/gyro/imu): remove NotNull annotations from abstract…
Baconing 1b9402f
refactor(hardware/gyro/imu): use Translation3d instead of Rotation3d …
Baconing 045bb2c
refactor(hardware/gyro/imu): use radians instead of degrees
Baconing d180bee
feat/refactor(hardware/gyro/imu/adis16*): finish implementations
Baconing 4f91bc7
style(hardware/gyro/imu/adis16470): remove unused import
Baconing a49c171
chore(build.gradle): add wpiunits dependency
Baconing 2e5b57d
refactor(hardware/gyro/imu/adis16470): use unqualified name instead o…
Baconing 3881104
refactor(hardware/gyro/imu): put unit in method name for IMU.getRotat…
Baconing e26558e
feat(hardware/gyro/imu): add getAngleRadians(SingleAxisGyroscope.Axis…
Baconing 2b1123a
Merge branch 'master' into v2025-1-0-0/gyros
Baconing a95c639
refactor(hardware/imu/adis16448): use unqualified name instead of FQD…
Baconing a39601e
Merge remote-tracking branch 'origin/v2025-1-0-0/gyros' into v2025-1-…
Baconing 77d2f72
Merge branch 'master' into v2025-1-0-0/gyros
Baconing fe3c8b6
Merge branch 'master' into v2025-1-0-0/gyros
Baconing 6556a2a
Merge branch 'master' into v2025-1-0-0/gyros
Baconing 8dd30a7
Merge branch 'master' into v2025-1-0-0/gyros
Baconing 935a74f
Merge branch 'master' into v2025-1-0-0/gyros
Baconing 426ea9c
Merge branch 'master' into v2025-1-0-0/gyros
Baconing d4743f9
Merge branch 'master' into v2025-1-0-0/gyros
Baconing 0837d8d
Merge branch 'master' into v2025-1-0-0/gyros
Baconing 73d6fd0
Merge branch 'master' into v2025-1-0-0/gyros
Baconing f48f6c7
Merge branch 'master' into v2025-1-0-0/gyros
Baconing 648adab
feat/fix(hardware/gyro/imu/adis16*): implement getAngleRadians(Single…
Baconing 28dfa6c
feat(hardware/gyro/imu): finish implementation of IMU and it's subcla…
Baconing 5722c6b
refactor(hardware/gyro/imu): move yaw pitch roll axis assignment to a…
Baconing 213fecf
refactor(hardware/gyro): remove SingleAxisGyroscope, just use IMU.
Baconing 898776e
feat(hardware/gyro): implement KauaiLabs NavX
Baconing 64eb036
docs(hardware/gyro/adis16*): update documentation to reflect changes
Baconing 9ba4834
style(hardware/gyro/imu): remove unnecessary qualifiers in IMU.Cartes…
Baconing 7108bbc
refactor(hardware/gyro): clean up some of the long methods
Baconing 336dd89
Merge branch 'master' into v2025-1-0-0/gyros
Baconing fa12c52
refactor(hardware/gyro/imu): only use Rotation3d where absolutely nec…
Baconing 9669e48
test(hardware/gyro): implement tests for ADIS16448, ADIS16470, and de…
Baconing ed1a44c
fix(hardware/gyro): implement getRate() function
Baconing 4e72ffa
fix(hardware/gyro): (re)implement angle rate logic
Baconing 7ae15eb
test(hardware/gyro): finish implementing unit tests for all implement…
Baconing e6b51db
fix(hardware/gyro/navx): use Gs not m/ss
Baconing 2de1188
docs(hardware/gyro): annotate deprecated members
Baconing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
src/main/java/net/frc5183/librobot/hardware/gyro/SingleAxisGyroscope.java
This file was deleted.
Oops, something went wrong.
122 changes: 122 additions & 0 deletions
122
src/main/java/net/frc5183/librobot/hardware/gyro/imu/ADIS16448IMU.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| package net.frc5183.librobot.hardware.gyro.imu; | ||
|
|
||
| import edu.wpi.first.math.geometry.Rotation3d; | ||
| import edu.wpi.first.wpilibj.ADIS16448_IMU; | ||
| import edu.wpi.first.wpilibj.SPI; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.util.Optional; | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Represents an ADIS16448 {@link IMU}. | ||
| */ | ||
| public class ADIS16448IMU extends IMU { | ||
| /** | ||
| * The ADIS16448 IMU. | ||
| */ | ||
| @NotNull | ||
| private final ADIS16448_IMU imu; | ||
|
|
||
| /** | ||
| * The YAW axis. | ||
| */ | ||
| private final IMUAxis yaw; | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * The PITCH axis. | ||
| */ | ||
| private final IMUAxis pitch; | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * The ROLL axis. | ||
| */ | ||
| private final IMUAxis roll; | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * 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() { | ||
| yaw = IMUAxis.Z; | ||
| imu = 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) { | ||
| 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(IMUAxis yaw) { | ||
| this.yaw = yaw; | ||
| imu = new ADIS16448_IMU(fromIMUAxis(yaw), SPI.Port.kMXP, ADIS16448_IMU.CalibrationTime._512ms); | ||
| } | ||
|
|
||
| /** | ||
| * 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(IMUAxis yaw, SPI.Port port) { | ||
| this.yaw = yaw; | ||
| imu = new ADIS16448_IMU(fromIMUAxis(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(IMUAxis yaw, SPI.Port port, ADIS16448_IMU.CalibrationTime calibrationTime) { | ||
| this.yaw = yaw; | ||
| imu = new ADIS16448_IMU(fromIMUAxis(yaw), port, calibrationTime); | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull Rotation3d getRawRotation3dDegrees() { | ||
| return new Rotation3d(imu.getGyroAngleX(), imu.getGyroAngleY(), imu.getGyroAngleZ()); | ||
| } | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public @NotNull Rotation3d getAccelerationMetersPerSecondSquared() { | ||
| return new Rotation3d(imu.getAccelX(), imu.getAccelY(), imu.getAccelZ()); | ||
| } | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @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; | ||
| }; | ||
| } | ||
| } | ||
111 changes: 111 additions & 0 deletions
111
src/main/java/net/frc5183/librobot/hardware/gyro/imu/ADIS16470IMU.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package net.frc5183.librobot.hardware.gyro.imu; | ||
|
|
||
| import edu.wpi.first.math.geometry.Rotation3d; | ||
| import edu.wpi.first.wpilibj.ADIS16448_IMU; | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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; | ||
|
|
||
| /** | ||
| * 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() { | ||
| imu = 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; | ||
| } | ||
|
|
||
| /** | ||
| * 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) { | ||
| imu = new ADIS16470_IMU(fromIMUAxis(yaw), fromIMUAxis(pitch), fromIMUAxis(roll)); | ||
| } | ||
|
|
||
| /** | ||
| * 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) { | ||
| imu = new ADIS16470_IMU(fromIMUAxis(yaw), fromIMUAxis(pitch), fromIMUAxis(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); | ||
| } | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public @NotNull Rotation3d getRawRotation3dDegrees() { | ||
| return new Rotation3d( | ||
| imu.getAngle(fromIMUAxis(IMUAxis.X)), | ||
| imu.getAngle(fromIMUAxis(IMUAxis.Y)), | ||
| imu.getAngle(fromIMUAxis(IMUAxis.Z)) | ||
| ); | ||
| } | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public @NotNull Rotation3d getAccelerationMetersPerSecondSquared() { | ||
| return new Rotation3d(imu.getAccelX(), imu.getAccelY(), imu.getAccelZ()); | ||
| } | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @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; | ||
| }; | ||
| } | ||
| } | ||
82 changes: 82 additions & 0 deletions
82
src/main/java/net/frc5183/librobot/hardware/gyro/imu/IMU.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package net.frc5183.librobot.hardware.gyro.imu; | ||
|
|
||
| import edu.wpi.first.math.geometry.Rotation3d; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| /** | ||
| * Represents an IMU (Inertial Measurement Unit). | ||
| */ | ||
| public abstract class IMU { | ||
| /** | ||
| * The offset to be added to the gyroscope. | ||
| */ | ||
| private Rotation3d offset = new Rotation3d(0, 0, 0); | ||
|
|
||
| /** | ||
| * Gets the rotation of the gyroscope (with offset) in degrees. | ||
| * @return {@link Rotation3d} of the rotation of the gyroscope (with offset) in degrees. | ||
| */ | ||
| @NotNull | ||
| public Rotation3d getRotation3dDegrees() { | ||
| return getRawRotation3dDegrees().plus(getOffset()); | ||
| } | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Gets the rotation of the gyroscope (without offset) in degrees. | ||
| * @return {@link Rotation3d} of the rotation of the gyroscope (without offset) in degrees. | ||
| */ | ||
| @NotNull | ||
| public abstract Rotation3d getRawRotation3dDegrees(); | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Gets the acceleration from the IMU in meters per second squared. | ||
| * @return {@link Rotation3d} of the acceleration from the IMU in meters per second squared. | ||
| */ | ||
| @NotNull | ||
| public abstract Rotation3d getAccelerationMetersPerSecondSquared(); | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Sets the offset of the gyroscope. | ||
| * @param offset the offset of the gyroscope. | ||
| */ | ||
| public void setOffset(@NotNull Rotation3d offset) { | ||
| this.offset = offset; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the offset of the gyroscope. | ||
| * @return {@link Rotation3d} the offset of the gyroscope. | ||
| */ | ||
| @NotNull | ||
| public Rotation3d getOffset() { | ||
| return offset; | ||
| } | ||
|
|
||
| /** | ||
| * Calibrates the gyroscope. | ||
| */ | ||
| public abstract void calibrate(); | ||
|
|
||
| /** | ||
| * Resets the gyroscope. | ||
| */ | ||
| public abstract void reset(); | ||
|
|
||
| /** | ||
| * Returns the raw gyroscope object. | ||
| * Should only be used when you know the subclass of the gyroscope. | ||
| * <br><br> | ||
| * Implementations should override the return type to the type of the gyroscope used in the vendor's API. | ||
| * (e.g the {@link ADIS16448IMU} would return {@link edu.wpi.first.wpilibj.ADIS16448_IMU}) | ||
| * @return the raw gyroscope object. | ||
| */ | ||
| @NotNull | ||
| public abstract Object getRawIMU(); | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Represents the three axes of a gyroscope. | ||
| */ | ||
| public enum IMUAxis { | ||
| X, Y, Z | ||
| } | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
src/main/java/net/frc5183/librobot/hardware/gyro/single/SingleAxisGyroscope.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package net.frc5183.librobot.hardware.gyro.single; | ||
|
|
||
| import edu.wpi.first.math.geometry.Rotation2d; | ||
|
|
||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public abstract class SingleAxisGyroscope { | ||
| // todo | ||
Baconing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public enum Axis { | ||
| YAW, PITCH, ROLL | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.