DifferentialDrivetrainSim

class wpilib.simulation.DifferentialDrivetrainSim(*args, **kwargs)

Bases: pybind11_object

Overloaded function.

  1. __init__(self: wpilib.simulation._simulation.DifferentialDrivetrainSim, plant: wpimath._wpimath.LinearSystem_2_2_2, trackwidth: wpimath.units.meters, driveMotor: wpimath._wpimath.DCMotor, gearingRatio: typing.SupportsFloat | typing.SupportsIndex, wheelRadius: wpimath.units.meters, measurementStdDevs: typing.Annotated[collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], “FixedSize(7)”] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) -> None

Creates a simulated differential drivetrain.

Parameters:
  • plant – The wpi::math::LinearSystem representing the robot’s drivetrain. This system can be created with wpi::math::Models::DifferentialDriveFromPhysicalConstants() or wpi::math::Models::DifferentialDriveFromSysId().

  • trackwidth – The robot’s trackwidth.

  • driveMotor – A wpi::math::DCMotor representing the left side of the drivetrain.

  • gearingRatio – The gearingRatio ratio of the left side, as output over input. This must be the same ratio as the ratio used to identify or create the plant.

  • wheelRadius – 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 omitted 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.

  1. __init__(self: wpilib.simulation._simulation.DifferentialDrivetrainSim, driveMotor: wpimath._wpimath.DCMotor, gearing: typing.SupportsFloat | typing.SupportsIndex, J: wpimath.units.kilogram_square_meters, mass: wpimath.units.kilograms, wheelRadius: wpimath.units.meters, trackwidth: wpimath.units.meters, measurementStdDevs: typing.Annotated[collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], “FixedSize(7)”] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) -> None

Creates a simulated differential drivetrain.

Parameters:
  • driveMotor – A wpi::math::DCMotor representing the left side of the drivetrain.

  • gearing – The gearing on the drive between motor and wheel, as output over input. This must be the same ratio as the ratio used to identify or create the plant.

  • J – The moment of inertia of the drivetrain about its center.

  • mass – The mass of the drivebase.

  • wheelRadius – The radius of the wheels on the drivetrain.

  • trackwidth – The robot’s trackwidth, 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 omitted 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.

class KitbotGearing

Bases: pybind11_object

Represents a gearing option of the Toughbox mini. 12.75:1 – 14:50 and 14:50 10.71:1 – 14:50 and 16:48 8.45:1 – 14:50 and 19:45 7.31:1 – 14:50 and 21:43 5.95:1 – 14:50 and 24:40

RATIO_10P71 = 10.71
RATIO_12P75 = 12.75
RATIO_5P95 = 5.95
RATIO_7P31 = 7.31
RATIO_8P45 = 8.45
class KitbotMotor

Bases: pybind11_object

Represents common motor layouts of the kit drivetrain.

DUAL_CIM_PER_SIDE = <wpimath._wpimath.DCMotor object>
DUAL_FALCON_500_PER_SIDE = <wpimath._wpimath.DCMotor object>
DUAL_MINI_CIM_PER_SIDE = <wpimath._wpimath.DCMotor object>
DUAL_NEO_PER_SIDE = <wpimath._wpimath.DCMotor object>
SINGLE_CIM_PER_SIDE = <wpimath._wpimath.DCMotor object>
SINGLE_FALCON_500_PER_SIDE = <wpimath._wpimath.DCMotor object>
SINGLE_MINI_CIM_PER_SIDE = <wpimath._wpimath.DCMotor object>
SINGLE_NEO_PER_SIDE = <wpimath._wpimath.DCMotor object>
class KitbotWheelSize

Bases: pybind11_object

Represents common wheel sizes of the kit drivetrain.

EIGHT_INCH = 0.2032
SIX_INCH = 0.1524
TEN_INCH = 0.254
class State

Bases: pybind11_object

HEADING = 2
LEFT_POSITION = 5
LEFT_VELOCITY = 3
RIGHT_POSITION = 6
RIGHT_VELOCITY = 4
X = 0
Y = 1
clampInput(u: Annotated[numpy.typing.ArrayLike, numpy.float64, '[2, 1]']) Annotated[numpy.typing.NDArray[numpy.float64], '[2, 1]']

Clamp the input vector such that no element exceeds the battery voltage. If any does, the relative magnitudes of the input will be maintained.

Parameters:

u – The input vector.

Returns:

The normalized input.

static createKitbotSim(*args, **kwargs)

Overloaded function.

  1. createKitbotSim(motor: wpimath._wpimath.DCMotor, gearing: typing.SupportsFloat | typing.SupportsIndex, wheelSize: wpimath.units.meters, measurementStdDevs: typing.Annotated[collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], “FixedSize(7)”] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) -> wpilib.simulation._simulation.DifferentialDrivetrainSim

Create a sim for the standard FRC kitbot.

Parameters:
  • motor – The motors installed in the bot.

  • gearing – The gearing reduction used.

  • wheelSize – The wheel size.

  • measurementStdDevs – Standard deviations for measurements, in the form [x, y, heading, left velocity, right velocity, left distance, right distance]ᵀ. Can be omitted 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.

  1. createKitbotSim(motor: wpimath._wpimath.DCMotor, gearing: typing.SupportsFloat | typing.SupportsIndex, wheelSize: wpimath.units.meters, J: wpimath.units.kilogram_square_meters, measurementStdDevs: typing.Annotated[collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], “FixedSize(7)”] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) -> wpilib.simulation._simulation.DifferentialDrivetrainSim

Create a sim for the standard FRC kitbot.

Parameters:
  • motor – The motors installed in the bot.

  • gearing – The gearing reduction used.

  • wheelSize – The wheel size.

  • J – The moment of inertia of the drivebase. This can be calculated using SysId.

  • measurementStdDevs – Standard deviations for measurements, in the form [x, y, heading, left velocity, right velocity, left distance, right distance]ᵀ. Can be omitted 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.

dynamics(x: Annotated[numpy.typing.ArrayLike, numpy.float64, '[7, 1]'], u: Annotated[numpy.typing.ArrayLike, numpy.float64, '[2, 1]']) Annotated[numpy.typing.NDArray[numpy.float64], '[7, 1]']

The differential drive dynamics function.

Parameters:
  • x – The state.

  • u – The input.

Returns:

The state derivative with respect to time.

getCurrentDraw() wpimath.units.amperes

Returns the currently drawn current.

getGearing() float

Returns the current gearing reduction of the drivetrain, as output over input.

getHeading() wpimath._wpimath.Rotation2d

Returns the direction the robot is pointing.

Note that this angle is counterclockwise-positive, while most gyros are clockwise positive.

getLeftCurrentDraw() wpimath.units.amperes

Returns the currently drawn current for the left side.

getLeftPosition() wpimath.units.meters

Get the left encoder position in meters.

Returns:

The encoder position.

getLeftPositionFeet() wpimath.units.feet
getLeftPositionInches() wpimath.units.inches
getLeftVelocity() wpimath.units.meters_per_second

Get the left encoder velocity in meters per second.

Returns:

The encoder velocity.

getLeftVelocityFps() wpimath.units.feet_per_second
getPose() wpimath._wpimath.Pose2d

Returns the current pose.

getRightCurrentDraw() wpimath.units.amperes

Returns the currently drawn current for the right side.

getRightPosition() wpimath.units.meters

Get the right encoder position in meters.

Returns:

The encoder position.

getRightPositionFeet() wpimath.units.feet
getRightPositionInches() wpimath.units.inches
getRightVelocity() wpimath.units.meters_per_second

Get the right encoder velocity in meters per second.

Returns:

The encoder velocity.

getRightVelocityFps() wpimath.units.feet_per_second
setGearing(newGearing: SupportsFloat | SupportsIndex) None

Sets the gearing reduction on the drivetrain. This is commonly used for shifting drivetrains.

Parameters:

newGearing – The new gear ratio, as output over input.

setInputs(leftVoltage: wpimath.units.volts, rightVoltage: wpimath.units.volts) None

Sets the applied voltage to the drivetrain. Note that positive voltage must make that side of the drivetrain travel forward (+X).

Parameters:
  • leftVoltage – The left voltage.

  • rightVoltage – The right voltage.

setPose(pose: wpimath._wpimath.Pose2d) None

Sets the system pose.

Parameters:

pose – The pose.

setState(state: Annotated[numpy.typing.ArrayLike, numpy.float64, '[7, 1]']) None

Sets the system state.

Parameters:

state – The state.

update(dt: wpimath.units.seconds) None

Updates the simulation.

Parameters:

dt – The time that’s passed since the last Update(wpi::units::second_t) call.