[wpimath] Move SlewRateLimiter from wpilib to wpimath (#3399)

Timer was replaced with wpi::Now() to avoid a dependency on other wpilib
classes.
This commit is contained in:
Tyler Veness
2021-05-31 10:35:54 -07:00
committed by GitHub
parent 93523d572e
commit 01dc0249de
16 changed files with 93 additions and 32 deletions

View File

@@ -0,0 +1,35 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.math.filter;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.wpiutil.WPIUtilJNI;
import org.junit.jupiter.api.Test;
public class SlewRateLimiterTest {
@Test
void slewRateLimitTest() {
WPIUtilJNI.enableMockTime();
var limiter = new SlewRateLimiter(1);
WPIUtilJNI.setMockTime(1000000L);
assertTrue(limiter.calculate(2) < 2);
WPIUtilJNI.setMockTime(0L);
}
@Test
void slewRateNoLimitTest() {
WPIUtilJNI.enableMockTime();
var limiter = new SlewRateLimiter(1);
WPIUtilJNI.setMockTime(1000000L);
assertEquals(limiter.calculate(0.5), 0.5);
WPIUtilJNI.setMockTime(0L);
}
}