forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShootingCalc.java
More file actions
86 lines (63 loc) · 3.15 KB
/
ShootingCalc.java
File metadata and controls
86 lines (63 loc) · 3.15 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
78
79
80
81
82
83
84
85
86
package org.firstinspires.ftc.teamcode;
import com.acmerobotics.dashboard.FtcDashboard;
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
import com.pedropathing.follower.Follower;
import com.pedropathing.geometry.BezierCurve;
import com.pedropathing.geometry.BezierLine;
import com.pedropathing.geometry.Pose;
import com.pedropathing.math.Vector;
import com.pedropathing.paths.Path;
import com.pedropathing.util.Timer;
import com.qualcomm.hardware.limelightvision.LLResult;
import com.qualcomm.hardware.limelightvision.Limelight3A;
import com.qualcomm.hardware.rev.RevHubOrientationOnRobot;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.IMU;
import com.qualcomm.robotcore.hardware.Servo;
import org.firstinspires.ftc.teamcode.pedroPathing.constants.Constants;
public class ShootingCalc {
public static double getVelocityNeeded(double distance, double shootingAngle, double height){
double GRAVITY = 9.80665;
double vx = Math.sqrt(
(GRAVITY * distance * distance) /
(2 * Math.pow(Math.cos(shootingAngle), 2) * (distance * Math.tan(shootingAngle) - height))
);
double vy = vx * Math.tan(shootingAngle);
// RETURN TOTAL VELOCITY (FIXED)
return Math.sqrt(vx * vx + vy * vy);
}
public static Vector get2DShotVector(Vector robotVelocity, Vector robotPosition, Vector targetVector, double shootingAngle, double height){
Vector toTarget = targetVector.minus(robotPosition);
double distanceMeters = toTarget.getMagnitude() / 39.3701;
double velocity = get2DVelocityNeeded(distanceMeters, shootingAngle, height);
// direction stays same
Vector idealShot = new Vector(velocity, toTarget.getTheta());
// convert robot velocity to m/s before subtracting
return idealShot.minus(robotVelocity.times(1 / 39.3701));
}
public static double flatMagVx(double distance, double height){
double GRAVITY = 9.80665;
return Math.sqrt(Math.abs(GRAVITY * distance * distance / 2) / height);
}
public static double flatMagVy(double distance, double height){
double vX = flatMagVx(distance, height);
double time = distance / vX;
double GRAVITY = 9.80665;
return (GRAVITY / 2 * time * time + height) / time;
}
public static double flatShootingAngleCalc(double distance, double height){
return Math.atan2(flatMagVy(distance, height), flatMagVx(distance, height));
}
public static double get2DVelocityNeeded(double distance, double shootingAngle, double height){
double GRAVITY = 9.80665;
double vx = Math.sqrt((GRAVITY * distance * distance) / (2 * Math.pow(Math.cos(shootingAngle), 2) * (distance * Math.tan(shootingAngle) - height)));
return vx;
}
public static double get2DTimeNeeded(double distance, double shootingAngle, double height){
return distance/get2DVelocityNeeded(distance, shootingAngle, height);
}
}
//