Skip to content

Commit

Permalink
switched to single-thread during simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
catr1xLiu committed Nov 20, 2024
1 parent 44dbc6c commit 7e3ca88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ public void setupPhotonVision()
public void periodic()
{
// When vision is enabled we must manually update odometry in SwerveDrive
if (visionDriveTest)
if (SwerveDriveTelemetry.isSimulation || visionDriveTest)
{
swerveDrive.updateOdometry();
}
if (visionDriveTest)
{
vision.updatePoseEstimation(swerveDrive);
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/swervelib/SwerveDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,16 @@ public SwerveDrive(
SwerveDriveTelemetry.measuredStatesObj = new SwerveModuleState[SwerveDriveTelemetry.moduleCount];
}

setOdometryPeriod(SwerveDriveTelemetry.isSimulation ? 0.01 : 0.02);

// during simulation, call update odometry in main thread since maple-sim is not thread-safe
if (SwerveDriveTelemetry.isSimulation)
{
stopOdometryThread();
}
// otherwise, start the odometry thread
else {
setOdometryPeriod(0.02);
}

checkIfTunerXCompatible();
}
Expand Down

0 comments on commit 7e3ca88

Please sign in to comment.