Skip to content

Commit

Permalink
cleaned out some commands
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiggy committed Jul 11, 2024
1 parent adc9314 commit 5e8ad18
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 224 deletions.
5 changes: 2 additions & 3 deletions src/main/java/org/carlmontrobotics/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,15 @@ private void setBindingsDriver() {

new POVButton(driverController, 0)
.whileTrue(new ParallelCommandGroup(new Intake(intakeShooter),
new AutoMATICALLYGetNote(drivetrain, limelight,
intakeShooter)));
new AutoMATICALLYGetNote(drivetrain, limelight)));

axisTrigger(driverController, Axis.kLeftTrigger)
// .onTrue(new AlignToApriltag(drivetrain, limelight));
.onTrue(new InstantCommand(() -> drivetrain.setFieldOriented(false)))
.onFalse(new InstantCommand(() -> drivetrain.setFieldOriented(true)));

axisTrigger(driverController, Manipulator.SHOOTER_BUTTON)
.whileTrue(new AlignToApriltagMegatag2(drivetrain, limelight));
.whileTrue(new AlignToApriltag(drivetrain, limelight));
new JoystickButton(driverController, Driver.rotateFieldRelative0Deg).onTrue(
new RotateToFieldRelativeAngle(Rotation2d.fromDegrees(0), drivetrain));
new JoystickButton(driverController, Driver.rotateFieldRelative90Deg)
Expand Down
62 changes: 30 additions & 32 deletions src/main/java/org/carlmontrobotics/commands/AimArmSpeaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,34 @@
import edu.wpi.first.wpilibj2.command.Command;

public class AimArmSpeaker extends Command {
private final Arm arm;
private final Limelight ll;

/** Creates a new AimOuttakeSpeaker. */
public AimArmSpeaker(Arm arm, Limelight ll) {
// Use addRequirements() here to declare subsystem dependencies.
addRequirements(this.arm = arm);
this.ll = ll;
}


// Called when the command is initially scheduled.
@Override
public void initialize() {
double goal = ll.getOptimizedArmAngleRadsMT2();
arm.setArmTarget(goal);
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return arm.armAtSetpoint();
}
private final Arm arm;
private final Limelight ll;

/** Creates a new AimOuttakeSpeaker. */
public AimArmSpeaker(Arm arm, Limelight ll) {
// Use addRequirements() here to declare subsystem dependencies.
addRequirements(this.arm = arm);
this.ll = ll;
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
double goal = ll.getOptimizedArmAngleRadsMT2();
arm.setArmTarget(goal);
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return arm.armAtSetpoint();
}
}
44 changes: 0 additions & 44 deletions src/main/java/org/carlmontrobotics/commands/AimArmSpeakerMT2.java

This file was deleted.

33 changes: 24 additions & 9 deletions src/main/java/org/carlmontrobotics/commands/AlignToApriltag.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;

public class AlignToApriltag extends Command {
Expand All @@ -21,18 +22,25 @@ public class AlignToApriltag extends Command {
public final Drivetrain drivetrain;
private Limelight limelight;

public final PIDController rotationPID = new PIDController(thetaPIDController[0], thetaPIDController[1],
thetaPIDController[2]);
public final PIDController rotationPID = new PIDController(
SmartDashboard.getNumber("apriltag align kp",
thetaPIDController[0]),
SmartDashboard.getNumber("apriltag align ki",
thetaPIDController[1]),
SmartDashboard.getNumber("apriltag align kd",
thetaPIDController[2]));

public AlignToApriltag(Drivetrain drivetrain, Limelight limelight) {
this.limelight = limelight;
this.limelight = limelight;
this.drivetrain = drivetrain;
this.teleopDrive = (TeleopDrive) drivetrain.getDefaultCommand();

rotationPID.enableContinuousInput(-180, 180);
Rotation2d targetAngle = Rotation2d.fromDegrees(drivetrain.getHeading())
.minus(Rotation2d.fromRadians(limelight.getRotateAngleRad()));
rotationPID.setSetpoint(MathUtil.inputModulus(targetAngle.getDegrees(), -180, 180));
.plus(Rotation2d.fromRadians(
limelight.getRotateAngleRadMT2()));
rotationPID.setSetpoint(MathUtil.inputModulus(targetAngle.getDegrees(),
-180, 180));
rotationPID.setTolerance(positionTolerance[2], velocityTolerance[2]);
SendableRegistry.addChild(this, rotationPID);
addRequirements(drivetrain);
Expand All @@ -41,14 +49,21 @@ public AlignToApriltag(Drivetrain drivetrain, Limelight limelight) {
@Override
public void execute() {
Rotation2d targetAngle = Rotation2d.fromDegrees(drivetrain.getHeading())
.minus(Rotation2d.fromRadians(limelight.getRotateAngleRad()));
rotationPID.setSetpoint(MathUtil.inputModulus(targetAngle.getDegrees(), -180, 180));
.plus(Rotation2d.fromRadians(
limelight.getRotateAngleRadMT2()));
rotationPID.setSetpoint(MathUtil.inputModulus(targetAngle.getDegrees(),
-180, 180));
double rotationDrive = rotationPID.calculate(drivetrain.getHeading());
if (!limelight.seesTag()) {
rotationDrive = 0;
}

if (teleopDrive == null)
drivetrain.drive(0, 0, rotationPID.calculate(drivetrain.getHeading()));
drivetrain.drive(0, 0, rotationDrive);
else {
double[] driverRequestedSpeeds = teleopDrive.getRequestedSpeeds();
drivetrain.drive(driverRequestedSpeeds[0], driverRequestedSpeeds[1],
rotationPID.calculate(drivetrain.getHeading()));
rotationDrive);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ public class AutoMATICALLYGetNote extends Command {
Timer timer = new Timer();
private IntakeShooter intake;

public AutoMATICALLYGetNote(Drivetrain dt, Limelight ll,
IntakeShooter intake) {
public AutoMATICALLYGetNote(Drivetrain dt, Limelight ll) {
addRequirements(this.dt = dt);
this.ll = ll;
this.intake = intake;
//addRequirements(this.effector = effector);
// Use addRequirements() here to declare subsystem dependencies.
}
Expand All @@ -51,6 +49,11 @@ public void execute() {
double forwardDistErrMeters = ll.getDistanceToNoteMeters();
double strafeDistErrMeters = forwardDistErrMeters * Math.tan(angleErrRad);

forwardDistErrMeters = Math.max(
forwardDistErrMeters
* SmartDashboard.getNumber("forward speed multiplier", 1.5),
MIN_MOVEMENT_METERSPSEC);

if (LimelightHelpers.getTV(INTAKE_LL_NAME)) {
dt.drive(forwardDistErrMeters, strafeDistErrMeters, angleErrRad);
}
Expand Down Expand Up @@ -108,6 +111,6 @@ public void end(boolean interrupted) {
// Returns true when the command should end.
@Override
public boolean isFinished() {
return intake.intakeDetectsNote();
return intake.outtakeDetectsNote();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;

public class RotateToFieldRelativeAngle extends Command {
Expand Down
Loading

0 comments on commit 5e8ad18

Please sign in to comment.