Skip to content

Commit

Permalink
Changed status frame timeouts to static variables.
Browse files Browse the repository at this point in the history
Signed-off-by: thenetworkgrinch <thenetworkgrinch@users.noreply.github.com>
  • Loading branch information
thenetworkgrinch committed Feb 7, 2024
1 parent 6ef7229 commit 74fb390
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/swervelib/encoders/CANCoderSwerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CANCoderSwerve extends SwerveAbsoluteEncoder
/**
* Wait time for status frames to show up.
*/
private final double STATUS_TIMEOUT_SECONDS = 0.02;
public static double STATUS_TIMEOUT_SECONDS = 0.02;
/**
* CANCoder with WPILib sendable and support.
*/
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/swervelib/imu/Pigeon2Swerve.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package swervelib.imu;

import com.ctre.phoenix6.StatusCode;
import com.ctre.phoenix6.StatusSignal;
import com.ctre.phoenix6.configs.Pigeon2Configuration;
import com.ctre.phoenix6.configs.Pigeon2Configurator;
Expand All @@ -19,7 +20,7 @@ public class Pigeon2Swerve extends SwerveIMU
/**
* Wait time for status frames to show up.
*/
private final double STATUS_TIMEOUT_SECONDS = 0.02;
public static double STATUS_TIMEOUT_SECONDS = 0.04;
/**
* Pigeon2 IMU device.
*/
Expand Down Expand Up @@ -110,10 +111,26 @@ public Rotation3d getRawRotation3d()
StatusSignal<Double> x = imu.getQuatX();
StatusSignal<Double> y = imu.getQuatY();
StatusSignal<Double> z = imu.getQuatZ();
Rotation3d reading = new Rotation3d(new Quaternion(w.waitForUpdate(STATUS_TIMEOUT_SECONDS).getValue(),
x.waitForUpdate(STATUS_TIMEOUT_SECONDS).getValue(),
y.waitForUpdate(STATUS_TIMEOUT_SECONDS).getValue(),
z.waitForUpdate(STATUS_TIMEOUT_SECONDS).getValue()));
if(w.getStatus() != StatusCode.OK)
{
w = w.waitForUpdate(STATUS_TIMEOUT_SECONDS);
}
if(x.getStatus() != StatusCode.OK)
{
x = x.waitForUpdate(STATUS_TIMEOUT_SECONDS);
}
if(y.getStatus() != StatusCode.OK)
{
y = y.waitForUpdate(STATUS_TIMEOUT_SECONDS);
}
if(z.getStatus() != StatusCode.OK)
{
z = z.waitForUpdate(STATUS_TIMEOUT_SECONDS);
}
Rotation3d reading = new Rotation3d(new Quaternion(w.getValue(),
x.getValue(),
y.getValue(),
z.getValue()));
return invertedIMU ? reading.unaryMinus() : reading;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/swervelib/motors/TalonFXSwerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class TalonFXSwerve extends SwerveMotor
/**
* Wait time for status frames to show up.
*/
private final double STATUS_TIMEOUT_SECONDS = 0.02;
public static double STATUS_TIMEOUT_SECONDS = 0.02;
/**
* TalonFX motor controller.
*/
Expand Down

0 comments on commit 74fb390

Please sign in to comment.