WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
frc::LTVUnicycleController Class Reference

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. More...

#include <frc/controller/LTVUnicycleController.h>

Public Member Functions

 LTVUnicycleController (units::second_t dt, units::meters_per_second_t maxVelocity=9_mps)
 Constructs a linear time-varying unicycle controller with default maximum desired error tolerances of (x = 0.0625 m, y = 0.125 m, heading = 2 rad) and default maximum desired control effort of (linear velocity = 1 m/s, angular velocity = 2 rad/s).
 
 LTVUnicycleController (const wpi::array< double, 3 > &Qelems, const wpi::array< double, 2 > &Relems, units::second_t dt, units::meters_per_second_t maxVelocity=9_mps)
 Constructs a linear time-varying unicycle controller.
 
 LTVUnicycleController (LTVUnicycleController &&)=default
 Move constructor.
 
LTVUnicycleControlleroperator= (LTVUnicycleController &&)=default
 Move assignment operator.
 
bool AtReference () const
 Returns true if the pose error is within tolerance of the reference.
 
void SetTolerance (const Pose2d &poseTolerance)
 Sets the pose error which is considered tolerable for use with AtReference().
 
ChassisSpeeds Calculate (const Pose2d &currentPose, const Pose2d &poseRef, units::meters_per_second_t linearVelocityRef, units::radians_per_second_t angularVelocityRef)
 Returns the linear and angular velocity outputs of the LTV controller.
 
ChassisSpeeds Calculate (const Pose2d &currentPose, const Trajectory::State &desiredState)
 Returns the linear and angular velocity outputs of the LTV controller.
 
void SetEnabled (bool enabled)
 Enables and disables the controller for troubleshooting purposes.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ LTVUnicycleController() [1/3]

frc::LTVUnicycleController::LTVUnicycleController ( units::second_t dt,
units::meters_per_second_t maxVelocity = 9_mps )
explicit

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

Parameters
dtDiscretization timestep.
maxVelocityThe maximum velocity for the controller gain lookup table.
Throws:
std::domain_error if maxVelocity <= 0 m/s or >= 15 m/s.

◆ LTVUnicycleController() [2/3]

frc::LTVUnicycleController::LTVUnicycleController ( const wpi::array< double, 3 > & Qelems,
const wpi::array< double, 2 > & Relems,
units::second_t dt,
units::meters_per_second_t maxVelocity = 9_mps )

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
QelemsThe maximum desired error tolerance for each state (x, y, heading).
RelemsThe maximum desired control effort for each input (linear velocity, angular velocity).
dtDiscretization timestep.
maxVelocityThe maximum velocity for the controller gain lookup table.
Throws:
std::domain_error if maxVelocity <= 0 m/s or >= 15 m/s.

◆ LTVUnicycleController() [3/3]

frc::LTVUnicycleController::LTVUnicycleController ( LTVUnicycleController && )
default

Move constructor.

Member Function Documentation

◆ AtReference()

bool frc::LTVUnicycleController::AtReference ( ) const

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

◆ Calculate() [1/2]

ChassisSpeeds frc::LTVUnicycleController::Calculate ( const Pose2d & currentPose,
const Pose2d & poseRef,
units::meters_per_second_t linearVelocityRef,
units::radians_per_second_t angularVelocityRef )

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
currentPoseThe current pose.
poseRefThe desired pose.
linearVelocityRefThe desired linear velocity.
angularVelocityRefThe desired angular velocity.

◆ Calculate() [2/2]

ChassisSpeeds frc::LTVUnicycleController::Calculate ( const Pose2d & currentPose,
const Trajectory::State & desiredState )

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
currentPoseThe current pose.
desiredStateThe desired pose, linear velocity, and angular velocity from a trajectory.

◆ operator=()

LTVUnicycleController & frc::LTVUnicycleController::operator= ( LTVUnicycleController && )
default

Move assignment operator.

◆ SetEnabled()

void frc::LTVUnicycleController::SetEnabled ( bool enabled)

Enables and disables the controller for troubleshooting purposes.

Parameters
enabledIf the controller is enabled or not.

◆ SetTolerance()

void frc::LTVUnicycleController::SetTolerance ( const Pose2d & poseTolerance)

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

Parameters
poseTolerancePose error which is tolerable.

The documentation for this class was generated from the following file: