Squashed 'third_party/Phoenix-frc-lib/' content from commit 666d176
Change-Id: Ibaca2fc8ffb1177e786576cc1e4cc9f7a8c98f13
git-subtree-dir: third_party/Phoenix-frc-lib
git-subtree-split: 666d176a08151793044ab74e0005f13d3732ed96
diff --git a/java/src/com/ctre/phoenix/Util.java b/java/src/com/ctre/phoenix/Util.java
new file mode 100644
index 0000000..4ccedc7
--- /dev/null
+++ b/java/src/com/ctre/phoenix/Util.java
@@ -0,0 +1,48 @@
+package com.ctre.phoenix;
+
+public class Util
+{
+ public static double cap(double value, double peak)
+ {
+ if(value < -peak) value = -peak;
+ if(value > peak) value = peak;
+ return value;
+ }
+
+ public static int scaleRotationsToNativeUnits(double scalar, double fullRotations) {
+ /* first assume we don't have config info, prep the default return */
+ int retval = (int) fullRotations;
+ /* apply scalar if its available */
+ if (scalar > 0) {
+ retval = (int) (fullRotations * scalar);
+ }
+ return retval;
+ }
+ public static int scaleVelocityToNativeUnits(double scalar, double rpm) {
+ /* first assume we don't have config info, prep the default return */
+ int retval = (int) rpm;
+ /* apply scalar if its available */
+ if (scalar > 0) {
+ retval = (int) (rpm * scalar);
+ }
+ return retval;
+ }
+ public static double scaleNativeUnitsToRotations(double scalar, long nativePos) {
+ /* first assume we don't have config info, prep the default return */
+ double retval = (double) nativePos;
+ /* retrieve scaling info */
+ if (scalar > 0) {
+ retval = ((double) nativePos) / scalar;
+ }
+ return retval;
+ }
+ public static double scaleNativeUnitsToRpm(double scalar, long nativeVel) {
+ /* first assume we don't have config info, prep the default return */
+ double retval = (double) nativeVel;
+ /* apply scalar if its available */
+ if (scalar > 0) {
+ retval = (double) (nativeVel) / (scalar);
+ }
+ return retval;
+ }
+}
\ No newline at end of file