wpimath functions

wpimath.RK4(*args, **kwargs)

Overloaded function.

  1. RK4(f: collections.abc.Callable[[typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”]], typing.Annotated[numpy.typing.NDArray[numpy.float64], “[m, n]”]], x: typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”], dt: wpimath.units.seconds) -> typing.Annotated[numpy.typing.NDArray[numpy.float64], “[m, n]”]

Performs 4th order Runge-Kutta integration of dx/dt = f(x) for dt.

Parameters:
  • f – The function to integrate. It must take one argument x.

  • x – The initial value of x.

  • dt – The time over which to integrate.

  1. RK4(f: collections.abc.Callable[[typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”], typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”]], typing.Annotated[numpy.typing.NDArray[numpy.float64], “[m, n]”]], x: typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”], u: typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”], dt: wpimath.units.seconds) -> typing.Annotated[numpy.typing.NDArray[numpy.float64], “[m, n]”]

Performs 4th order Runge-Kutta integration of dx/dt = f(x, u) for dt.

Parameters:
  • f – The function to integrate. It must take two arguments x and u.

  • x – The initial value of x.

  • u – The value u held constant over the integration period.

  • dt – The time over which to integrate.

  1. RK4(f: collections.abc.Callable[[wpimath.units.seconds, typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”]], typing.Annotated[numpy.typing.NDArray[numpy.float64], “[m, n]”]], t: wpimath.units.seconds, y: typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”], dt: wpimath.units.seconds) -> typing.Annotated[numpy.typing.NDArray[numpy.float64], “[m, n]”]

Performs 4th order Runge-Kutta integration of dy/dt = f(t, y) for dt.

Parameters:
  • f – The function to integrate. It must take two arguments t and y.

  • t – The initial value of t.

  • y – The initial value of y.

  • dt – The time over which to integrate.

wpimath.RKDP(*args, **kwargs)

Overloaded function.

  1. RKDP(f: collections.abc.Callable[[typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”], typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”]], typing.Annotated[numpy.typing.NDArray[numpy.float64], “[m, n]”]], x: typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”], u: typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”], dt: wpimath.units.seconds, maxError: typing.SupportsFloat | typing.SupportsIndex = 1e-06) -> typing.Annotated[numpy.typing.NDArray[numpy.float64], “[m, n]”]

Performs adaptive Dormand-Prince integration of dx/dt = f(x, u) for dt.

Parameters:
  • f – The function to integrate. It must take two arguments x and u.

  • x – The initial value of x.

  • u – The value u held constant over the integration period.

  • dt – The time over which to integrate.

  • maxError – The maximum acceptable truncation error. Usually a small number like 1e-6.

  1. RKDP(f: collections.abc.Callable[[wpimath.units.seconds, typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”]], typing.Annotated[numpy.typing.NDArray[numpy.float64], “[m, n]”]], t: wpimath.units.seconds, y: typing.Annotated[numpy.typing.ArrayLike, numpy.float64, “[m, n]”], dt: wpimath.units.seconds, maxError: typing.SupportsFloat | typing.SupportsIndex = 1e-06) -> typing.Annotated[numpy.typing.NDArray[numpy.float64], “[m, n]”]

Performs adaptive Dormand-Prince integration of dy/dt = f(t, y) for dt.

Parameters:
  • f – The function to integrate. It must take two arguments t and y.

  • t – The initial value of t.

  • y – The initial value of y.

  • dt – The time over which to integrate.

  • maxError – The maximum acceptable truncation error. Usually a small number like 1e-6.

wpimath.angleModulus(angle: wpimath.units.radians) wpimath.units.radians
wpimath.applyDeadband(value: SupportsFloat | SupportsIndex, deadband: SupportsFloat | SupportsIndex, maxMagnitude: SupportsFloat | SupportsIndex = 1.0) float

Returns 0.0 if the given value is within the specified range around zero. The remaining range between the deadband and the maximum magnitude is scaled from 0.0 to the maximum magnitude.

Parameters:
  • value – Value to clip.

  • deadband – Range around zero.

  • maxMagnitude – The maximum magnitude of the input (defaults to 1). Can be infinite.

Returns:

The value after the deadband is applied.

wpimath.inputModulus(input: SupportsFloat | SupportsIndex, minimumInput: SupportsFloat | SupportsIndex, maximumInput: SupportsFloat | SupportsIndex) float

Returns modulus of input.

Parameters:
  • input – Input value to wrap.

  • minimumInput – The minimum value expected from the input.

  • maximumInput – The maximum value expected from the input.

wpimath.numericalJacobian(f: collections.abc.Callable[[Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]']], Annotated[numpy.typing.NDArray[numpy.float64], '[m, 1]']], x: Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]']) Annotated[numpy.typing.NDArray[numpy.float64], '[m, n]']

Returns numerical Jacobian with respect to x for f(x).

Parameters:
  • f – Vector-valued function from which to compute Jacobian.

  • x – Vector argument.

wpimath.numericalJacobianU(f: collections.abc.Callable[[Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]'], Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]'], *args], Annotated[numpy.typing.NDArray[numpy.float64], '[m, 1]']], x: Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]'], u: Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]'], *args) Annotated[numpy.typing.NDArray[numpy.float64], '[m, n]']

Returns numerical Jacobian with respect to u for f(x, u, …).

@tparam F Function object type. @tparam Args… Types of remaining arguments to f(x, u, …).

Parameters:
  • f – Vector-valued function from which to compute Jacobian.

  • x – State vector.

  • u – Input vector.

  • args – Remaining arguments to f(x, u, …).

wpimath.numericalJacobianX(f: collections.abc.Callable[[Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]'], Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]'], *args], Annotated[numpy.typing.NDArray[numpy.float64], '[m, 1]']], x: Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]'], u: Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]'], *args) Annotated[numpy.typing.NDArray[numpy.float64], '[m, n]']

Returns numerical Jacobian with respect to x for f(x, u, …).

@tparam F Function object type. @tparam Args… Types of remaining arguments to f(x, u, …).

Parameters:
  • f – Vector-valued function from which to compute Jacobian.

  • x – State vector.

  • u – Input vector.

  • args – Remaining arguments to f(x, u, …).

wpimath.objectToRobotPose(objectInField: wpimath._wpimath.Pose3d, cameraToObject: wpimath._wpimath.Transform3d, robotToCamera: wpimath._wpimath.Transform3d) wpimath._wpimath.Pose3d
wpimath.slewRateLimit(*args, **kwargs)

Overloaded function.

  1. slewRateLimit(current: wpimath._wpimath.Translation2d, next: wpimath._wpimath.Translation2d, dt: wpimath.units.seconds, maxVelocity: wpimath.units.meters_per_second) -> wpimath._wpimath.Translation2d

Limits translation velocity.

Parameters:
  • current – Translation at current timestep.

  • next – Translation at next timestep.

  • dt – Timestep duration.

  • maxVelocity – Maximum translation velocity.

Returns:

Returns the next Translation2d limited to maxVelocity

  1. slewRateLimit(current: wpimath._wpimath.Translation3d, next: wpimath._wpimath.Translation3d, dt: wpimath.units.seconds, maxVelocity: wpimath.units.meters_per_second) -> wpimath._wpimath.Translation3d

Limits translation velocity.

Parameters:
  • current – Translation at current timestep.

  • next – Translation at next timestep.

  • dt – Timestep duration.

  • maxVelocity – Maximum translation velocity.

Returns:

Returns the next Translation3d limited to maxVelocity