LTVUnicycleController

class wpimath.controller.LTVUnicycleController(*args, **kwargs)

Bases: pybind11_object

The linear time-varying unicycle controller has a similar form to the LQR, but the model used to compute the controller gain is the nonlinear unicycle model linearized around the drivetrain’s current state.

This controller is a roughly drop-in replacement for RamseteController with more optimal feedback gains in the “least-squares error” sense.

See section 8.9 in Controls Engineering in FRC for a derivation of the control law we used shown in theorem 8.9.1.

Overloaded function.

  1. __init__(self: wpimath._controls._controls.controller.LTVUnicycleController, dt: wpimath.units.seconds, maxVelocity: wpimath.units.meters_per_second = 9.0) -> None

Constructs a linear time-varying unicycle controller with default maximum desired error tolerances of (0.0625 m, 0.125 m, 2 rad) and default maximum desired control effort of (1 m/s, 2 rad/s).

Parameters:
  • dt – Discretization timestep.

  • maxVelocity – The maximum velocity for the controller gain lookup table. @throws std::domain_error if maxVelocity <= 0.

  1. __init__(self: wpimath._controls._controls.controller.LTVUnicycleController, Qelems: Tuple[float, float, float], Relems: Tuple[float, float], dt: wpimath.units.seconds, maxVelocity: wpimath.units.meters_per_second = 9.0) -> None

Constructs a linear time-varying unicycle controller.

See https://docs.wpilib.org/en/stable/docs/software/advanced-controls/state-space/state-space-intro.html#lqr-tuning for how to select the tolerances.

Parameters:
  • Qelems – The maximum desired error tolerance for each state.

  • Relems – The maximum desired control effort for each input.

  • dt – Discretization timestep.

  • maxVelocity – The maximum velocity for the controller gain lookup table. @throws std::domain_error if maxVelocity <= 0 m/s or >= 15 m/s.

atReference() bool

Returns true if the pose error is within tolerance of the reference.

calculate(*args, **kwargs)

Overloaded function.

  1. calculate(self: wpimath._controls._controls.controller.LTVUnicycleController, currentPose: wpimath.geometry._geometry.Pose2d, poseRef: wpimath.geometry._geometry.Pose2d, linearVelocityRef: wpimath.units.meters_per_second, angularVelocityRef: wpimath.units.radians_per_second) -> wpimath.kinematics._kinematics.ChassisSpeeds

Returns the linear and angular velocity outputs of the LTV controller.

The reference pose, linear velocity, and angular velocity should come from a drivetrain trajectory.

Parameters:
  • currentPose – The current pose.

  • poseRef – The desired pose.

  • linearVelocityRef – The desired linear velocity.

  • angularVelocityRef – The desired angular velocity.

  1. calculate(self: wpimath._controls._controls.controller.LTVUnicycleController, currentPose: wpimath.geometry._geometry.Pose2d, desiredState: wpimath._controls._controls.trajectory.Trajectory.State) -> wpimath.kinematics._kinematics.ChassisSpeeds

Returns the linear and angular velocity outputs of the LTV controller.

The reference pose, linear velocity, and angular velocity should come from a drivetrain trajectory.

Parameters:
  • currentPose – The current pose.

  • desiredState – The desired pose, linear velocity, and angular velocity from a trajectory.

setEnabled(enabled: bool) None

Enables and disables the controller for troubleshooting purposes.

Parameters:

enabled – If the controller is enabled or not.

setTolerance(poseTolerance: wpimath.geometry._geometry.Pose2d) None

Sets the pose error which is considered tolerable for use with AtReference().

Parameters:

poseTolerance – Pose error which is tolerable.