[wpimath] Disallow LTV controller max velocities above 15 m/s (#5495)

15 m/s is about 50 ft/s, which is way above what FRC robots should be
able to achieve. This limit lets us catch user errors from bad unit
conversions immediately instead of the LUT generation in the LTV
controllers hanging for a really long time.

Fixes #5027.
This commit is contained in:
Tyler Veness
2023-08-02 23:37:49 -07:00
committed by GitHub
parent 7496e0d208
commit 21439b606c
6 changed files with 24 additions and 8 deletions

View File

@@ -65,7 +65,8 @@ public class LTVDifferentialDriveController {
* @param qelems The maximum desired error tolerance for each state.
* @param relems The maximum desired control effort for each input.
* @param dt Discretization timestep in seconds.
* @throws IllegalArgumentException if max velocity of plant with 12 V input <= 0.
* @throws IllegalArgumentException if max velocity of plant with 12 V input <= 0 m/s or >=
* 15 m/s.
*/
public LTVDifferentialDriveController(
LinearSystem<N2, N2, N2> plant,
@@ -134,7 +135,11 @@ public class LTVDifferentialDriveController {
if (maxV <= 0.0) {
throw new IllegalArgumentException(
"Max velocity of plant with 12 V input must be greater than zero.");
"Max velocity of plant with 12 V input must be greater than 0 m/s.");
}
if (maxV >= 15.0) {
throw new IllegalArgumentException(
"Max velocity of plant with 12 V input must be less than 15 m/s.");
}
for (double velocity = -maxV; velocity < maxV; velocity += 0.01) {

View File

@@ -99,12 +99,15 @@ public class LTVUnicycleController {
* @param dt Discretization timestep in seconds.
* @param maxVelocity The maximum velocity in meters per second for the controller gain lookup
* table. The default is 9 m/s.
* @throws IllegalArgumentException if maxVelocity &lt;= 0.
* @throws IllegalArgumentException if maxVelocity &lt;= 0 m/s or &gt;= 15 m/s.
*/
public LTVUnicycleController(
Vector<N3> qelems, Vector<N2> relems, double dt, double maxVelocity) {
if (maxVelocity <= 0.0) {
throw new IllegalArgumentException("Max velocity must be greater than zero.");
throw new IllegalArgumentException("Max velocity must be greater than 0 m/s.");
}
if (maxVelocity >= 15.0) {
throw new IllegalArgumentException("Max velocity must be less than 15 m/s.");
}
// The change in global pose for a unicycle is defined by the following