mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Add typedefs for common types
This makes complex code significantly easier to read. frc::Vectord<Size> = Eigen::Vector<double, Size> frc::Matrixd<Rows, Cols> = Eigen::Matrix<double, Rows, Cols>
This commit is contained in:
@@ -41,8 +41,7 @@ DifferentialDrivetrainSim::DifferentialDrivetrainSim(
|
||||
driveMotor, mass, wheelRadius, trackWidth / 2.0, J, gearing),
|
||||
trackWidth, driveMotor, gearing, wheelRadius, measurementStdDevs) {}
|
||||
|
||||
Eigen::Vector<double, 2> DifferentialDrivetrainSim::ClampInput(
|
||||
const Eigen::Vector<double, 2>& u) {
|
||||
Vectord<2> DifferentialDrivetrainSim::ClampInput(const Vectord<2>& u) {
|
||||
return frc::DesaturateInputVector<2>(u,
|
||||
frc::RobotController::GetInputVoltage());
|
||||
}
|
||||
@@ -66,11 +65,11 @@ double DifferentialDrivetrainSim::GetGearing() const {
|
||||
return m_currentGearing;
|
||||
}
|
||||
|
||||
Eigen::Vector<double, 7> DifferentialDrivetrainSim::GetOutput() const {
|
||||
Vectord<7> DifferentialDrivetrainSim::GetOutput() const {
|
||||
return m_y;
|
||||
}
|
||||
|
||||
Eigen::Vector<double, 7> DifferentialDrivetrainSim::GetState() const {
|
||||
Vectord<7> DifferentialDrivetrainSim::GetState() const {
|
||||
return m_x;
|
||||
}
|
||||
|
||||
@@ -116,8 +115,7 @@ units::ampere_t DifferentialDrivetrainSim::GetCurrentDraw() const {
|
||||
return GetLeftCurrentDraw() + GetRightCurrentDraw();
|
||||
}
|
||||
|
||||
void DifferentialDrivetrainSim::SetState(
|
||||
const Eigen::Vector<double, 7>& state) {
|
||||
void DifferentialDrivetrainSim::SetState(const Vectord<7>& state) {
|
||||
m_x = state;
|
||||
}
|
||||
|
||||
@@ -129,19 +127,19 @@ void DifferentialDrivetrainSim::SetPose(const frc::Pose2d& pose) {
|
||||
m_x(State::kRightPosition) = 0;
|
||||
}
|
||||
|
||||
Eigen::Vector<double, 7> DifferentialDrivetrainSim::Dynamics(
|
||||
const Eigen::Vector<double, 7>& x, const Eigen::Vector<double, 2>& u) {
|
||||
Vectord<7> DifferentialDrivetrainSim::Dynamics(const Vectord<7>& x,
|
||||
const Vectord<2>& u) {
|
||||
// Because G^2 can be factored out of A, we can divide by the old ratio
|
||||
// squared and multiply by the new ratio squared to get a new drivetrain
|
||||
// model.
|
||||
Eigen::Matrix<double, 4, 2> B;
|
||||
Matrixd<4, 2> B;
|
||||
B.block<2, 2>(0, 0) = m_plant.B() * m_currentGearing * m_currentGearing /
|
||||
m_originalGearing / m_originalGearing;
|
||||
B.block<2, 2>(2, 0).setZero();
|
||||
|
||||
// Because G can be factored out of B, we can divide by the old ratio and
|
||||
// multiply by the new ratio to get a new drivetrain model.
|
||||
Eigen::Matrix<double, 4, 4> A;
|
||||
Matrixd<4, 4> A;
|
||||
A.block<2, 2>(0, 0) = m_plant.A() * m_currentGearing / m_originalGearing;
|
||||
|
||||
A.block<2, 2>(2, 0).setIdentity();
|
||||
@@ -149,7 +147,7 @@ Eigen::Vector<double, 7> DifferentialDrivetrainSim::Dynamics(
|
||||
|
||||
double v = (x(State::kLeftVelocity) + x(State::kRightVelocity)) / 2.0;
|
||||
|
||||
Eigen::Vector<double, 7> xdot;
|
||||
Vectord<7> xdot;
|
||||
xdot(0) = v * std::cos(x(State::kHeading));
|
||||
xdot(1) = v * std::sin(x(State::kHeading));
|
||||
xdot(2) =
|
||||
|
||||
Reference in New Issue
Block a user