WPILibC++ 2023.4.3
|
The linear time-varying differential drive controller has a similar form to the LQR, but the model used to compute the controller gain is the nonlinear model linearized around the drivetrain's current state. More...
#include <frc/controller/LTVDifferentialDriveController.h>
Public Member Functions | |
LTVDifferentialDriveController (const frc::LinearSystem< 2, 2, 2 > &plant, units::meter_t trackwidth, const wpi::array< double, 5 > &Qelems, const wpi::array< double, 2 > &Relems, units::second_t dt) | |
Constructs a linear time-varying differential drive controller. More... | |
LTVDifferentialDriveController (LTVDifferentialDriveController &&)=default | |
Move constructor. More... | |
LTVDifferentialDriveController & | operator= (LTVDifferentialDriveController &&)=default |
Move assignment operator. More... | |
bool | AtReference () const |
Returns true if the pose error is within tolerance of the reference. More... | |
void | SetTolerance (const Pose2d &poseTolerance, units::meters_per_second_t leftVelocityTolerance, units::meters_per_second_t rightVelocityTolerance) |
Sets the pose error which is considered tolerable for use with AtReference(). More... | |
DifferentialDriveWheelVoltages | Calculate (const Pose2d ¤tPose, units::meters_per_second_t leftVelocity, units::meters_per_second_t rightVelocity, const Pose2d &poseRef, units::meters_per_second_t leftVelocityRef, units::meters_per_second_t rightVelocityRef) |
Returns the left and right output voltages of the LTV controller. More... | |
DifferentialDriveWheelVoltages | Calculate (const Pose2d ¤tPose, units::meters_per_second_t leftVelocity, units::meters_per_second_t rightVelocity, const Trajectory::State &desiredState) |
Returns the left and right output voltages of the LTV controller. More... | |
The linear time-varying differential drive controller has a similar form to the LQR, but the model used to compute the controller gain is the nonlinear model linearized around the drivetrain's current state.
We precomputed gains for important places in our state-space, then interpolated between them with a LUT to save computational resources.
See section 8.7 in Controls Engineering in FRC for a derivation of the control law we used shown in theorem 8.7.4.
frc::LTVDifferentialDriveController::LTVDifferentialDriveController | ( | const frc::LinearSystem< 2, 2, 2 > & | plant, |
units::meter_t | trackwidth, | ||
const wpi::array< double, 5 > & | Qelems, | ||
const wpi::array< double, 2 > & | Relems, | ||
units::second_t | dt | ||
) |
Constructs a linear time-varying differential drive controller.
plant | The differential drive velocity plant. |
trackwidth | The distance between the differential drive's left and right wheels. |
Qelems | The maximum desired error tolerance for each state. |
Relems | The maximum desired control effort for each input. |
dt | Discretization timestep. |
std::domain_error | if max velocity of plant with 12 V input <= 0. |
|
default |
Move constructor.
bool frc::LTVDifferentialDriveController::AtReference | ( | ) | const |
Returns true if the pose error is within tolerance of the reference.
DifferentialDriveWheelVoltages frc::LTVDifferentialDriveController::Calculate | ( | const Pose2d & | currentPose, |
units::meters_per_second_t | leftVelocity, | ||
units::meters_per_second_t | rightVelocity, | ||
const Pose2d & | poseRef, | ||
units::meters_per_second_t | leftVelocityRef, | ||
units::meters_per_second_t | rightVelocityRef | ||
) |
Returns the left and right output voltages of the LTV controller.
The reference pose, linear velocity, and angular velocity should come from a drivetrain trajectory.
currentPose | The current pose. |
leftVelocity | The current left velocity. |
rightVelocity | The current right velocity. |
poseRef | The desired pose. |
leftVelocityRef | The desired left velocity. |
rightVelocityRef | The desired right velocity. |
DifferentialDriveWheelVoltages frc::LTVDifferentialDriveController::Calculate | ( | const Pose2d & | currentPose, |
units::meters_per_second_t | leftVelocity, | ||
units::meters_per_second_t | rightVelocity, | ||
const Trajectory::State & | desiredState | ||
) |
Returns the left and right output voltages of the LTV controller.
The reference pose, linear velocity, and angular velocity should come from a drivetrain trajectory.
currentPose | The current pose. |
leftVelocity | The left velocity. |
rightVelocity | The right velocity. |
desiredState | The desired pose, linear velocity, and angular velocity from a trajectory. |
|
default |
Move assignment operator.
void frc::LTVDifferentialDriveController::SetTolerance | ( | const Pose2d & | poseTolerance, |
units::meters_per_second_t | leftVelocityTolerance, | ||
units::meters_per_second_t | rightVelocityTolerance | ||
) |
Sets the pose error which is considered tolerable for use with AtReference().
poseTolerance | Pose error which is tolerable. |
leftVelocityTolerance | Left velocity error which is tolerable. |
rightVelocityTolerance | Right velocity error which is tolerable. |