[wpimath] LinearSystemSim Constructor and method cleanup (#6502)

Modified Java constructors to take a variable number of measurement std devs argument with checks in place to make sure the right amount (or none) are passed into the constructor. All changes passed down to classes utilizing LinearSystemSim.

Removed excess constructors

Removed Java and C++ CurrentDrawAmps method as it doesn't belong in a generic (non electrical) linear system. Kept a non override version in all derived electrical classes.

Also LinearSystemSim has now been made agnostic to electrical systems. Inputs don't have to be voltage. BatteryVoltage clamp function has been pushed down to electrical subclasses.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
Nicholas Armstrong
2024-05-15 13:40:30 -04:00
committed by GitHub
parent 0f45fe9486
commit ab315e24c8
19 changed files with 83 additions and 310 deletions

View File

@@ -78,7 +78,7 @@ class DCMotorSim : public LinearSystemSim<2, 1, 2> {
*
* @return The DC motor current draw.
*/
units::ampere_t GetCurrentDraw() const override;
units::ampere_t GetCurrentDraw() const;
/**
* Sets the input voltage for the DC motor.

View File

@@ -150,7 +150,7 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> {
*
* @return The elevator current draw.
*/
units::ampere_t GetCurrentDraw() const override;
units::ampere_t GetCurrentDraw() const;
/**
* Sets the input voltage for the elevator.

View File

@@ -68,7 +68,7 @@ class FlywheelSim : public LinearSystemSim<1, 1, 1> {
*
* @return The flywheel current draw.
*/
units::ampere_t GetCurrentDraw() const override;
units::ampere_t GetCurrentDraw() const;
/**
* Sets the input voltage for the flywheel.

View File

@@ -86,7 +86,7 @@ class LinearSystemSim {
*
* @param u The system inputs.
*/
void SetInput(const Vectord<Inputs>& u) { m_u = ClampInput(u); }
void SetInput(const Vectord<Inputs>& u) { m_u = u; }
/**
* Sets the system inputs.
@@ -94,10 +94,7 @@ class LinearSystemSim {
* @param row The row in the input matrix to set.
* @param value The value to set the row to.
*/
void SetInput(int row, double value) {
m_u(row, 0) = value;
ClampInput(m_u);
}
void SetInput(int row, double value) { m_u(row, 0) = value; }
/**
* Returns the current input of the plant.
@@ -121,14 +118,6 @@ class LinearSystemSim {
*/
void SetState(const Vectord<States>& state) { m_x = state; }
/**
* Returns the current drawn by this simulated system. Override this method to
* add a custom current calculation.
*
* @return The current drawn by this simulated mechanism.
*/
virtual units::ampere_t GetCurrentDraw() const { return 0_A; }
protected:
/**
* Updates the state estimate of the system.
@@ -147,12 +136,10 @@ class LinearSystemSim {
* Clamp the input vector such that no element exceeds the given voltage. If
* any does, the relative magnitudes of the input will be maintained.
*
* @param u The input vector.
* @return The normalized input.
* @param maxInput The maximum magnitude of the input vector after clamping.
*/
Vectord<Inputs> ClampInput(Vectord<Inputs> u) {
return frc::DesaturateInputVector<Inputs>(
u, frc::RobotController::GetInputVoltage());
void ClampInput(double maxInput) {
m_u = frc::DesaturateInputVector<Inputs>(m_u, maxInput);
}
/// The plant that represents the linear system.

View File

@@ -126,7 +126,7 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> {
*
* @return The arm current draw.
*/
units::ampere_t GetCurrentDraw() const override;
units::ampere_t GetCurrentDraw() const;
/**
* Sets the input voltage for the arm.