Skip to content

Commit

Permalink
Updating for competition
Browse files Browse the repository at this point in the history
- autos calibrate gyro properly
- adjust shooter angle
  • Loading branch information
bobopop787 committed Mar 9, 2024
1 parent b064743 commit c82950a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/main/java/frc/robot/commands/Autos.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public class Autos {
public static final SendableChooser<AutoCommand> autoChooser = new SendableChooser<>();
public static final Field2d autoField = new Field2d();

public static final void initAutos(SwerveDrive swerveDrive, Shooter shooter) {
autoChooser.addOption("Speaker Back", new SpeakerBack(swerveDrive, shooter));
autoChooser.setDefaultOption("Shoot Only", new ShootOnly(shooter));
public static final void initAutos(SwerveDrive swerve, Shooter shooter) {
autoChooser.addOption("Speaker Back", new SpeakerBack(swerve, shooter));
autoChooser.setDefaultOption("Shoot Only", new ShootOnly(swerve, shooter));
// autoChooser.addOption("Shoot Only", new SpeakerOnly(shooter));
autoChooser.addOption("Do Nothing", new NothingAuto());
autoChooser.addOption("Do Nothing", new NothingAuto(swerve));
// autoChooser.addOption("Mid Double Auto", new MidDoubleAuto(swerveDrive));
Shuffleboard.getTab("Autos")
.add("Auto", autoChooser)
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/frc/robot/commands/auto/NothingAuto.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@
import edu.wpi.first.wpilibj2.command.Commands;
import frc.robot.commands.AutoCommand;
import frc.robot.commands.Autos;
import frc.robot.subsystems.swerve.SwerveDrive;

public class NothingAuto extends AutoCommand {
public NothingAuto() {
addCommands(Commands.print("Nothing auto has finished running."));
private Rotation2d startingRot;

public NothingAuto(SwerveDrive swerve) {
this(swerve, Rotation2d.fromDegrees(180));
}

public NothingAuto(SwerveDrive swerve, Rotation2d startingRot) {
this.startingRot = startingRot;
addCommands(
swerve.runSetGyroAngle(startingRot),
Commands.print("Nothing auto has set the current angle to " + startingRot.getDegrees() + " degrees.")
);
addRequirements(swerve);
}

@Override
public Pose2d getStartPose() {
return Autos.getPathPlannerTrajectory("Get Mid Note", Rotation2d.fromDegrees(0)).getInitialPose();
return Autos.getPathPlannerTrajectory("Get Mid Note", startingRot).getInitialPose();
}
}
15 changes: 12 additions & 3 deletions src/main/java/frc/robot/commands/auto/ShootOnly.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
import frc.robot.commands.AutoCommand;
import frc.robot.commands.Autos;
import frc.robot.subsystems.shooter.Shooter;
import frc.robot.subsystems.swerve.SwerveDrive;

public class ShootOnly extends AutoCommand {
public ShootOnly(Shooter shooter) {
private Rotation2d startingRot;

public ShootOnly(SwerveDrive swerve, Shooter shooter) {
this(swerve, shooter, Rotation2d.fromDegrees(180));
}

public ShootOnly(SwerveDrive swerve, Shooter shooter, Rotation2d startingRot) {
this.startingRot = startingRot;
addCommands(
swerve.runSetGyroAngle(startingRot),
Autos.runSpeakerShot(shooter)
);
addRequirements(shooter);
addRequirements(swerve, shooter);
}

@Override
public Pose2d getStartPose() {
return Autos.getPathPlannerTrajectory("Get Mid Note", Rotation2d.fromDegrees(180)).getInitialPose();
return Autos.getPathPlannerTrajectory("Get Mid Note", startingRot).getInitialPose();
}
}
14 changes: 11 additions & 3 deletions src/main/java/frc/robot/commands/auto/SpeakerBack.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ public class SpeakerBack extends AutoCommand {
public SpeakerBack(SwerveDrive swerve, Shooter shooter) {
addCommands(
Autos.runSpeakerShot(shooter),
swerve.runSetGyroAngle(Rotation2d.fromDegrees(180)),
new WaitCommand(1),
Commands.runOnce(() -> {
swerve.rawDriveInputs(0, -2, 0, false, false);
swerve.rawDriveInputs(0, 2, 0, false, false);
}, swerve),
new WaitCommand(0.7),
Commands.runOnce(() -> {
swerve.rawDriveInputs(0, 0, 0, false, false);
Commands.run(() -> {
swerve.rawDriveInputs(0, 0, -1.5, false, false);
System.out.println(Math.abs(swerve.getRotation2d().getDegrees() % 360));
}, swerve)
.until(() ->
(Math.abs(swerve.getRotation2d().getDegrees() % 360) < 5)
)
.andThen(() -> {
swerve.rawDriveInputs(0, 0, 0, false, false);
}, swerve)
);
addRequirements(swerve, shooter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public enum ShooterPosition {
FLAT("FLAT", 19.5),
AMP("AMP", 90), // prev 108.7
SPEAKER("SPEAKER", 62.9),
SPEAKER("SPEAKER", 64),
SOURCE("SOURCE", 49);
// amp or speaker shooting method adjusted if needed could work for trap

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/frc/robot/subsystems/swerve/SwerveDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ public Command runZeroGyro() {
gyro.reset();
});
}

public Command runSetGyroAngle(Rotation2d rot) { // ccw+ ?
return runOnce(() -> {
gyro.setYaw(rot.getDegrees());
});
}

public Command runSetSpeedFactor(double factor) {
return runOnce(() -> {
Expand Down Expand Up @@ -408,6 +414,10 @@ public SwerveDriveKinematics getSwerveKinematics() {
public Pose2d getPose() {
return swerveOdometry.getEstimatedPosition();
}

public Rotation2d getRotation2d() {
return gyro.getRotation2d();
}

public ChassisSpeeds getRobotRelativeChassisSpeeds() {
return SwerveConstants.kSwerveKinematics.toChassisSpeeds(getModuleStates());
Expand Down

0 comments on commit c82950a

Please sign in to comment.