From e17100cd4257287beb499b0ceb3855aa9ae883ab Mon Sep 17 00:00:00 2001 From: EliTheCompSciGuy <35388026+EliTheCompSciGuy@users.noreply.github.com> Date: Thu, 1 Feb 2018 18:36:50 -0500 Subject: [PATCH 1/2] Create LimelightMath I didn't know the exact number for some variables or the exact format of the Limelight code, but I got the math for most (if not all) of the calculations to determine distances and their rate of change. I parsed whatever I didn't know or if the value would be imported from another class. --- .../usfirst/frc/team263/robot/LimelightMath | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Slipgate/src/org/usfirst/frc/team263/robot/LimelightMath diff --git a/Slipgate/src/org/usfirst/frc/team263/robot/LimelightMath b/Slipgate/src/org/usfirst/frc/team263/robot/LimelightMath new file mode 100644 index 0000000..9db50d2 --- /dev/null +++ b/Slipgate/src/org/usfirst/frc/team263/robot/LimelightMath @@ -0,0 +1,51 @@ +import javax.swing.JOptionPane; +import java.lang.Math; +public class LimelightMath +{ + public static void main(String[] args) + { + String X = JOptionPane.showInputDialog("Enter the robot's distance from cube (in)."); + double x = Double.parseDouble(X); + String Y = JOptionPane.showInputDialog("Enter the fixed height of the Limelight."); + double y = Double.parseDouble(Y); + String V = JOptionPane.showInputDialog("Enter the velocity of the robot (in/s)."); // v = dx + double v = Double.parseDouble(V); + double h = calcLimelightDistance(x, y); + double dh = changeInLimelightDistance(x,y,v); + double o1 = Math.toDegrees(angleOfElevation(x,y)); + double o2 = Math.toDegrees(angleOther(x,y)); + double do1 = Math.toDegrees(-1 * changeInAngle(x,y)); + double do2 = Math.toDegrees(changeInAngle(x,y)); + if (v == 0) + { + do1 = 0; + do2 = 0; + } + System.out.println("Distance = " + h + " in"); + System.out.println("Change in Diagonal Distance = " + dh + " in/s"); + System.out.println("Angle of Elevation = " + o1 + " degrees"); + System.out.println("Other Angle = " + o2 + " degrees"); + System.out.println("Change in Angle of Elevation = " + do1 + " degrees/s"); + System.out.println("Change in Other Angle = " + do2 + " degrees/s"); + } + public static double calcLimelightDistance(double a, double b) + { + return Math.hypot(a, b); + } + public static double changeInLimelightDistance(double a, double b, double c) + { + return (a * c) / Math.hypot(a, b); + } + public static double angleOfElevation(double a, double b) + { + return Math.acos(a / (Math.hypot(a, b))); + } + public static double angleOther(double a, double b) + { + return Math.asin(a / (Math.hypot(a, b))); + } + public static double changeInAngle(double a, double b) + { + return 1 / (b * (1 + Math.pow(a, 2) / Math.pow(b, 2))); + } +} From 04ed5b2eb8496ac81ad7a758a849b2aa97ae21e4 Mon Sep 17 00:00:00 2001 From: EliTheCompSciGuy <35388026+EliTheCompSciGuy@users.noreply.github.com> Date: Sun, 4 Feb 2018 11:16:26 -0500 Subject: [PATCH 2/2] Update LimelightMath I removed all of the parsing at the beginning of the code to prevent dialog boxes from popping up. I didn't put in any computations/values for these variables since x and v would be imported from another source and y hasn't been determined yet. I also put in documentation stating what each variable means and what each method is calculating . --- .../usfirst/frc/team263/robot/LimelightMath | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/Slipgate/src/org/usfirst/frc/team263/robot/LimelightMath b/Slipgate/src/org/usfirst/frc/team263/robot/LimelightMath index 9db50d2..c30fadc 100644 --- a/Slipgate/src/org/usfirst/frc/team263/robot/LimelightMath +++ b/Slipgate/src/org/usfirst/frc/team263/robot/LimelightMath @@ -4,18 +4,24 @@ public class LimelightMath { public static void main(String[] args) { - String X = JOptionPane.showInputDialog("Enter the robot's distance from cube (in)."); - double x = Double.parseDouble(X); - String Y = JOptionPane.showInputDialog("Enter the fixed height of the Limelight."); - double y = Double.parseDouble(Y); - String V = JOptionPane.showInputDialog("Enter the velocity of the robot (in/s)."); // v = dx - double v = Double.parseDouble(V); - double h = calcLimelightDistance(x, y); - double dh = changeInLimelightDistance(x,y,v); - double o1 = Math.toDegrees(angleOfElevation(x,y)); - double o2 = Math.toDegrees(angleOther(x,y)); - double do1 = Math.toDegrees(-1 * changeInAngle(x,y)); - double do2 = Math.toDegrees(changeInAngle(x,y)); + double x = ; + //the distance between the robot and the power cube (needs to be imported) + double y = ; + //the height of the limelight camera above the cube (once known we can input that straight into the math) + double v = ; + //(v = dx) the velocity/change in position of the robot over a period of time (needs to be imported) + double h = calcLimelightDistance(x, y); + //the calculated distance between the limelight and the power cube + double dh = changeInLimelightDistance(x,y,v); + //the calculated change in distance between the limelight and the power cube + double o1 = Math.toDegrees(angleOfElevation(x,y)); + //the calculated measure of the angle of elevation of the limelight + double o2 = Math.toDegrees(angleOther(x,y)); + //the calculated measure of the complement to the angle of elevation + double do1 = Math.toDegrees(-1 * changeInAngle(x,y)); + //the calculated change in the angle of elevation + double do2 = Math.toDegrees(changeInAngle(x,y)); + //the calculated change of the complement to the angle of elevation if (v == 0) { do1 = 0; @@ -30,22 +36,27 @@ public class LimelightMath } public static double calcLimelightDistance(double a, double b) { - return Math.hypot(a, b); + return Math.hypot(a, b); + //method to calculate h; a = x & b = y } public static double changeInLimelightDistance(double a, double b, double c) { - return (a * c) / Math.hypot(a, b); + return (a * c) / Math.hypot(a, b); + //method to calculate dh; a = x, b = y & c = v } public static double angleOfElevation(double a, double b) { - return Math.acos(a / (Math.hypot(a, b))); + return Math.acos(a / (Math.hypot(a, b))); + //method to calculate o1; a = x & b = y } public static double angleOther(double a, double b) { - return Math.asin(a / (Math.hypot(a, b))); + return Math.asin(a / (Math.hypot(a, b))); + //method to calculate o2; a = x & b = y } public static double changeInAngle(double a, double b) { - return 1 / (b * (1 + Math.pow(a, 2) / Math.pow(b, 2))); + return 1 / (b * (1 + Math.pow(a, 2) / Math.pow(b, 2))); + //method to calculate do2 (do1 = -1 * do2); a = x & b = y } }