[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:
Peter Johnson
2022-04-29 22:29:20 -07:00
parent 97c493241f
commit e767605e94
76 changed files with 1136 additions and 1449 deletions

View File

@@ -101,8 +101,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(Eigen::Vector<double, 1>{
m_motor.Get() * frc::RobotController::GetInputVoltage()});
m_armSim.SetInput(frc::Vectord<1>{m_motor.Get() *
frc::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms.
m_armSim.Update(20_ms);

View File

@@ -88,7 +88,7 @@ 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(Eigen::Vector<double, 1>{
m_elevatorSim.SetInput(frc::Vectord<1>{
m_motor.Get() * frc::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms.

View File

@@ -97,8 +97,7 @@ class Robot : public frc::TimedRobot {
}
void TeleopInit() override {
m_loop.Reset(
Eigen::Vector<double, 2>{m_encoder.GetDistance(), m_encoder.GetRate()});
m_loop.Reset(frc::Vectord<2>{m_encoder.GetDistance(), m_encoder.GetRate()});
m_lastProfiledReference = {
units::radian_t(m_encoder.GetDistance()),
@@ -121,12 +120,11 @@ class Robot : public frc::TimedRobot {
m_lastProfiledReference))
.Calculate(20_ms);
m_loop.SetNextR(
Eigen::Vector<double, 2>{m_lastProfiledReference.position.value(),
m_lastProfiledReference.velocity.value()});
m_loop.SetNextR(frc::Vectord<2>{m_lastProfiledReference.position.value(),
m_lastProfiledReference.velocity.value()});
// Correct our Kalman filter's state vector estimate with encoder data.
m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetDistance()});
m_loop.Correct(frc::Vectord<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.

View File

@@ -96,8 +96,7 @@ class Robot : public frc::TimedRobot {
void TeleopInit() override {
// Reset our loop to make sure it's in a known state.
m_loop.Reset(
Eigen::Vector<double, 2>{m_encoder.GetDistance(), m_encoder.GetRate()});
m_loop.Reset(frc::Vectord<2>{m_encoder.GetDistance(), m_encoder.GetRate()});
m_lastProfiledReference = {units::meter_t(m_encoder.GetDistance()),
units::meters_per_second_t(m_encoder.GetRate())};
@@ -119,12 +118,11 @@ class Robot : public frc::TimedRobot {
m_lastProfiledReference))
.Calculate(20_ms);
m_loop.SetNextR(
Eigen::Vector<double, 2>{m_lastProfiledReference.position.value(),
m_lastProfiledReference.velocity.value()});
m_loop.SetNextR(frc::Vectord<2>{m_lastProfiledReference.position.value(),
m_lastProfiledReference.velocity.value()});
// Correct our Kalman filter's state vector estimate with encoder data.
m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetDistance()});
m_loop.Correct(frc::Vectord<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.

View File

@@ -85,7 +85,7 @@ class Robot : public frc::TimedRobot {
}
void TeleopInit() override {
m_loop.Reset(Eigen::Vector<double, 1>{m_encoder.GetRate()});
m_loop.Reset(frc::Vectord<1>{m_encoder.GetRate()});
}
void TeleopPeriodic() override {
@@ -93,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(Eigen::Vector<double, 1>{kSpinup.value()});
m_loop.SetNextR(frc::Vectord<1>{kSpinup.value()});
} else {
// We released the bumper, so let's spin down
m_loop.SetNextR(Eigen::Vector<double, 1>{0.0});
m_loop.SetNextR(frc::Vectord<1>{0.0});
}
// Correct our Kalman filter's state vector estimate with encoder data.
m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetRate()});
m_loop.Correct(frc::Vectord<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.

View File

@@ -85,7 +85,7 @@ class Robot : public frc::TimedRobot {
}
void TeleopInit() override {
m_loop.Reset(Eigen::Vector<double, 1>{m_encoder.GetRate()});
m_loop.Reset(frc::Vectord<1>{m_encoder.GetRate()});
}
void TeleopPeriodic() override {
@@ -93,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(Eigen::Vector<double, 1>{kSpinup.value()});
m_loop.SetNextR(frc::Vectord<1>{kSpinup.value()});
} else {
// We released the bumper, so let's spin down
m_loop.SetNextR(Eigen::Vector<double, 1>{0.0});
m_loop.SetNextR(frc::Vectord<1>{0.0});
}
// Correct our Kalman filter's state vector estimate with encoder data.
m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetRate()});
m_loop.Correct(frc::Vectord<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.