mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +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
@@ -21,31 +21,29 @@ MecanumDriveWheelSpeeds MecanumDriveKinematics::ToWheelSpeeds(
|
||||
m_previousCoR = centerOfRotation;
|
||||
}
|
||||
|
||||
Eigen::Vector3d chassisSpeedsVector;
|
||||
chassisSpeedsVector << chassisSpeeds.vx.to<double>(),
|
||||
chassisSpeeds.vy.to<double>(), chassisSpeeds.omega.to<double>();
|
||||
Eigen::Vector3d chassisSpeedsVector{chassisSpeeds.vx.to<double>(),
|
||||
chassisSpeeds.vy.to<double>(),
|
||||
chassisSpeeds.omega.to<double>()};
|
||||
|
||||
Eigen::Matrix<double, 4, 1> wheelsMatrix =
|
||||
Eigen::Vector<double, 4> wheelsVector =
|
||||
m_inverseKinematics * chassisSpeedsVector;
|
||||
|
||||
MecanumDriveWheelSpeeds wheelSpeeds;
|
||||
wheelSpeeds.frontLeft = units::meters_per_second_t{wheelsMatrix(0, 0)};
|
||||
wheelSpeeds.frontRight = units::meters_per_second_t{wheelsMatrix(1, 0)};
|
||||
wheelSpeeds.rearLeft = units::meters_per_second_t{wheelsMatrix(2, 0)};
|
||||
wheelSpeeds.rearRight = units::meters_per_second_t{wheelsMatrix(3, 0)};
|
||||
wheelSpeeds.frontLeft = units::meters_per_second_t{wheelsVector(0)};
|
||||
wheelSpeeds.frontRight = units::meters_per_second_t{wheelsVector(1)};
|
||||
wheelSpeeds.rearLeft = units::meters_per_second_t{wheelsVector(2)};
|
||||
wheelSpeeds.rearRight = units::meters_per_second_t{wheelsVector(3)};
|
||||
return wheelSpeeds;
|
||||
}
|
||||
|
||||
ChassisSpeeds MecanumDriveKinematics::ToChassisSpeeds(
|
||||
const MecanumDriveWheelSpeeds& wheelSpeeds) const {
|
||||
Eigen::Matrix<double, 4, 1> wheelSpeedsMatrix;
|
||||
// clang-format off
|
||||
wheelSpeedsMatrix << wheelSpeeds.frontLeft.to<double>(), wheelSpeeds.frontRight.to<double>(),
|
||||
wheelSpeeds.rearLeft.to<double>(), wheelSpeeds.rearRight.to<double>();
|
||||
// clang-format on
|
||||
Eigen::Vector<double, 4> wheelSpeedsVector{
|
||||
wheelSpeeds.frontLeft.to<double>(), wheelSpeeds.frontRight.to<double>(),
|
||||
wheelSpeeds.rearLeft.to<double>(), wheelSpeeds.rearRight.to<double>()};
|
||||
|
||||
Eigen::Vector3d chassisSpeedsVector =
|
||||
m_forwardKinematics.solve(wheelSpeedsMatrix);
|
||||
m_forwardKinematics.solve(wheelSpeedsVector);
|
||||
|
||||
return {units::meters_per_second_t{chassisSpeedsVector(0)}, // NOLINT
|
||||
units::meters_per_second_t{chassisSpeedsVector(1)},
|
||||
@@ -56,10 +54,9 @@ void MecanumDriveKinematics::SetInverseKinematics(Translation2d fl,
|
||||
Translation2d fr,
|
||||
Translation2d rl,
|
||||
Translation2d rr) const {
|
||||
// clang-format off
|
||||
m_inverseKinematics << 1, -1, (-(fl.X() + fl.Y())).template to<double>(),
|
||||
1, 1, (fr.X() - fr.Y()).template to<double>(),
|
||||
1, 1, (rl.X() - rl.Y()).template to<double>(),
|
||||
1, -1, (-(rr.X() + rr.Y())).template to<double>();
|
||||
// clang-format on
|
||||
m_inverseKinematics = Eigen::Matrix<double, 4, 3>{
|
||||
{1, -1, (-(fl.X() + fl.Y())).template to<double>()},
|
||||
{1, 1, (fr.X() - fr.Y()).template to<double>()},
|
||||
{1, 1, (rl.X() - rl.Y()).template to<double>()},
|
||||
{1, -1, (-(rr.X() + rr.Y())).template to<double>()}};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user