-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWheelRounder.java
More file actions
77 lines (62 loc) · 2.11 KB
/
WheelRounder.java
File metadata and controls
77 lines (62 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
This makes two wheel values equal if they are close enough together. This
also ensures that they are not above 1.
*/
package org.firstinspires.ftc.teamcode;
public class WheelRounder {
double tolerance;
public WheelRounder(double tolerance_input) {
tolerance = tolerance_input;
}
public void scream() {
System.out.println("AAAAAA!!!");
}
public double truncateNumber(double number) {
int number_processing = (int) (number * 100);
double number_final_processing = (number_processing/100.0);
return(number_final_processing);
}
//if this is close enough to 1 to be within its tolerance.
public boolean toleratesOne(double number) {
return(Math.abs(1-number)<=tolerance);
}
public boolean toleratesZero(double number) {
return(Math.abs(number)<=tolerance);
}
public boolean toleratesNegativeOne(double number) {
return(Math.abs(1+number)<=tolerance);
}
//this rounds, based on tolerance, to -1, 0, or 1. Also caps the range
//of values, preventing them from going above 1 or below -1.
public double ends(double number) {
if (toleratesOne(number)) {
return(1);
}
if (toleratesZero(number)) {
return(0);
}
if (toleratesNegativeOne(number)) {
return(-1);
}
if (number > 1) {
return(1);
}
if (number < -1) {
return (-1);
}
return(number);
}
public double[] roundWheel(double wheel1, double wheel2) {
double wheel1_return = wheel1;
double wheel2_return = wheel2;
boolean close_to_opposites = false;
if (Math.abs(wheel1-wheel2)<tolerance) {
wheel1_return = (wheel1+wheel2)/2;
wheel2_return = (wheel1+wheel2)/2;
}
wheel1_return = ends(wheel1_return);
wheel2_return = ends(wheel2_return);
double[] wheels_return = {truncateNumber(wheel1_return), truncateNumber(wheel2_return)};
return(wheels_return);
}
}