mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[wpimath] Fix C++ feedforward constructors and add tests (#6873)
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
|
||||
package edu.wpi.first.math.controller;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import edu.wpi.first.math.MatBuilder;
|
||||
import edu.wpi.first.math.Matrix;
|
||||
@@ -100,4 +102,14 @@ class ArmFeedforwardTest {
|
||||
assertEquals(-7.25, m_armFF.minAchievableAcceleration(12, Math.PI / 3, 1), 0.002);
|
||||
assertEquals(-5.25, m_armFF.minAchievableAcceleration(12, Math.PI / 3, -1), 0.002);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNegativeGains() {
|
||||
assertAll(
|
||||
() ->
|
||||
assertThrows(IllegalArgumentException.class, () -> new ArmFeedforward(ks, kg, -kv, ka)),
|
||||
() ->
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new ArmFeedforward(ks, kg, kv, -ka)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
package edu.wpi.first.math.controller;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import edu.wpi.first.math.MatBuilder;
|
||||
import edu.wpi.first.math.Nat;
|
||||
@@ -53,4 +55,15 @@ class ElevatorFeedforwardTest {
|
||||
assertEquals(-8.25, m_elevatorFF.minAchievableAcceleration(12, 2), 0.002);
|
||||
assertEquals(-4.75, m_elevatorFF.minAchievableAcceleration(12, -2), 0.002);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNegativeGains() {
|
||||
assertAll(
|
||||
() ->
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new ElevatorFeedforward(ks, kg, -kv, ka)),
|
||||
() ->
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new ElevatorFeedforward(ks, kg, kv, -ka)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
package edu.wpi.first.math.controller;
|
||||
|
||||
import static edu.wpi.first.units.Units.RadiansPerSecond;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import edu.wpi.first.math.MatBuilder;
|
||||
import edu.wpi.first.math.Nat;
|
||||
@@ -49,4 +51,23 @@ class SimpleMotorFeedforwardTest {
|
||||
simpleMotor.calculate(currentVelocity, nextVelocity).magnitude(),
|
||||
2.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNegativeGains() {
|
||||
double Ks = 0.5;
|
||||
double Kv = 3.5;
|
||||
double Ka = 3.5;
|
||||
double dt = 0.02;
|
||||
|
||||
assertAll(
|
||||
() ->
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new SimpleMotorFeedforward(Ks, -Kv, Ka, dt)),
|
||||
() ->
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new SimpleMotorFeedforward(Ks, Kv, -Ka, dt)),
|
||||
() ->
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new SimpleMotorFeedforward(Ks, Kv, Ka, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user