Brian Silverman | 890a32a | 2018-03-11 15:41:56 -0700 | [diff] [blame] | 1 | #include "ctre/phoenix/Utilities.h" |
| 2 | |
| 3 | namespace ctre { |
| 4 | namespace phoenix { |
| 5 | |
| 6 | float Utilities::abs(float f) { |
| 7 | if (f >= 0) |
| 8 | return f; |
| 9 | return -f; |
| 10 | } |
| 11 | |
| 12 | float Utilities::bound(float value, float capValue) { |
| 13 | if (value > capValue) |
| 14 | return capValue; |
| 15 | if (value < -capValue) |
| 16 | return -capValue; |
| 17 | return value; |
| 18 | } |
| 19 | |
| 20 | float Utilities::cap(float value, float peak) { |
| 21 | if (value < -peak) |
| 22 | return -peak; |
| 23 | if (value > +peak) |
| 24 | return +peak; |
| 25 | return value; |
| 26 | } |
| 27 | |
| 28 | bool Utilities::Contains(char array[], char item) { |
| 29 | //Not sure how to implement in c++ yet, made private |
| 30 | (void)array; |
| 31 | (void)item; |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | void Utilities::Deadband(float &value, float deadband) { |
| 36 | if (value < -deadband) { |
| 37 | /* outside of deadband */ |
| 38 | } else if (value > +deadband) { |
| 39 | /* outside of deadband */ |
| 40 | } else { |
| 41 | /* within 10% so zero it */ |
| 42 | value = 0; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | bool Utilities::IsWithin(float value, float compareTo, float allowDelta) { |
| 47 | float f = value - compareTo; |
| 48 | if (f < 0) |
| 49 | f *= -1; |
| 50 | return (f < allowDelta); |
| 51 | } |
| 52 | |
| 53 | int Utilities::SmallerOf(int value_1, int value_2) { |
| 54 | if (value_1 > value_2) |
| 55 | return value_2; |
| 56 | else |
| 57 | return value_1; |
| 58 | } |
| 59 | |
| 60 | void Utilities::Split_1(float forward, float turn, float *left, float *right) { |
| 61 | *left = forward + turn; |
| 62 | *right = forward - turn; |
| 63 | } |
| 64 | void Utilities::Split_2(float left, float right, float *forward, float *turn) { |
| 65 | *forward = (left + right) * 0.5f; |
| 66 | *turn = (left - right) * 0.5f; |
| 67 | } |
| 68 | } |
| 69 | } |