|
5 | 5 | import com.pathplanner.lib.config.PIDConstants; |
6 | 6 | import com.pathplanner.lib.config.RobotConfig; |
7 | 7 | import com.pathplanner.lib.controllers.PPHolonomicDriveController; |
8 | | -import edu.wpi.first.math.controller.ProfiledPIDController; |
9 | | -import edu.wpi.first.math.geometry.Pose2d; |
10 | | -import edu.wpi.first.math.geometry.Rotation2d; |
11 | | -import edu.wpi.first.math.kinematics.ChassisSpeeds; |
12 | 8 | import edu.wpi.first.math.system.plant.DCMotor; |
13 | 9 | import edu.wpi.first.wpilibj.DriverStation; |
14 | | -import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; |
15 | 10 | import frc.robot.Subsystems.Drive.Drive; |
16 | | -import frc.robot.Subsystems.Drive.DriveStates; |
17 | 11 | import swervelib.SwerveDrive; |
18 | 12 |
|
19 | 13 | public class PathFinder { |
20 | 14 |
|
21 | | - public static Pose2d getNearestTargetPose(DriveStates state, Pose2d currentPose) { |
22 | | - Pose2d nearestPose = null; |
23 | | - double nearestDistance = Double.MAX_VALUE; |
24 | | - |
25 | | - for (Pose2d pose : state.getTargetPoses()) { |
26 | | - double distance = getDistance(currentPose, pose); |
27 | | - if (distance < nearestDistance) { |
28 | | - nearestPose = pose; |
29 | | - nearestDistance = distance; |
30 | | - } |
31 | | - } |
32 | | - return nearestPose; |
33 | | - } |
34 | | - |
35 | | - public static Pose2d MirrorPoseNear(DriveStates state, Pose2d currentPose) { |
36 | | - Pose2d nearestPose = null; |
37 | | - double nearestDistance = Double.MAX_VALUE; |
38 | | - Pose2d workingPose; |
39 | | - |
40 | | - for (Pose2d pose : state.getTargetPoses()) { |
41 | | - workingPose = MirrorPose(pose); |
42 | | - double distance = getDistance(currentPose, workingPose); |
43 | | - if (distance < nearestDistance) { |
44 | | - nearestPose = workingPose; |
45 | | - nearestDistance = distance; |
46 | | - } |
47 | | - } |
48 | | - return nearestPose; |
49 | | - } |
50 | | - |
51 | | - public static Pose2d MirrorPose(Pose2d input) { |
52 | | - return new Pose2d( |
53 | | - (8.77 * 2) - input.getX(), |
54 | | - input.getY(), |
55 | | - new Rotation2d(-input.getRotation().getRadians()) |
56 | | - ); |
57 | | - } |
58 | | - |
59 | | - public static double getDistance(Pose2d a, Pose2d b) { |
60 | | - return (a.getTranslation().getDistance(b.getTranslation())); |
61 | | - } |
62 | | - |
63 | | - public static ChassisSpeeds driveToPose( |
64 | | - Pose2d targetPose, |
65 | | - Pose2d currentPose, |
66 | | - ProfiledPIDController x, |
67 | | - ProfiledPIDController y, |
68 | | - ProfiledPIDController omega |
69 | | - ) { |
70 | | - double rotationOutput = omega.calculate( |
71 | | - currentPose.getRotation().getRadians(), |
72 | | - targetPose.getRotation().getRadians() |
73 | | - ); |
74 | | - double xOutput = x.calculate(currentPose.getX(), targetPose.getX()); |
75 | | - double yOutput = y.calculate(currentPose.getY(), targetPose.getY()); |
76 | | - |
77 | | - return new ChassisSpeeds(xOutput, yOutput, rotationOutput); |
78 | | - } |
79 | | - |
80 | | - public static Pose2d getAssignedCagePose( |
81 | | - SendableChooser<Pose2d[]> cageChooser, |
82 | | - Pose2d curentPose |
83 | | - ) { |
84 | | - if ( |
85 | | - getDistance(cageChooser.getSelected()[0], curentPose) > |
86 | | - getDistance(cageChooser.getSelected()[1], curentPose) |
87 | | - ) { |
88 | | - return cageChooser.getSelected()[1]; |
89 | | - } else { |
90 | | - return cageChooser.getSelected()[0]; |
91 | | - } |
92 | | - } |
93 | | - |
94 | 15 | public static void BuildAutoBuilder(SwerveDrive swerveDrive, Drive drive) { |
95 | 16 | // Auto Builder and Pathfinder setup: |
96 | 17 | RobotConfig config = null; |
|
0 commit comments