mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +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
@@ -5,7 +5,6 @@
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/Joystick.h>
|
||||
#include <frc/RobotController.h>
|
||||
#include <frc/StateSpaceUtil.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/controller/PIDController.h>
|
||||
#include <frc/motorcontrol/PWMSparkMax.h>
|
||||
@@ -69,8 +68,8 @@ class Robot : public frc::TimedRobot {
|
||||
void SimulationPeriodic() override {
|
||||
// In this method, we update our simulation of what our arm is doing
|
||||
// First, we set our "inputs" (voltages)
|
||||
m_armSim.SetInput(frc::MakeMatrix<1, 1>(
|
||||
m_motor.Get() * frc::RobotController::GetInputVoltage()));
|
||||
m_armSim.SetInput(Eigen::Vector<double, 1>{
|
||||
m_motor.Get() * frc::RobotController::GetInputVoltage()});
|
||||
|
||||
// Next, we update it. The standard loop time is 20ms.
|
||||
m_armSim.Update(20_ms);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/Joystick.h>
|
||||
#include <frc/RobotController.h>
|
||||
#include <frc/StateSpaceUtil.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/controller/PIDController.h>
|
||||
#include <frc/motorcontrol/PWMSparkMax.h>
|
||||
@@ -68,8 +67,8 @@ class Robot : public frc::TimedRobot {
|
||||
void SimulationPeriodic() override {
|
||||
// In this method, we update our simulation of what our elevator is doing
|
||||
// First, we set our "inputs" (voltages)
|
||||
m_elevatorSim.SetInput(frc::MakeMatrix<1, 1>(
|
||||
m_motor.Get() * frc::RobotController::GetInputVoltage()));
|
||||
m_elevatorSim.SetInput(Eigen::Vector<double, 1>{
|
||||
m_motor.Get() * frc::RobotController::GetInputVoltage()});
|
||||
|
||||
// Next, we update it. The standard loop time is 20ms.
|
||||
m_elevatorSim.Update(20_ms);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/StateSpaceUtil.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/XboxController.h>
|
||||
#include <frc/controller/LinearPlantInversionFeedforward.h>
|
||||
@@ -100,7 +99,7 @@ class Robot : public frc::TimedRobot {
|
||||
|
||||
void TeleopInit() override {
|
||||
m_loop.Reset(
|
||||
frc::MakeMatrix<2, 1>(m_encoder.GetDistance(), m_encoder.GetRate()));
|
||||
Eigen::Vector<double, 2>{m_encoder.GetDistance(), m_encoder.GetRate()});
|
||||
|
||||
m_lastProfiledReference = {
|
||||
units::radian_t(m_encoder.GetDistance()),
|
||||
@@ -123,12 +122,12 @@ class Robot : public frc::TimedRobot {
|
||||
m_lastProfiledReference))
|
||||
.Calculate(20_ms);
|
||||
|
||||
m_loop.SetNextR(
|
||||
frc::MakeMatrix<2, 1>(m_lastProfiledReference.position.to<double>(),
|
||||
m_lastProfiledReference.velocity.to<double>()));
|
||||
m_loop.SetNextR(Eigen::Vector<double, 2>{
|
||||
m_lastProfiledReference.position.to<double>(),
|
||||
m_lastProfiledReference.velocity.to<double>()});
|
||||
|
||||
// Correct our Kalman filter's state vector estimate with encoder data.
|
||||
m_loop.Correct(frc::MakeMatrix<1, 1>(m_encoder.GetDistance()));
|
||||
m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetDistance()});
|
||||
|
||||
// Update our LQR to generate new voltage commands and use the voltages to
|
||||
// predict the next state with out Kalman filter.
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/StateSpaceUtil.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/XboxController.h>
|
||||
#include <frc/controller/LinearQuadraticRegulator.h>
|
||||
@@ -98,7 +97,7 @@ class Robot : public frc::TimedRobot {
|
||||
void TeleopInit() override {
|
||||
// Reset our loop to make sure it's in a known state.
|
||||
m_loop.Reset(
|
||||
frc::MakeMatrix<2, 1>(m_encoder.GetDistance(), m_encoder.GetRate()));
|
||||
Eigen::Vector<double, 2>{m_encoder.GetDistance(), m_encoder.GetRate()});
|
||||
|
||||
m_lastProfiledReference = {units::meter_t(m_encoder.GetDistance()),
|
||||
units::meters_per_second_t(m_encoder.GetRate())};
|
||||
@@ -120,12 +119,12 @@ class Robot : public frc::TimedRobot {
|
||||
m_lastProfiledReference))
|
||||
.Calculate(20_ms);
|
||||
|
||||
m_loop.SetNextR(
|
||||
frc::MakeMatrix<2, 1>(m_lastProfiledReference.position.to<double>(),
|
||||
m_lastProfiledReference.velocity.to<double>()));
|
||||
m_loop.SetNextR(Eigen::Vector<double, 2>{
|
||||
m_lastProfiledReference.position.to<double>(),
|
||||
m_lastProfiledReference.velocity.to<double>()});
|
||||
|
||||
// Correct our Kalman filter's state vector estimate with encoder data.
|
||||
m_loop.Correct(frc::MakeMatrix<1, 1>(m_encoder.GetDistance()));
|
||||
m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetDistance()});
|
||||
|
||||
// Update our LQR to generate new voltage commands and use the voltages to
|
||||
// predict the next state with out Kalman filter.
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <frc/DriverStation.h>
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/StateSpaceUtil.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/XboxController.h>
|
||||
#include <frc/controller/LinearQuadraticRegulator.h>
|
||||
@@ -86,7 +85,7 @@ class Robot : public frc::TimedRobot {
|
||||
}
|
||||
|
||||
void TeleopInit() override {
|
||||
m_loop.Reset(frc::MakeMatrix<1, 1>(m_encoder.GetRate()));
|
||||
m_loop.Reset(Eigen::Vector<double, 1>{m_encoder.GetRate()});
|
||||
}
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
@@ -94,14 +93,14 @@ class Robot : public frc::TimedRobot {
|
||||
// setpoint of a PID controller.
|
||||
if (m_joystick.GetRightBumper()) {
|
||||
// We pressed the bumper, so let's set our next reference
|
||||
m_loop.SetNextR(frc::MakeMatrix<1, 1>(kSpinup.to<double>()));
|
||||
m_loop.SetNextR(Eigen::Vector<double, 1>{kSpinup.to<double>()});
|
||||
} else {
|
||||
// We released the bumper, so let's spin down
|
||||
m_loop.SetNextR(frc::MakeMatrix<1, 1>(0.0));
|
||||
m_loop.SetNextR(Eigen::Vector<double, 1>{0.0});
|
||||
}
|
||||
|
||||
// Correct our Kalman filter's state vector estimate with encoder data.
|
||||
m_loop.Correct(frc::MakeMatrix<1, 1>(m_encoder.GetRate()));
|
||||
m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetRate()});
|
||||
|
||||
// Update our LQR to generate new voltage commands and use the voltages to
|
||||
// predict the next state with out Kalman filter.
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <frc/DriverStation.h>
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/StateSpaceUtil.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/XboxController.h>
|
||||
#include <frc/controller/LinearPlantInversionFeedforward.h>
|
||||
@@ -87,7 +86,7 @@ class Robot : public frc::TimedRobot {
|
||||
}
|
||||
|
||||
void TeleopInit() override {
|
||||
m_loop.Reset(frc::MakeMatrix<1, 1>(m_encoder.GetRate()));
|
||||
m_loop.Reset(Eigen::Vector<double, 1>{m_encoder.GetRate()});
|
||||
}
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
@@ -95,14 +94,14 @@ class Robot : public frc::TimedRobot {
|
||||
// setpoint of a PID controller.
|
||||
if (m_joystick.GetRightBumper()) {
|
||||
// We pressed the bumper, so let's set our next reference
|
||||
m_loop.SetNextR(frc::MakeMatrix<1, 1>(kSpinup.to<double>()));
|
||||
m_loop.SetNextR(Eigen::Vector<double, 1>{kSpinup.to<double>()});
|
||||
} else {
|
||||
// We released the bumper, so let's spin down
|
||||
m_loop.SetNextR(frc::MakeMatrix<1, 1>(0.0));
|
||||
m_loop.SetNextR(Eigen::Vector<double, 1>{0.0});
|
||||
}
|
||||
|
||||
// Correct our Kalman filter's state vector estimate with encoder data.
|
||||
m_loop.Correct(frc::MakeMatrix<1, 1>(m_encoder.GetRate()));
|
||||
m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetRate()});
|
||||
|
||||
// Update our LQR to generate new voltage commands and use the voltages to
|
||||
// predict the next state with out Kalman filter.
|
||||
|
||||
Reference in New Issue
Block a user