16#include "wpi/units/length.hpp"
17#include "wpi/units/time.hpp"
18#include "wpi/units/velocity.hpp"
58 wpi::units::meter_t trackwidth,
61 wpi::units::second_t dt)
62 : m_trackwidth{trackwidth},
84 return std::abs(m_error(0)) < m_tolerance(0) &&
85 std::abs(m_error(1)) < m_tolerance(1) &&
86 std::abs(m_error(2)) < m_tolerance(2) &&
87 std::abs(m_error(3)) < m_tolerance(3) &&
88 std::abs(m_error(4)) < m_tolerance(4);
100 wpi::units::meters_per_second_t leftVelocityTolerance,
101 wpi::units::meters_per_second_t rightVelocityTolerance) {
102 m_tolerance = Eigen::Vector<double, 5>{
103 poseTolerance.
X().value(), poseTolerance.
Y().value(),
105 leftVelocityTolerance.value(), rightVelocityTolerance.value()};
122 const Pose2d& currentPose, wpi::units::meters_per_second_t leftVelocity,
123 wpi::units::meters_per_second_t rightVelocity,
const Pose2d& poseRef,
124 wpi::units::meters_per_second_t leftVelocityRef,
125 wpi::units::meters_per_second_t rightVelocityRef);
140 const Pose2d& currentPose, wpi::units::meters_per_second_t leftVelocity,
141 wpi::units::meters_per_second_t rightVelocity,
155 currentPose, leftVelocity, rightVelocity, desiredState.
pose,
157 (1 - (desiredState.
curvature / 1_rad * m_trackwidth / 2.0)),
159 (1 + (desiredState.
curvature / 1_rad * m_trackwidth / 2.0)));
163 wpi::units::meter_t m_trackwidth;
166 Eigen::Matrix<double, 2, 2> m_A;
167 Eigen::Matrix<double, 2, 2> m_B;
170 Eigen::Matrix<double, 5, 5> m_Q;
171 Eigen::Matrix<double, 2, 2> m_R;
173 wpi::units::second_t m_dt;
175 Eigen::Vector<double, 5> m_error;
176 Eigen::Vector<double, 5> m_tolerance;
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
bool AtReference() const
Returns true if the pose error is within tolerance of the reference.
Definition LTVDifferentialDriveController.hpp:83
DifferentialDriveWheelVoltages Calculate(const Pose2d ¤tPose, wpi::units::meters_per_second_t leftVelocity, wpi::units::meters_per_second_t rightVelocity, const Pose2d &poseRef, wpi::units::meters_per_second_t leftVelocityRef, wpi::units::meters_per_second_t rightVelocityRef)
Returns the left and right output voltages of the LTV controller.
LTVDifferentialDriveController & operator=(LTVDifferentialDriveController &&)=default
Move assignment operator.
LTVDifferentialDriveController(const wpi::math::LinearSystem< 2, 2, 2 > &plant, wpi::units::meter_t trackwidth, const wpi::util::array< double, 5 > &Qelems, const wpi::util::array< double, 2 > &Relems, wpi::units::second_t dt)
Constructs a linear time-varying differential drive controller.
Definition LTVDifferentialDriveController.hpp:57
LTVDifferentialDriveController(LTVDifferentialDriveController &&)=default
Move constructor.
DifferentialDriveWheelVoltages Calculate(const Pose2d ¤tPose, wpi::units::meters_per_second_t leftVelocity, wpi::units::meters_per_second_t rightVelocity, const Trajectory::State &desiredState)
Returns the left and right output voltages of the LTV controller.
Definition LTVDifferentialDriveController.hpp:139
void SetTolerance(const Pose2d &poseTolerance, wpi::units::meters_per_second_t leftVelocityTolerance, wpi::units::meters_per_second_t rightVelocityTolerance)
Sets the pose error which is considered tolerable for use with AtReference().
Definition LTVDifferentialDriveController.hpp:99
A plant defined using state-space notation.
Definition LinearSystem.hpp:35
Represents a 2D pose containing translational and rotational elements.
Definition Pose2d.hpp:27
constexpr wpi::units::meter_t X() const
Returns the X component of the pose's translation.
Definition Pose2d.hpp:114
constexpr const Rotation2d & Rotation() const
Returns the underlying rotation.
Definition Pose2d.hpp:128
constexpr wpi::units::meter_t Y() const
Returns the Y component of the pose's translation.
Definition Pose2d.hpp:121
constexpr wpi::units::radian_t Radians() const
Returns the radian value of the rotation constrained within [-π, π].
Definition Rotation2d.hpp:219
This class is a wrapper around std::array that does compile time size checking.
Definition array.hpp:26
Definition LinearSystem.hpp:20
constexpr Eigen::Matrix< double, sizeof...(Ts), sizeof...(Ts)> CostMatrix(Ts... tolerances)
Creates a cost matrix from the given vector for use with LQR.
Definition StateSpaceUtil.hpp:34
Definition CvSource.hpp:15
Motor voltages for a differential drive.
Definition DifferentialDriveWheelVoltages.hpp:14
Represents one point on the trajectory.
Definition Trajectory.hpp:33
Pose2d pose
The pose at that point of the trajectory.
Definition Trajectory.hpp:44
wpi::units::meters_per_second_t velocity
The velocity at that point of the trajectory.
Definition Trajectory.hpp:38
wpi::units::curvature_t curvature
The curvature at that point of the trajectory.
Definition Trajectory.hpp:47