mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[wpimath] Add Translation2d/Translation3d slew rate limiter (#7806)
Co-authored-by: Tyler Veness <calcmogul@gmail.com> Co-authored-by: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com>
This commit is contained in:
@@ -8,6 +8,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import edu.wpi.first.math.geometry.Translation2d;
|
||||
import edu.wpi.first.math.geometry.Translation3d;
|
||||
import edu.wpi.first.wpilibj.UtilityClassTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -167,4 +169,55 @@ class MathUtilTest extends UtilityClassTest<MathUtil> {
|
||||
assertFalse(MathUtil.isNear(400, -315, 5, 0, 360));
|
||||
assertFalse(MathUtil.isNear(400, 395, 5, 0, 360));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSlewRateTranslation2dUnchanged() {
|
||||
Translation2d translation1 = new Translation2d(0, 0);
|
||||
Translation2d translation2 = new Translation2d(2, 2);
|
||||
|
||||
Translation2d result1 = MathUtil.slewRateLimit(translation1, translation2, 1, 50);
|
||||
|
||||
Translation2d expected1 = new Translation2d(2, 2);
|
||||
|
||||
assertEquals(expected1, result1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSlewRateTranslation2dChanged() {
|
||||
Translation2d translation3 = new Translation2d(1, 1);
|
||||
Translation2d translation4 = new Translation2d(3, 3);
|
||||
|
||||
Translation2d result2 = MathUtil.slewRateLimit(translation3, translation4, 0.25, 2);
|
||||
|
||||
Translation2d expected2 =
|
||||
new Translation2d(1.0 + 1.0 / Math.sqrt(8.0), 1.0 + 1.0 / Math.sqrt(8.0));
|
||||
|
||||
assertEquals(expected2, result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSlewRateTranslation3dUnchanged() {
|
||||
Translation3d translation1 = new Translation3d(0, 0, 0);
|
||||
Translation3d translation2 = new Translation3d(2, 2, 2);
|
||||
|
||||
Translation3d result1 = MathUtil.slewRateLimit(translation1, translation2, 1, 50);
|
||||
|
||||
Translation3d expected1 = new Translation3d(2, 2, 2);
|
||||
|
||||
assertEquals(expected1, result1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSlewRateTranslation3dChanged() {
|
||||
Translation3d translation3 = new Translation3d(1, 1, 1);
|
||||
Translation3d translation4 = new Translation3d(3, 3, 3);
|
||||
|
||||
Translation3d result2 = MathUtil.slewRateLimit(translation3, translation4, 0.25, 2);
|
||||
|
||||
Translation3d expected2 =
|
||||
new Translation3d(
|
||||
1.0 + 1.0 / Math.sqrt(12.0), 1.0 + 1.0 / Math.sqrt(12.0), 1.0 + 1.0 / Math.sqrt(12.0));
|
||||
|
||||
assertEquals(expected2, result2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user