[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:
Tyler Veness
2021-08-19 00:23:48 -07:00
committed by Peter Johnson
parent 72716f51ce
commit 9359431bad
63 changed files with 821 additions and 955 deletions

View File

@@ -59,7 +59,7 @@ class LinearPlantInversionFeedforward {
*
* @return The calculated feedforward.
*/
const Eigen::Matrix<double, Inputs, 1>& Uff() const { return m_uff; }
const Eigen::Vector<double, Inputs>& Uff() const { return m_uff; }
/**
* Returns an element of the previously calculated feedforward.
@@ -75,7 +75,7 @@ class LinearPlantInversionFeedforward {
*
* @return The current reference vector.
*/
const Eigen::Matrix<double, States, 1>& R() const { return m_r; }
const Eigen::Vector<double, States>& R() const { return m_r; }
/**
* Returns an element of the reference vector r.
@@ -91,7 +91,7 @@ class LinearPlantInversionFeedforward {
*
* @param initialState The initial state vector.
*/
void Reset(const Eigen::Matrix<double, States, 1>& initialState) {
void Reset(const Eigen::Vector<double, States>& initialState) {
m_r = initialState;
m_uff.setZero();
}
@@ -109,16 +109,16 @@ class LinearPlantInversionFeedforward {
* future reference. This uses the internally stored "current"
* reference.
*
* If this method is used the initial state of the system is the one
* set using Reset(const Eigen::Matrix<double, States, 1>&).
* If the initial state is not set it defaults to a zero vector.
* If this method is used the initial state of the system is the one set using
* Reset(const Eigen::Vector<double, States>&). If the initial state is not
* set it defaults to a zero vector.
*
* @param nextR The reference state of the future timestep (k + dt).
*
* @return The calculated feedforward.
*/
Eigen::Matrix<double, Inputs, 1> Calculate(
const Eigen::Matrix<double, States, 1>& nextR) {
Eigen::Vector<double, Inputs> Calculate(
const Eigen::Vector<double, States>& nextR) {
return Calculate(m_r, nextR); // NOLINT
}
@@ -130,9 +130,9 @@ class LinearPlantInversionFeedforward {
*
* @return The calculated feedforward.
*/
Eigen::Matrix<double, Inputs, 1> Calculate(
const Eigen::Matrix<double, States, 1>& r,
const Eigen::Matrix<double, States, 1>& nextR) {
Eigen::Vector<double, Inputs> Calculate(
const Eigen::Vector<double, States>& r,
const Eigen::Vector<double, States>& nextR) {
m_uff = m_B.householderQr().solve(nextR - (m_A * r));
m_r = nextR;
return m_uff;
@@ -145,10 +145,10 @@ class LinearPlantInversionFeedforward {
units::second_t m_dt;
// Current reference
Eigen::Matrix<double, States, 1> m_r;
Eigen::Vector<double, States> m_r;
// Computed feedforward
Eigen::Matrix<double, Inputs, 1> m_uff;
Eigen::Vector<double, Inputs> m_uff;
};
} // namespace frc