Updated IMU

This commit is contained in:
thenetworkgrinch
2023-03-08 23:34:33 -06:00
parent ca03b2122f
commit ec958aecaa
117 changed files with 678 additions and 635 deletions

View File

@@ -17,9 +17,9 @@ public class ADIS16448Swerve extends SwerveIMU
*/
private final ADIS16448_IMU imu;
/**
* Offset for the ADIS16448 yaw reading.
* Offset for the ADIS16448.
*/
private double yawOffset = 0;
private Rotation3d offset = new Rotation3d();
/**
* Construct the ADIS16448 imu and reset default configurations. Publish the gyro to the SmartDashboard.
@@ -37,7 +37,9 @@ public class ADIS16448Swerve extends SwerveIMU
@Override
public void factoryDefault()
{
yawOffset = (imu.getAngle() % 360);
offset = new Rotation3d(
Math.toRadians(imu.getYComplementaryAngle()), Math.toRadians(imu.getXComplementaryAngle()),
Math.toRadians(imu.getAngle()));
}
/**
@@ -50,40 +52,36 @@ public class ADIS16448Swerve extends SwerveIMU
}
/**
* Set the yaw in degrees.
* Set the gyro offset.
*
* @param yaw Yaw angle in degrees.
* @param offset gyro offset as a {@link Rotation3d}.
*/
@Override
public void setYaw(double yaw)
public void setOffset(Rotation3d offset)
{
yawOffset = (yaw % 360) + (imu.getAngle() % 360);
offset = getRotation3d();
}
/**
* Fetch the yaw/pitch/roll from the IMU.
* Fetch the {@link Rotation3d} from the IMU without any zeroing. Robot relative.
*
* @param yprArray Array which will be filled with {yaw, pitch, roll} in degrees.
* @return {@link Rotation3d} from the IMU.
*/
@Override
public void getYawPitchRoll(double[] yprArray)
public Rotation3d getRawRotation3d()
{
yprArray[0] = (imu.getAngle() % 360) - yawOffset;
yprArray[1] = imu.getXComplementaryAngle() % 360;
yprArray[2] = imu.getYComplementaryAngle() % 360;
return new Rotation3d(
Math.toRadians(imu.getYComplementaryAngle()), Math.toRadians(imu.getXComplementaryAngle()),
Math.toRadians(imu.getAngle()));
}
/**
* Fetch the {@link Rotation3d} from the IMU. Robot relative.
*
* @return {@link Rotation3d} from the IMU.
*/
@Override
public Rotation3d getRotation3d()
{
return new Rotation3d(
imu.getYComplementaryAngle(), imu.getXComplementaryAngle(), imu.getAngle())
.minus(new Rotation3d(0, 0, Math.toRadians(yawOffset)));
return getRawRotation3d().minus(offset);
}
/**