[wpimath] Remove LinearSystem from LinearSystemLoop (#2968)

The system wasn't being used internally, and as LinearSystem is stateless, it doesn't need to be held by LinearSystemLoop.
This commit is contained in:
Matt
2020-12-28 10:35:51 -08:00
committed by GitHub
parent aa89744c95
commit 254931b9a8
4 changed files with 43 additions and 73 deletions

View File

@@ -15,8 +15,8 @@
namespace frc {
/**
* Combines a plant, controller, and observer for controlling a mechanism with
* full state feedback.
* Combines a controller, feedforward, and observer for controlling a mechanism
* with full state feedback.
*
* For everything in this file, "inputs" and "outputs" are defined from the
* perspective of the plant. This means U is an input and Y is an output
@@ -37,7 +37,6 @@ class LinearSystemLoop {
* call reset with the initial system state before enabling the loop. This
* constructor assumes that the input(s) to this system are voltage.
*
* @param plant State-space plant.
* @param controller State-space controller.
* @param observer State-space observer.
* @param maxVoltage The maximum voltage that can be applied. Commonly 12.
@@ -75,16 +74,15 @@ class LinearSystemLoop {
clampFunction,
units::second_t dt)
: LinearSystemLoop(
plant, controller,
controller,
LinearPlantInversionFeedforward<States, Inputs>{plant, dt},
observer, clampFunction) {}
/**
* Constructs a state-space loop with the given plant, controller, and
* Constructs a state-space loop with the given controller, feedforward and
* observer. By default, the initial reference is all zeros. Users should
* call reset with the initial system state before enabling the loop.
* call reset with the initial system state.
*
* @param plant State-space plant.
* @param controller State-space controller.
* @param feedforward Plant inversion feedforward.
* @param observer State-space observer.
@@ -92,36 +90,33 @@ class LinearSystemLoop {
* that the inputs are voltages.
*/
LinearSystemLoop(
LinearSystem<States, Inputs, Outputs>& plant,
LinearQuadraticRegulator<States, Inputs>& controller,
const LinearPlantInversionFeedforward<States, Inputs>& feedforward,
KalmanFilter<States, Inputs, Outputs>& observer, units::volt_t maxVoltage)
: LinearSystemLoop(plant, controller, feedforward, observer,
: LinearSystemLoop(controller, feedforward, observer,
[=](Eigen::Matrix<double, Inputs, 1> u) {
return frc::NormalizeInputVector<Inputs>(
u, maxVoltage.template to<double>());
}) {}
/**
* Constructs a state-space loop with the given plant, controller, and
* observer.
* Constructs a state-space loop with the given controller, feedforward,
* observer and clamp function. By default, the initial reference is all
* zeros. Users should call reset with the initial system state.
*
* @param plant State-space plant.
* @param controller State-space controller.
* @param feedforward Plant-inversion feedforward.
* @param observer State-space observer.
* @param clampFunction The function used to clamp the input vector.
*/
LinearSystemLoop(
LinearSystem<States, Inputs, Outputs>& plant,
LinearQuadraticRegulator<States, Inputs>& controller,
const LinearPlantInversionFeedforward<States, Inputs>& feedforward,
KalmanFilter<States, Inputs, Outputs>& observer,
std::function<Eigen::Matrix<double, Inputs, 1>(
const Eigen::Matrix<double, Inputs, 1>&)>
clampFunction)
: m_plant(plant),
m_controller(controller),
: m_controller(controller),
m_feedforward(feedforward),
m_observer(observer),
m_clampFunc(clampFunction) {
@@ -195,11 +190,6 @@ class LinearSystemLoop {
m_nextR = nextR;
}
/**
* Return the plant used internally.
*/
const LinearSystem<States, Inputs, Outputs>& Plant() const { return m_plant; }
/**
* Return the controller used internally.
*/
@@ -281,7 +271,6 @@ class LinearSystemLoop {
}
protected:
LinearSystem<States, Inputs, Outputs>& m_plant;
LinearQuadraticRegulator<States, Inputs>& m_controller;
LinearPlantInversionFeedforward<States, Inputs> m_feedforward;
KalmanFilter<States, Inputs, Outputs>& m_observer;