blob: 5c749b2108474d5c207f389783e768116ef467bc [file] [log] [blame]
Brian Silverman890a32a2018-03-11 15:41:56 -07001#include "ctre/phoenix/Utilities.h"
2
3namespace ctre {
4namespace phoenix {
5
6float Utilities::abs(float f) {
7 if (f >= 0)
8 return f;
9 return -f;
10}
11
12float 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
20float 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
28bool 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
35void 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
46bool 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
53int 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
60void Utilities::Split_1(float forward, float turn, float *left, float *right) {
61 *left = forward + turn;
62 *right = forward - turn;
63}
64void 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}