Class GyroSimulation

java.lang.Object
org.ironmaple.simulation.drivesims.GyroSimulation

public class GyroSimulation extends Object
Simulation for a IMU module used as gyro.

The Simulation is basically an indefinite integral of the angular velocity during each simulation sub ticks. Above that, it also musicales the measurement inaccuracy of the gyro, drifting in no-motion and drifting due to impacts.

  • Constructor Details

    • GyroSimulation

      public GyroSimulation(double AVERAGE_DRIFTING_IN_30_SECS_MOTIONLESS_DEG, double VELOCITY_MEASUREMENT_STANDARD_DEVIATION_PERCENT)

      Creates a Gyro Simulation.

      Parameters:
      AVERAGE_DRIFTING_IN_30_SECS_MOTIONLESS_DEG - the average amount of drift, in degrees, the gyro experiences if it remains motionless for 30 seconds on a vibrating platform. This value can often be found in the user manual.
      VELOCITY_MEASUREMENT_STANDARD_DEVIATION_PERCENT - the standard deviation of the velocity measurement, typically around 0.05
  • Method Details

    • setRotation

      public void setRotation(Rotation2d currentRotation)

      Calibrates the Gyro to a Given Rotation.

      This method sets the current rotation of the gyro, similar to Pigeon2().setYaw() .

      After setting the rotation, the gyro will continue to estimate the rotation by integrating the angular velocity, adding it to the specified rotation.

      Parameters:
      currentRotation - the current rotation of the robot, represented as a Rotation2d
    • getGyroReading

      public Rotation2d getGyroReading()

      Obtains the Estimated Rotation of the Gyro.

      This method returns the estimated rotation of the gyro, which includes measurement errors due to drifting and other factors.

      Returns:
      the current reading of the gyro, represented as a Rotation2d
    • getMeasuredAngularVelocity

      public edu.wpi.first.units.measure.AngularVelocity getMeasuredAngularVelocity()

      Gets the Measured Angular Velocity of the Gyro.

      This method returns the angular velocity measured by the gyro, in radians per second.

      The measurement includes random errors based on the configured settings of the gyro.

      Returns:
      the measured angular velocity
    • getCachedGyroReadings

      public Rotation2d[] getCachedGyroReadings()
      gyro readings for high-frequency odometers.
      Returns:
      the readings of the gyro during the last 5 simulation sub ticks
    • updateSimulationSubTick

      public void updateSimulationSubTick(double actualAngularVelocityRadPerSec)

      Updates the Gyro Simulation for Each Sub-Tick.

      This method updates the gyro simulation and should be called during every sub-tick of the simulation.

      If you are using this class outside of SimulatedArena: make sure to call it 5 times in each robot period (if using default timings), or refer to SimulatedArena.overrideSimulationTimings(Time, int).

      Parameters:
      actualAngularVelocityRadPerSec - the actual angular velocity in radians per second, usually obtained from AbstractPhysicsBody.getAngularVelocity()