Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
[utils] Add deadzone function (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty authored Jul 9, 2024
1 parent 61b25be commit 4f9741a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/frc/robot/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ private Utils() {
public static double now() {
return WPIUtilJNI.now() * 1e+6;
}

/**
* A function to apply a 0.05 deadzone.
*
* @param value The value to apply a deadzone to.
* @return The value with the applied deadzone.
*/
public static double deadzone(double value) {
return (Math.abs(value) > 0.05) ? value : 0;
}
}
9 changes: 9 additions & 0 deletions src/test/java/frc/robot/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ void testNow() {
SimHooks.stepTiming(3);
assertEquals(Utils.now(), 3.0E12);
}

@Test
void testDeadzone() {
var val1 = 0.001;
assertEquals(Utils.deadzone(val1), 0);

var val2 = 0.5;
assertEquals(Utils.deadzone(val2), val2);
}
}

0 comments on commit 4f9741a

Please sign in to comment.