Skip to content

Commit

Permalink
Fully automatic aiming system at target!
Browse files Browse the repository at this point in the history
  • Loading branch information
TreeWonTwoToFor committed Feb 10, 2024
1 parent 3fdfb59 commit d8ac87b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/deploy/swerve/comp/swervedrive.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": 0,
"canbus": null
},
"invertedIMU": true,
"invertedIMU": false,
"modules": [
"frontleft.json",
"frontright.json",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc3512/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static final class GeneralConstants {
}

public static final class VisionConstants {
public static final String cameraName = "jonny";
public static final String cameraName = "USB_GS_Camera";
public static final Transform3d robotToCam = new Transform3d();
}
}
13 changes: 6 additions & 7 deletions src/main/java/frc3512/robot/subsystems/Swerve.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package frc3512.robot.subsystems;

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
import edu.wpi.first.math.trajectory.Trajectory;
import edu.wpi.first.wpilibj.Filesystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc3512.lib.logging.SpartanEntryManager;
Expand Down Expand Up @@ -75,21 +75,20 @@ public Command driveCommand(
PhotonCamera camera) {
return run(
() -> {
SmartDashboard.putBoolean("Diagnostics/Vision/DoVisionAim", doAim.getAsBoolean());
PhotonPipelineResult result = camera.getLatestResult();
final double ANGULAR_P = 0.1;
final double ANGULAR_D = 0.0;
PIDController turnController = new PIDController(ANGULAR_P, 0, ANGULAR_D);
if (result.hasTargets() && doAim.getAsBoolean()) {
drive(
getTargetSpeeds(
swerve.swerveController.getRawTargetSpeeds(
MathUtil.applyDeadband(
translationX.getAsDouble() * swerve.getMaximumVelocity(),
Constants.SwerveConstants.swerveDeadband),
MathUtil.applyDeadband(
translationY.getAsDouble() * swerve.getMaximumVelocity(),
Constants.SwerveConstants.swerveDeadband),
Rotation2d.fromDegrees(
result
.getBestTarget()
.getYaw()))); // Not sure if this will work, more math may be required.
-turnController.calculate(result.getBestTarget().getYaw(), 0)));
} else {
swerve.drive(
new Translation2d(
Expand Down

0 comments on commit d8ac87b

Please sign in to comment.