Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 committed Jun 3, 2024
1 parent 660ae72 commit 17a95d4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 51 deletions.
56 changes: 30 additions & 26 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java
Original file line number Diff line number Diff line change
Expand Up @@ -1159,25 +1159,27 @@ public synchronized double getAngle(IMUAxis axis) {
* @return The Yaw axis angle in degrees (CCW positive).
*/
public synchronized double getAngle() {
switch (m_yaw_axis) {
case kX:
return switch (m_yaw_axis) {
case kX -> {
if (m_simGyroAngleX != null) {
return m_simGyroAngleX.get();
yield m_simGyroAngleX.get();
}
return m_integ_angle_x;
case kY:
yield m_integ_angle_x;
}
case kY -> {
if (m_simGyroAngleY != null) {
return m_simGyroAngleY.get();
yield m_simGyroAngleY.get();
}
return m_integ_angle_y;
case kZ:
yield m_integ_angle_y;
}
case kZ -> {
if (m_simGyroAngleZ != null) {
return m_simGyroAngleZ.get();
yield m_simGyroAngleZ.get();
}
return m_integ_angle_z;
default:
}
return 0.0;
yield m_integ_angle_z;
}
default -> 0.0;
};
}

/**
Expand Down Expand Up @@ -1224,25 +1226,27 @@ public synchronized double getRate(IMUAxis axis) {
* @return Yaw axis angular rate in degrees per second (CCW positive).
*/
public synchronized double getRate() {
switch (m_yaw_axis) {
case kX:
return switch (m_yaw_axis) {
case kX -> {
if (m_simGyroRateX != null) {
return m_simGyroRateX.get();
yield m_simGyroRateX.get();
}
return m_gyro_rate_x;
case kY:
yield m_gyro_rate_x;
}
case kY -> {
if (m_simGyroRateY != null) {
return m_simGyroRateY.get();
yield m_simGyroRateY.get();
}
return m_gyro_rate_y;
case kZ:
yield m_gyro_rate_y;
}
case kZ -> {
if (m_simGyroRateZ != null) {
return m_simGyroRateZ.get();
yield m_simGyroRateZ.get();
}
return m_gyro_rate_z;
default:
}
return 0.0;
yield m_gyro_rate_z;
}
default -> 0.0;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,10 @@ void testAngleBasedOnYawAxis(
sim.setGyroAngleZ(4.13);

switch (yawAxis) {
case kX:
assertEquals(imu.getAngle(), imu.getGyroAngleX());
break;
case kY:
assertEquals(imu.getAngle(), imu.getGyroAngleY());
break;
case kZ:
assertEquals(imu.getAngle(), imu.getGyroAngleZ());
break;
default:
fail("invalid YawAxis!");
break;
case kX -> assertEquals(imu.getAngle(), imu.getGyroAngleX());
case kY -> assertEquals(imu.getAngle(), imu.getGyroAngleY());
case kZ -> assertEquals(imu.getAngle(), imu.getGyroAngleZ());
default -> fail("invalid YawAxis!");
}
}
}
Expand All @@ -122,18 +114,10 @@ void testRateBasedOnYawAxis(
sim.setGyroRateZ(20.71);

switch (yawAxis) {
case kX:
assertEquals(imu.getRate(), imu.getGyroRateX());
break;
case kY:
assertEquals(imu.getRate(), imu.getGyroRateY());
break;
case kZ:
assertEquals(imu.getRate(), imu.getGyroRateZ());
break;
default:
fail("invalid YawAxis!");
break;
case kX -> assertEquals(imu.getRate(), imu.getGyroRateX());
case kY -> assertEquals(imu.getRate(), imu.getGyroRateY());
case kZ -> assertEquals(imu.getRate(), imu.getGyroRateZ());
default -> fail("invalid YawAxis!");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Debouncer(double debounceTime, DebounceType type) {
resetTimer();

m_baseline =
m_debounceType) {
switch (m_debounceType) {
case kBoth, kRising -> false;
case kFalling -> true;
};
Expand Down

0 comments on commit 17a95d4

Please sign in to comment.