2023-02-13 17:21:24 -06:00
|
|
|
package swervelib.imu;
|
2023-02-13 14:37:05 -06:00
|
|
|
|
2023-03-06 20:45:54 -06:00
|
|
|
import edu.wpi.first.math.geometry.Rotation3d;
|
|
|
|
|
import edu.wpi.first.math.geometry.Translation3d;
|
2024-12-17 18:49:55 +00:00
|
|
|
import edu.wpi.first.units.measure.MutAngularVelocity;
|
2023-03-06 20:45:54 -06:00
|
|
|
import java.util.Optional;
|
|
|
|
|
|
2023-02-13 14:37:05 -06:00
|
|
|
/**
|
|
|
|
|
* Swerve IMU abstraction to define a standard interface with a swerve drive.
|
|
|
|
|
*/
|
2025-02-22 06:15:56 +00:00
|
|
|
public abstract class SwerveIMU implements AutoCloseable
|
2023-02-13 14:37:05 -06:00
|
|
|
{
|
|
|
|
|
|
2025-02-22 06:15:56 +00:00
|
|
|
@Override
|
|
|
|
|
public abstract void close();
|
|
|
|
|
|
2023-02-13 14:37:05 -06:00
|
|
|
/**
|
|
|
|
|
* Reset IMU to factory default.
|
|
|
|
|
*/
|
|
|
|
|
public abstract void factoryDefault();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear sticky faults on IMU.
|
|
|
|
|
*/
|
|
|
|
|
public abstract void clearStickyFaults();
|
|
|
|
|
|
|
|
|
|
/**
|
2023-03-08 23:34:33 -06:00
|
|
|
* Set the gyro offset.
|
2023-02-13 14:37:05 -06:00
|
|
|
*
|
2023-03-08 23:34:33 -06:00
|
|
|
* @param offset gyro offset as a {@link Rotation3d}.
|
2023-02-13 14:37:05 -06:00
|
|
|
*/
|
2023-03-08 23:34:33 -06:00
|
|
|
public abstract void setOffset(Rotation3d offset);
|
2023-02-13 14:37:05 -06:00
|
|
|
|
2024-01-22 15:11:18 -06:00
|
|
|
/**
|
|
|
|
|
* Set the gyro to invert its default direction.
|
|
|
|
|
*
|
|
|
|
|
* @param invertIMU gyro direction
|
|
|
|
|
*/
|
|
|
|
|
public abstract void setInverted(boolean invertIMU);
|
|
|
|
|
|
2023-02-13 14:37:05 -06:00
|
|
|
/**
|
2023-03-08 23:34:33 -06:00
|
|
|
* Fetch the {@link Rotation3d} from the IMU without any zeroing. Robot relative.
|
2023-02-13 14:37:05 -06:00
|
|
|
*
|
2023-03-08 23:34:33 -06:00
|
|
|
* @return {@link Rotation3d} from the IMU.
|
2023-02-13 14:37:05 -06:00
|
|
|
*/
|
2023-03-08 23:34:33 -06:00
|
|
|
public abstract Rotation3d getRawRotation3d();
|
2023-02-13 14:37:05 -06:00
|
|
|
|
2023-03-06 20:45:54 -06:00
|
|
|
/**
|
|
|
|
|
* Fetch the {@link Rotation3d} from the IMU. Robot relative.
|
|
|
|
|
*
|
|
|
|
|
* @return {@link Rotation3d} from the IMU.
|
|
|
|
|
*/
|
|
|
|
|
public abstract Rotation3d getRotation3d();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the acceleration [x, y, z] from the IMU in meters per second squared. If acceleration isn't supported returns
|
|
|
|
|
* empty.
|
|
|
|
|
*
|
|
|
|
|
* @return {@link Translation3d} of the acceleration as an {@link Optional}.
|
|
|
|
|
*/
|
|
|
|
|
public abstract Optional<Translation3d> getAccel();
|
|
|
|
|
|
2024-08-24 17:27:03 -05:00
|
|
|
/**
|
2025-01-06 15:44:15 +00:00
|
|
|
* Fetch the rotation rate from the IMU as {@link MutAngularVelocity}
|
2024-08-24 17:40:19 -05:00
|
|
|
*
|
2025-01-06 15:44:15 +00:00
|
|
|
* @return {@link MutAngularVelocity} of the rotation rate.
|
2024-08-24 17:27:03 -05:00
|
|
|
*/
|
2024-12-17 18:49:55 +00:00
|
|
|
public abstract MutAngularVelocity getYawAngularVelocity();
|
2024-08-24 17:27:03 -05:00
|
|
|
|
2023-02-13 14:37:05 -06:00
|
|
|
/**
|
|
|
|
|
* Get the instantiated IMU object.
|
|
|
|
|
*
|
|
|
|
|
* @return IMU object.
|
|
|
|
|
*/
|
|
|
|
|
public abstract Object getIMU();
|
|
|
|
|
}
|