DifferentialDrivetrainSim
- class wpilib.simulation.DifferentialDrivetrainSim(*args, **kwargs)
Bases:
pybind11_objectOverloaded function.
__init__(self: wpilib.simulation._simulation.DifferentialDrivetrainSim, plant: wpimath._wpimath.LinearSystem_2_2_2, trackwidth: wpimath.units.meters, drive_motor: wpimath._wpimath.DCMotor, gearing_ratio: typing.SupportsFloat | typing.SupportsIndex, wheel_radius: wpimath.units.meters, measurement_std_devs: 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.
drive_motor – A wpi::math::DCMotor representing the left side of the drivetrain.
gearing_ratio – 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.
wheel_radius – The radius of the wheels on the drivetrain, in meters.
measurement_std_devs – 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, drive_motor: wpimath._wpimath.DCMotor, gearing: typing.SupportsFloat | typing.SupportsIndex, j: wpimath.units.kilogram_square_meters, mass: wpimath.units.kilograms, wheel_radius: wpimath.units.meters, trackwidth: wpimath.units.meters, measurement_std_devs: 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:
drive_motor – 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.
wheel_radius – The radius of the wheels on the drivetrain.
trackwidth – The robot’s trackwidth, or distance between left and right wheels.
measurement_std_devs – 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_objectRepresents 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_objectRepresents 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_objectRepresents 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
- clamp_input(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 create_kitbot_sim(*args, **kwargs)
Overloaded function.
create_kitbot_sim(motor: wpimath._wpimath.DCMotor, gearing: typing.SupportsFloat | typing.SupportsIndex, wheel_size: wpimath.units.meters, measurement_std_devs: 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.
wheel_size – The wheel size.
measurement_std_devs – 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.
create_kitbot_sim(motor: wpimath._wpimath.DCMotor, gearing: typing.SupportsFloat | typing.SupportsIndex, wheel_size: wpimath.units.meters, j: wpimath.units.kilogram_square_meters, measurement_std_devs: 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.
wheel_size – The wheel size.
j – The moment of inertia of the drivebase. This can be calculated using SysId.
measurement_std_devs – 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.
- get_current_draw() wpimath.units.amperes
Returns the currently drawn current.
- get_gearing() float
Returns the current gearing reduction of the drivetrain, as output over input.
- get_heading() wpimath._wpimath.Rotation2d
Returns the direction the robot is pointing.
Note that this angle is counterclockwise-positive, while most gyros are clockwise positive.
- get_left_current_draw() wpimath.units.amperes
Returns the currently drawn current for the left side.
- get_left_position() wpimath.units.meters
Get the left encoder position in meters.
- Returns:
The encoder position.
- get_left_position_feet() wpimath.units.feet
- get_left_position_inches() wpimath.units.inches
- get_left_velocity() wpimath.units.meters_per_second
Get the left encoder velocity in meters per second.
- Returns:
The encoder velocity.
- get_left_velocity_fps() wpimath.units.feet_per_second
- get_pose() wpimath._wpimath.Pose2d
Returns the current pose.
- get_right_current_draw() wpimath.units.amperes
Returns the currently drawn current for the right side.
- get_right_position() wpimath.units.meters
Get the right encoder position in meters.
- Returns:
The encoder position.
- get_right_position_feet() wpimath.units.feet
- get_right_position_inches() wpimath.units.inches
- get_right_velocity() wpimath.units.meters_per_second
Get the right encoder velocity in meters per second.
- Returns:
The encoder velocity.
- get_right_velocity_fps() wpimath.units.feet_per_second
- get_state(*args, **kwargs)
Overloaded function.
get_state(self: wpilib.simulation._simulation.DifferentialDrivetrainSim) -> typing.Annotated[numpy.typing.NDArray[numpy.float64], “[7, 1]”]
Returns the current state vector x. Note that this will not include noise!
get_state(self: wpilib.simulation._simulation.DifferentialDrivetrainSim, state: typing.SupportsInt | typing.SupportsIndex) -> float
Returns an element of the state vector. Note that this will not include noise!
- Parameters:
state – The row of the state vector.
- set_gearing(new_gearing: SupportsFloat | SupportsIndex) None
Sets the gearing reduction on the drivetrain. This is commonly used for shifting drivetrains.
- Parameters:
new_gearing – The new gear ratio, as output over input.
- set_inputs(left_voltage: wpimath.units.volts, right_voltage: 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:
left_voltage – The left voltage.
right_voltage – The right voltage.
- set_pose(pose: wpimath._wpimath.Pose2d) None
Sets the system pose.
- Parameters:
pose – The pose.
- set_state(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.