Simulation

YAGSL-Example provides simulation out of the box!

How it works?

YAGSL Simulates the entire robot using the same simulation modules provided by vendors to varying degrees of support. There is an entirely simulated SwerveModule named SwerveModuleSimulation and SwerveIMUSimulation which provide necessary data.

How do I enable it?

Cosine compensation and heading correction should be disabled when running simulation or else the simulation may be uncontrollable!

For simulation to work properly all you have to do is ensure that heading compensation and cosine compensation are disabled like in the example below.

 /**
   * Initialize {@link SwerveDrive} with the directory provided.
   *
   * @param directory Directory of swerve drive config files.
   */
  public SwerveSubsystem(File directory)
  {
    // Configure the Telemetry before creating the SwerveDrive to avoid unnecessary objects being created.
    SwerveDriveTelemetry.verbosity = TelemetryVerbosity.HIGH;
    swerveDrive = new SwerveParser(directory).createSwerveDrive(Constants.MAX_SPEED);
    swerveDrive.setHeadingCorrection(false); // Heading correction should only be used while controlling the robot via angle.
    swerveDrive.setCosineCompensator(false); // Disables cosine compensation for simulations since it causes discrepancies not seen in real life.
  }

Then run simulation like you normally would in wpilib.

For more information checkout WPILib documentaiton on simulation!

Last updated