Skip to content

Commit

Permalink
Merge pull request #8 from StuyPulse/automations
Browse files Browse the repository at this point in the history
Automations
  • Loading branch information
IanShiii authored Feb 11, 2025
2 parents 9d5b368 + 358fe83 commit 23c9359
Show file tree
Hide file tree
Showing 26 changed files with 334 additions and 438 deletions.
68 changes: 45 additions & 23 deletions src/main/java/com/stuypulse/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.stuypulse.robot;

import com.stuypulse.robot.commands.SeedFieldRelative;
import com.stuypulse.robot.commands.auton.EDCB.FourPieceEDCB;
import com.stuypulse.robot.commands.auton.EDCB.OnePieceE;
import com.stuypulse.robot.commands.auton.EDCB.ThreeHalfPieceEDC;
Expand All @@ -24,15 +25,18 @@
import com.stuypulse.robot.commands.auton.tests.SquareTest;
import com.stuypulse.robot.commands.auton.tests.StraightLineTest;
import com.stuypulse.robot.commands.elevator.ElevatorToBottom;
import com.stuypulse.robot.commands.elevator.ElevatorToLvl1;
import com.stuypulse.robot.commands.elevator.ElevatorToFeed;
import com.stuypulse.robot.commands.elevator.ElevatorToLvl2;
import com.stuypulse.robot.commands.elevator.ElevatorToLvl3;
import com.stuypulse.robot.commands.elevator.ElevatorToLvl4;
import com.stuypulse.robot.commands.funnel.FunnelDeacquire;
import com.stuypulse.robot.commands.funnel.FunnelStop;
import com.stuypulse.robot.commands.elevator.ElevatorWaitUntilAtTargetHeight;
import com.stuypulse.robot.commands.funnel.FunnelDefaultCommand;
import com.stuypulse.robot.commands.shooter.ShooterAcquire;
import com.stuypulse.robot.commands.shooter.ShooterShoot;
import com.stuypulse.robot.commands.shooter.ShooterStop;
import com.stuypulse.robot.commands.swerve.SwerveDriveDrive;
import com.stuypulse.robot.commands.swerve.SwerveDriveDriveAlignedToNearestCoralStation;
import com.stuypulse.robot.commands.swerve.SwerveDrivePIDToNearestBranch;
import com.stuypulse.robot.commands.swerve.SwerveDrivePIDToPose;
import com.stuypulse.robot.constants.Field;
import com.stuypulse.robot.constants.Ports;
Expand All @@ -49,6 +53,8 @@
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.ConditionalCommand;
import edu.wpi.first.wpilibj2.command.InstantCommand;


public class RobotContainer {
Expand Down Expand Up @@ -82,6 +88,8 @@ public RobotContainer() {

private void configureDefaultCommands() {
swerve.setDefaultCommand(new SwerveDriveDrive(driver));
funnel.setDefaultCommand(new FunnelDefaultCommand());
shooter.setDefaultCommand(new ShooterAcquire().onlyIf(() -> !shooter.hasCoral()));
}

/***************/
Expand All @@ -90,32 +98,46 @@ private void configureDefaultCommands() {

private void configureButtonBindings() {

driver.getDPadUp().onTrue(new SeedFieldRelative());

driver.getRightTriggerButton()
.whileTrue(new SwerveDrivePIDToPose(() -> Field.getClosestBranch().getTargetPose()));
.whileTrue(new SwerveDriveDriveAlignedToNearestCoralStation(driver));

driver.getRightBumper()
.onTrue(new ShooterShoot())
.onFalse(new ShooterStop());

// Automated L4
driver.getTopButton()
.whileTrue(new ElevatorToLvl4());
.whileTrue(new ElevatorToLvl4()
// .andThen(new ElevatorWaitUntilAtTargetHeight().alongWith(new SwerveDrivePIDToNearestBranch()))
.andThen(new ElevatorWaitUntilAtTargetHeight())
.andThen(new ShooterShoot())
)
.onFalse(new ElevatorToFeed())
.onFalse(new ShooterStop());

// Automated L3
driver.getRightButton()
.whileTrue(new ElevatorToLvl3());

driver.getLeftButton()
.whileTrue(new ElevatorToLvl2());

.whileTrue(new ElevatorToLvl3()
// .andThen(new ElevatorWaitUntilAtTargetHeight().alongWith(new SwerveDrivePIDToNearestBranch()))
.andThen(new ElevatorWaitUntilAtTargetHeight())
.andThen(new ShooterShoot())
)
.onFalse(new ElevatorToFeed())
.onFalse(new ShooterStop());

// Automated L2
driver.getBottomButton()
.whileTrue(new ElevatorToLvl1());

driver.getDPadDown()
.whileTrue(new ElevatorToBottom());

driver.getDPadUp()
.whileTrue(new FunnelDeacquire());

driver.getLeftBumper()
.whileTrue(new ShooterAcquire());

driver.getRightBumper()
.whileTrue(new ShooterShoot());
.whileTrue(new ElevatorToLvl2()
// .andThen(new ElevatorWaitUntilAtTargetHeight().alongWith(new SwerveDrivePIDToNearestBranch()))
.andThen(new ElevatorWaitUntilAtTargetHeight())
.andThen(new ShooterShoot())
)
.onFalse(new ElevatorToFeed())
.onFalse(new ShooterStop());

driver.getLeftButton().whileTrue(new SwerveDrivePIDToNearestBranch());
}

/**************/
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.stuypulse.robot.commands.funnel;

import com.stuypulse.robot.subsystems.funnel.Funnel;
import com.stuypulse.robot.subsystems.shooter.Shooter;

import edu.wpi.first.wpilibj2.command.Command;

public class FunnelDefaultCommand extends Command{

private final Funnel funnel;

public FunnelDefaultCommand() {
this.funnel = Funnel.getInstance();
addRequirements(funnel);
}

@Override
public void execute() {
if (Shooter.getInstance().hasCoral()) {
funnel.stop();
}
else if (funnel.shouldReverse()) {
funnel.reverse();
}
else {
funnel.acquire();
}
}
}
20 changes: 0 additions & 20 deletions src/main/java/com/stuypulse/robot/commands/funnel/FunnelStop.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public SwerveDriveDrive(Gamepad driver) {

turn = IStream.create(driver::getRightX)
.filtered(
x -> -x,
x -> SLMath.deadband(x, Turn.DEADBAND.get()),
x -> SLMath.spow(x, Turn.POWER.get()),
x -> x * Turn.MAX_TELEOP_TURN_SPEED.get(),
Expand All @@ -55,18 +56,6 @@ private Vector2D getDriverInputAsVelocity() {

@Override
public void execute() {
Vector2D targetVelocity = speed.get();
double omega = turn.get();

ChassisSpeeds currentSpeed = swerve.getChassisSpeeds();
double currentSpeedMagnitude = Math.hypot(currentSpeed.vxMetersPerSecond, currentSpeed.vyMetersPerSecond);

// if (targetVelocity.magnitude() > 0.05 || Math.abs(omega) > 0.05 || currentSpeedMagnitude > 0.05 || Math.abs(currentSpeed.omegaRadiansPerSecond) > 0.05) {
// swerve.drive(speed.get(), turn.get());
// }
// else {
// swerve.setXMode();
// }
swerve.drive(speed.get(), turn.get());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.stuypulse.robot.commands.swerve;

import java.util.function.Supplier;

import com.stuypulse.robot.constants.Settings.Driver.Drive;
import com.stuypulse.robot.constants.Settings.Swerve.Alignment;
import com.stuypulse.robot.subsystems.odometry.Odometry;
import com.stuypulse.robot.subsystems.swerve.SwerveDrive;
import com.stuypulse.stuylib.control.angle.AngleController;
import com.stuypulse.stuylib.control.angle.feedback.AnglePIDController;
import com.stuypulse.stuylib.input.Gamepad;
import com.stuypulse.stuylib.math.Angle;
import com.stuypulse.stuylib.streams.vectors.VStream;
import com.stuypulse.stuylib.streams.vectors.filters.VDeadZone;
import com.stuypulse.stuylib.streams.vectors.filters.VLowPassFilter;
import com.stuypulse.stuylib.streams.vectors.filters.VRateLimit;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj2.command.Command;

public class SwerveDriveDriveAligned extends Command {

private final SwerveDrive swerve;
private final VStream drive;
private final Odometry odometry;

private final AngleController controller;

private final Supplier<Rotation2d> targetAngle;

public SwerveDriveDriveAligned(Gamepad driver, Supplier<Rotation2d> targetAngle) {
swerve = SwerveDrive.getInstance();
odometry = Odometry.getInstance();

this.targetAngle = targetAngle;

drive = VStream.create(driver::getLeftStick)
.filtered(
new VDeadZone(Drive.DEADBAND),
x -> x.clamp(1),
x -> x.pow(Drive.POWER.get()),
x -> x.mul(Drive.MAX_TELEOP_SPEED.get()),
new VRateLimit(Drive.MAX_TELEOP_ACCEL.get()),
new VLowPassFilter(Drive.RC.get()));

controller = new AnglePIDController(Alignment.THETA.kP, Alignment.THETA.kI, Alignment.THETA.kD)
.setOutputFilter(x -> -x);

addRequirements(swerve);
}

public SwerveDriveDriveAligned(Gamepad driver, Rotation2d targetAngle) {
this(driver, () -> targetAngle);
}

@Override
public void execute() {
swerve.drive(
drive.get(),
controller.update(
Angle.fromRotation2d(targetAngle.get()),
Angle.fromRotation2d(odometry.getPose().getRotation())));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.stuypulse.robot.commands.swerve;

import com.stuypulse.robot.constants.Field;
import com.stuypulse.stuylib.input.Gamepad;

public class SwerveDriveDriveAlignedToNearestCoralStation extends SwerveDriveDriveAligned{

public SwerveDriveDriveAlignedToNearestCoralStation(Gamepad driver) {
super(driver, () -> Field.getClosestCoralStationTargetPose().getRotation());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.stuypulse.robot.commands.swerve;

import com.stuypulse.robot.constants.Field;

public class SwerveDrivePIDToNearestBranch extends SwerveDrivePIDToPose{
public SwerveDrivePIDToNearestBranch() {
super(() -> Field.getClosestBranch().getTargetPose());
}
}
Loading

0 comments on commit 23c9359

Please sign in to comment.