mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Clean up Eigen usage
* Replace Matrix<> with Vector<> where vectors are explicitly intended. I found these via `rg "Eigen::Matrix<double, \w+, 1>"`. * Pass all Eigen matrices by const reference. I found these via `rg "\(Eigen"` on main (the initializer list constructors make more false positives). * Replace MakeMatrix() and operator<< usage with initializer list constructors. I found these via `rg MakeMatrix` and `rg "<<"` respectively. * Deprecate MakeMatrix()
This commit is contained in:
committed by
Peter Johnson
parent
72716f51ce
commit
9359431bad
@@ -41,8 +41,8 @@ DifferentialDrivetrainSim::DifferentialDrivetrainSim(
|
||||
driveMotor, mass, wheelRadius, trackWidth / 2.0, J, gearing),
|
||||
trackWidth, driveMotor, gearing, wheelRadius, measurementStdDevs) {}
|
||||
|
||||
Eigen::Matrix<double, 2, 1> DifferentialDrivetrainSim::ClampInput(
|
||||
Eigen::Matrix<double, 2, 1> u) {
|
||||
Eigen::Vector<double, 2> DifferentialDrivetrainSim::ClampInput(
|
||||
const Eigen::Vector<double, 2>& u) {
|
||||
return frc::NormalizeInputVector<2>(u,
|
||||
frc::RobotController::GetInputVoltage());
|
||||
}
|
||||
@@ -66,11 +66,11 @@ double DifferentialDrivetrainSim::GetGearing() const {
|
||||
return m_currentGearing;
|
||||
}
|
||||
|
||||
Eigen::Matrix<double, 7, 1> DifferentialDrivetrainSim::GetOutput() const {
|
||||
Eigen::Vector<double, 7> DifferentialDrivetrainSim::GetOutput() const {
|
||||
return m_y;
|
||||
}
|
||||
|
||||
Eigen::Matrix<double, 7, 1> DifferentialDrivetrainSim::GetState() const {
|
||||
Eigen::Vector<double, 7> DifferentialDrivetrainSim::GetState() const {
|
||||
return m_x;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ units::ampere_t DifferentialDrivetrainSim::GetCurrentDraw() const {
|
||||
}
|
||||
|
||||
void DifferentialDrivetrainSim::SetState(
|
||||
const Eigen::Matrix<double, 7, 1>& state) {
|
||||
const Eigen::Vector<double, 7>& state) {
|
||||
m_x = state;
|
||||
}
|
||||
|
||||
@@ -129,9 +129,8 @@ void DifferentialDrivetrainSim::SetPose(const frc::Pose2d& pose) {
|
||||
m_x(State::kRightPosition) = 0;
|
||||
}
|
||||
|
||||
Eigen::Matrix<double, 7, 1> DifferentialDrivetrainSim::Dynamics(
|
||||
const Eigen::Matrix<double, 7, 1>& x,
|
||||
const Eigen::Matrix<double, 2, 1>& u) {
|
||||
Eigen::Vector<double, 7> DifferentialDrivetrainSim::Dynamics(
|
||||
const Eigen::Vector<double, 7>& x, const Eigen::Vector<double, 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.
|
||||
@@ -150,7 +149,7 @@ Eigen::Matrix<double, 7, 1> DifferentialDrivetrainSim::Dynamics(
|
||||
|
||||
double v = (x(State::kLeftVelocity) + x(State::kRightVelocity)) / 2.0;
|
||||
|
||||
Eigen::Matrix<double, 7, 1> xdot;
|
||||
Eigen::Vector<double, 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