Class DifferentialDrivetrainSim

java.lang.Object
edu.wpi.first.wpilibj.simulation.DifferentialDrivetrainSim

public class DifferentialDrivetrainSim
extends Object
This class simulates the state of the drivetrain. In simulationPeriodic, users should first set inputs from motors with setInputs(double, double), call update(double) to update the simulation, and set estimated encoder and gyro positions, as well as estimated odometry pose. Teams can use Field2d to visualize their robot on the Sim GUI's field.

Our state-space system is:

x = [[x, y, theta, vel_l, vel_r, dist_l, dist_r]]ᵀ in the field coordinate system (dist_* are wheel distances.)

u = [[voltage_l, voltage_r]]ᵀ This is typically the control input of the last timestep from a LTVDiffDriveController.

y = x

  • Constructor Details

    • DifferentialDrivetrainSim

      public DifferentialDrivetrainSim​(DCMotor driveMotor, double gearing, double jKgMetersSquared, double massKg, double wheelRadiusMeters, double trackWidthMeters, Matrix<N7,​N1> measurementStdDevs)
      Creates a simulated differential drivetrain.
      Parameters:
      driveMotor - A DCMotor representing the left side of the drivetrain.
      gearing - The gearing ratio between motor and wheel, as output over input. This must be the same ratio as the ratio used to identify or create the drivetrainPlant.
      jKgMetersSquared - The moment of inertia of the drivetrain about its center.
      massKg - The mass of the drivebase.
      wheelRadiusMeters - The radius of the wheels on the drivetrain.
      trackWidthMeters - The robot's track width, or distance between left and right wheels.
      measurementStdDevs - Standard deviations for measurements, in the form [x, y, heading, left velocity, right velocity, left distance, right distance]ᵀ. Can be null if no noise is desired. Gyro standard deviations of 0.0001 radians, velocity standard deviations of 0.05 m/s, and position measurement standard deviations of 0.005 meters are a reasonable starting point.
    • DifferentialDrivetrainSim

      public DifferentialDrivetrainSim​(LinearSystem<N2,​N2,​N2> plant, DCMotor driveMotor, double gearing, double trackWidthMeters, double wheelRadiusMeters, Matrix<N7,​N1> measurementStdDevs)
      Creates a simulated differential drivetrain.
      Parameters:
      plant - The LinearSystem representing the robot's drivetrain. This system can be created with LinearSystemId.createDrivetrainVelocitySystem(DCMotor, double, double, double, double, double) or LinearSystemId.identifyDrivetrainSystem(double, double, double, double).
      driveMotor - A DCMotor representing the drivetrain.
      gearing - The gearingRatio ratio of the robot, as output over input. This must be the same ratio as the ratio used to identify or create the drivetrainPlant.
      trackWidthMeters - The distance between the two sides of the drivetrian. Can be found with SysId.
      wheelRadiusMeters - The radius of the wheels on the drivetrain, in meters.
      measurementStdDevs - Standard deviations for measurements, in the form [x, y, heading, left velocity, right velocity, left distance, right distance]ᵀ. Can be null if no noise is desired. Gyro standard deviations of 0.0001 radians, velocity standard deviations of 0.05 m/s, and position measurement standard deviations of 0.005 meters are a reasonable starting point.
  • Method Details