Skip to content

Commit bc40b80

Browse files
authored
Merge pull request #5 from Team6593/UtilImprovements
Merge branch "UtilImprovements" into master
2 parents c0b1df1 + 3fdccaa commit bc40b80

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) FIRST and other WPILib contributors.
2+
// Open Source Software; you can modify and/or share it under the terms of
3+
// the WPILib BSD license file in the root directory of this project.
4+
5+
package frc.robot.Utils;
6+
7+
/** Add your docs here. */
8+
public class UnitConverter {
9+
10+
/**
11+
* An ideal use-case for this is when you are programming sensors/encoders/autonomoue
12+
* Converts degrees into radians
13+
* @param degrees
14+
* @return radians
15+
*/
16+
public double deg2rad(double degrees) {
17+
double radians = Math.toRadians(degrees);
18+
return radians;
19+
}
20+
21+
/**
22+
* An ideal use-case for this is when you are programming sensors/encoders/autonomoue
23+
* Converts radians into degrees
24+
* @param radians
25+
* @return degrees
26+
*/
27+
public double rad2deg(double radians) {
28+
double degrees = Math.toDegrees(radians);
29+
return degrees;
30+
}
31+
32+
/**
33+
* An ideal use-case for this is when you are programming sensors/encoders/autonomoue
34+
* @param units
35+
* @return units per revolution/full rotation (360 degrees)
36+
*/
37+
public double unitsPerFullRevolution(double units) {
38+
double unitsPerRev = units / 360;
39+
return unitsPerRev;
40+
}
41+
42+
/**
43+
* An ideal use-case for this is when you are programming sensors/encoders/autonomoue
44+
* @param units
45+
* @return units per half-revolution/half of a full rotation (180 degrees)
46+
*/
47+
public double unitsPerHalfRevolution(double units) {
48+
double unitsPerHalfRev = units / 180;
49+
return unitsPerHalfRev;
50+
}
51+
52+
/**
53+
* An ideal use-case for this is when you are programming sensors/encoders/autonomoue
54+
* @param units
55+
* @param degrees
56+
* @return units per-degree (units/degree)
57+
*/
58+
public double unitsPerDegree(double units, double degrees) {
59+
double unitsPerDegr = units / degrees;
60+
return unitsPerDegr;
61+
}
62+
63+
/**
64+
* An ideal use-case for this is when you are programming sensors/encoders/autonomoue
65+
* @param degree
66+
* @param units
67+
* @return degree(s) per unit (degree/units)
68+
*/
69+
public double degreePerUnits(double degree, double units) {
70+
double degPerUnit = degree / units;
71+
return degPerUnit;
72+
}
73+
74+
}

0 commit comments

Comments
 (0)