88package frc .robot .commands ;
99
1010import edu .wpi .first .math .MathUtil ;
11+ import edu .wpi .first .math .controller .PIDController ;
1112import edu .wpi .first .math .controller .ProfiledPIDController ;
1213import edu .wpi .first .math .filter .SlewRateLimiter ;
1314import edu .wpi .first .math .geometry .Pose2d ;
3031import java .util .function .DoubleSupplier ;
3132import java .util .function .Supplier ;
3233
34+ import org .photonvision .PhotonUtils ;
35+
3336public class DriveCommands {
3437 private static final double DEADBAND = 0.1 ;
3538 private static final double ANGLE_KP = 5.0 ;
@@ -41,6 +44,10 @@ public class DriveCommands {
4144 private static final double WHEEL_RADIUS_MAX_VELOCITY = 0.25 ; // Rad/Sec
4245 private static final double WHEEL_RADIUS_RAMP_RATE = 0.05 ; // Rad/Sec^2
4346
47+ private static final PIDController orbitController =
48+ new PIDController (1 , 0 , 0.5 );
49+
50+
4451 private DriveCommands () {}
4552
4653 private static Translation2d getLinearVelocityFromJoysticks (double x , double y ) {
@@ -150,6 +157,28 @@ public static Command joystickDriveAtAngle(
150157 .beforeStarting (() -> angleController .reset (drive .getRotation ().getRadians ()));
151158 }
152159
160+ public static Command joystickOrbitDrive (
161+ Drive drive ,
162+ DoubleSupplier xSupplier ,
163+ DoubleSupplier ySupplier ,
164+ Pose2d orbitPose ) {
165+ return Commands .run (
166+ () -> {
167+ Rotation2d rotationTarget = PhotonUtils .getYawToPose (drive .getPose (), orbitPose );//gets angle from robot position to tag position
168+
169+ double radiansOff = drive .getPose ().getRotation ().getRadians () - rotationTarget .getRadians ();
170+
171+ double orbitControllerOutput = orbitController .calculate (radiansOff , 0 );
172+ double orbitPIDXOut = xSupplier .getAsDouble ();
173+ double orbitPIDYOut = ySupplier .getAsDouble ();
174+
175+ drive .runVelocity (
176+ ChassisSpeeds .fromFieldRelativeSpeeds (orbitPIDXOut , orbitPIDYOut , orbitControllerOutput , drive .getPose ().getRotation ())
177+ );
178+
179+
180+ }, drive );
181+ }
153182 /** pid look at thingy */
154183 public static Command lookAt (
155184 Drive drive ,
0 commit comments