Brian Silverman | 890a32a | 2018-03-11 15:41:56 -0700 | [diff] [blame^] | 1 | package com.ctre.phoenix; |
| 2 | |
| 3 | public class Util |
| 4 | { |
| 5 | public static double cap(double value, double peak) |
| 6 | { |
| 7 | if(value < -peak) value = -peak; |
| 8 | if(value > peak) value = peak; |
| 9 | return value; |
| 10 | } |
| 11 | |
| 12 | public static int scaleRotationsToNativeUnits(double scalar, double fullRotations) { |
| 13 | /* first assume we don't have config info, prep the default return */ |
| 14 | int retval = (int) fullRotations; |
| 15 | /* apply scalar if its available */ |
| 16 | if (scalar > 0) { |
| 17 | retval = (int) (fullRotations * scalar); |
| 18 | } |
| 19 | return retval; |
| 20 | } |
| 21 | public static int scaleVelocityToNativeUnits(double scalar, double rpm) { |
| 22 | /* first assume we don't have config info, prep the default return */ |
| 23 | int retval = (int) rpm; |
| 24 | /* apply scalar if its available */ |
| 25 | if (scalar > 0) { |
| 26 | retval = (int) (rpm * scalar); |
| 27 | } |
| 28 | return retval; |
| 29 | } |
| 30 | public static double scaleNativeUnitsToRotations(double scalar, long nativePos) { |
| 31 | /* first assume we don't have config info, prep the default return */ |
| 32 | double retval = (double) nativePos; |
| 33 | /* retrieve scaling info */ |
| 34 | if (scalar > 0) { |
| 35 | retval = ((double) nativePos) / scalar; |
| 36 | } |
| 37 | return retval; |
| 38 | } |
| 39 | public static double scaleNativeUnitsToRpm(double scalar, long nativeVel) { |
| 40 | /* first assume we don't have config info, prep the default return */ |
| 41 | double retval = (double) nativeVel; |
| 42 | /* apply scalar if its available */ |
| 43 | if (scalar > 0) { |
| 44 | retval = (double) (nativeVel) / (scalar); |
| 45 | } |
| 46 | return retval; |
| 47 | } |
| 48 | } |