[wpilib] LinearSystemSim: Add missing clamp function and getInput() (#6493)

This commit is contained in:
Nicholas Armstrong
2024-04-04 12:19:13 -04:00
committed by GitHub
parent c46847b32a
commit fbb3669546
2 changed files with 36 additions and 1 deletions

View File

@@ -88,7 +88,7 @@ class LinearSystemSim {
*/
void SetInput(const Vectord<Inputs>& u) { m_u = ClampInput(u); }
/*
/**
* Sets the system inputs.
*
* @param row The row in the input matrix to set.
@@ -99,6 +99,21 @@ class LinearSystemSim {
ClampInput(m_u);
}
/**
* Returns the current input of the plant.
*
* @return The current input of the plant.
*/
const Vectord<Inputs>& GetInput() const { return m_u; }
/**
* Returns an element of the current input of the plant.
*
* @param row The row to return.
* @return An element of the current input of the plant.
*/
double GetInput(int row) const { return m_u(row); }
/**
* Sets the system state.
*

View File

@@ -137,6 +137,26 @@ public class LinearSystemSim<States extends Num, Inputs extends Num, Outputs ext
"Malformed input! Got " + u.length + " elements instead of " + m_u.getNumRows());
}
m_u = new Matrix<>(new SimpleMatrix(m_u.getNumRows(), 1, true, u));
m_u = clampInput(m_u);
}
/**
* Returns the current input of the plant.
*
* @return The current input of the plant.
*/
public Matrix<Inputs, N1> getInput() {
return m_u;
}
/**
* Returns an element of the current input of the plant.
*
* @param row The row to return.
* @return An element of the current input of the plant.
*/
public double getInput(int row) {
return m_u.get(row, 0);
}
/**