Skip to content

Commit a73c388

Browse files
committed
added Orbit drive draft
Robot will drive normally and point at a Pose2d
1 parent 1962ba0 commit a73c388

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/main/java/frc/robot/commands/DriveCommands.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package frc.robot.commands;
99

1010
import edu.wpi.first.math.MathUtil;
11+
import edu.wpi.first.math.controller.PIDController;
1112
import edu.wpi.first.math.controller.ProfiledPIDController;
1213
import edu.wpi.first.math.filter.SlewRateLimiter;
1314
import edu.wpi.first.math.geometry.Pose2d;
@@ -30,6 +31,8 @@
3031
import java.util.function.DoubleSupplier;
3132
import java.util.function.Supplier;
3233

34+
import org.photonvision.PhotonUtils;
35+
3336
public 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

Comments
 (0)