DifferentialDrivetrainSim
- class wpilib.simulation.DifferentialDrivetrainSim(*args, **kwargs)
Bases:
pybind11_object
Overloaded function.
__init__(self: wpilib.simulation._simulation.DifferentialDrivetrainSim, plant: wpimath._controls._controls.system.LinearSystem_2_2_2, trackWidth: wpimath.units.meters, driveMotor: wpimath._controls._controls.plant.DCMotor, gearingRatio: float, wheelRadius: wpimath.units.meters, measurementStdDevs: Annotated[list[float], 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 LinearSystem representing the robot’s drivetrain. This system can be created with LinearSystemId::DrivetrainVelocitySystem() or LinearSystemId::IdentifyDrivetrainSystem().
trackWidth – The robot’s track width.
driveMotor – A 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.
__init__(self: wpilib.simulation._simulation.DifferentialDrivetrainSim, driveMotor: wpimath._controls._controls.plant.DCMotor, gearing: float, J: wpimath.units.kilogram_square_meters, mass: wpimath.units.kilograms, wheelRadius: wpimath.units.meters, trackWidth: wpimath.units.meters, measurementStdDevs: Annotated[list[float], 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 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 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 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
- k10p71 = 10.71
- k12p75 = 12.75
- k5p95 = 5.95
- k7p31 = 7.31
- k8p45 = 8.45
- class KitbotMotor
Bases:
pybind11_object
Represents common motor layouts of the kit drivetrain.
- DualCIMPerSide = <wpimath._controls._controls.plant.DCMotor object>
- DualFalcon500PerSide = <wpimath._controls._controls.plant.DCMotor object>
- DualMiniCIMPerSide = <wpimath._controls._controls.plant.DCMotor object>
- DualNEOPerSide = <wpimath._controls._controls.plant.DCMotor object>
- SingleCIMPerSide = <wpimath._controls._controls.plant.DCMotor object>
- SingleFalcon500PerSide = <wpimath._controls._controls.plant.DCMotor object>
- SingleMiniCIMPerSide = <wpimath._controls._controls.plant.DCMotor object>
- SingleNEOPerSide = <wpimath._controls._controls.plant.DCMotor object>
- class KitbotWheelSize
Bases:
pybind11_object
Represents common wheel sizes of the kit drivetrain.
- kEightInch = 0.2032
- kSixInch = 0.1524
- kTenInch = 0.254
- class State
Bases:
pybind11_object
- kHeading = 2
- kLeftPosition = 5
- kLeftVelocity = 3
- kRightPosition = 6
- kRightVelocity = 4
- kX = 0
- kY = 1
- clampInput(u: numpy.ndarray[numpy.float64[2, 1]]) numpy.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.
createKitbotSim(motor: wpimath._controls._controls.plant.DCMotor, gearing: float, wheelSize: wpimath.units.meters, measurementStdDevs: Annotated[list[float], 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.
createKitbotSim(motor: wpimath._controls._controls.plant.DCMotor, gearing: float, wheelSize: wpimath.units.meters, J: wpimath.units.kilogram_square_meters, measurementStdDevs: Annotated[list[float], 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: numpy.ndarray[numpy.float64[7, 1]], u: numpy.ndarray[numpy.float64[2, 1]]) numpy.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.geometry._geometry.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.geometry._geometry.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: float) 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.geometry._geometry.Pose2d) None
Sets the system pose.
- Parameters:
pose – The pose.
- setState(state: numpy.ndarray[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(units::second_t) call.