[wpimath] Make feedforward classes throw exceptions for negative Kv or Ka (#6084)

This commit is contained in:
ncorrea210
2023-12-23 11:12:46 -05:00
committed by GitHub
parent d1793f077d
commit 4e4a468d4d
8 changed files with 92 additions and 20 deletions

View File

@@ -28,12 +28,20 @@ public class ArmFeedforward {
* @param kg The gravity gain.
* @param kv The velocity gain.
* @param ka The acceleration gain.
* @throws IllegalArgumentException for kv < zero.
* @throws IllegalArgumentException for ka < zero.
*/
public ArmFeedforward(double ks, double kg, double kv, double ka) {
this.ks = ks;
this.kg = kg;
this.kv = kv;
this.ka = ka;
if (kv < 0.0) {
throw new IllegalArgumentException("kv must be a non-negative number, got " + kv + "!");
}
if (ka < 0.0) {
throw new IllegalArgumentException("ka must be a non-negative number, got " + kv + "!");
}
}
/**

View File

@@ -31,12 +31,20 @@ public class ElevatorFeedforward {
* @param kg The gravity gain.
* @param kv The velocity gain.
* @param ka The acceleration gain.
* @throws IllegalArgumentException for kv &lt; zero.
* @throws IllegalArgumentException for ka &lt; zero.
*/
public ElevatorFeedforward(double ks, double kg, double kv, double ka) {
this.ks = ks;
this.kg = kg;
this.kv = kv;
this.ka = ka;
if (kv < 0.0) {
throw new IllegalArgumentException("kv must be a non-negative number, got " + kv + "!");
}
if (ka < 0.0) {
throw new IllegalArgumentException("ka must be a non-negative number, got " + kv + "!");
}
}
/**

View File

@@ -21,11 +21,19 @@ public class SimpleMotorFeedforward {
* @param ks The static gain.
* @param kv The velocity gain.
* @param ka The acceleration gain.
* @throws IllegalArgumentException for kv &lt; zero.
* @throws IllegalArgumentException for ka &lt; zero.
*/
public SimpleMotorFeedforward(double ks, double kv, double ka) {
this.ks = ks;
this.kv = kv;
this.ka = ka;
if (kv < 0.0) {
throw new IllegalArgumentException("kv must be a non-negative number, got " + kv + "!");
}
if (ka < 0.0) {
throw new IllegalArgumentException("ka must be a non-negative number, got " + kv + "!");
}
}
/**