Skip to content

Commit

Permalink
FLR Day 1 Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
asun121 committed Mar 11, 2022
1 parent 4e8c3e0 commit 95bc554
Show file tree
Hide file tree
Showing 20 changed files with 319 additions and 78 deletions.
47 changes: 28 additions & 19 deletions src/main/java/org/team639/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.TreeMap;

import org.team639.auto.*;
import org.team639.commands.AimbotLED;
import org.team639.commands.Acquisition.*;
import org.team639.commands.Climber.ToggleClimber;
import org.team639.commands.Drive.*;
Expand Down Expand Up @@ -56,8 +57,7 @@ public class RobotContainer {
private final JoystickDrive joystickDrive = new JoystickDrive(driveTrain);
private final ToggleGears shiftGears = new ToggleGears(driveTrain);
private final ReverseHeading swap = new ReverseHeading(driveTrain);
private final TurnToAngleRelative aimbot = new TurnToAngleRelative(driveTrain);
public final TurnToBall turnToBall = new TurnToBall(driveTrain);
//public final TurnToBall turnToBall = new TurnToBall(driveTrain);

// Acquisition
private final ToggleAcquisition toggleAcquisition = new ToggleAcquisition(acquisition);
Expand All @@ -69,8 +69,12 @@ public class RobotContainer {
// Shooter
private final ShootClosedLoop fenderShot = new ShootClosedLoop(indexer, shooter, acquisition,
Constants.ShooterConstants.fenderRPM, Constants.ShooterConstants.fenderAngle);
private final AutoShootAtDistance autoShoot = new AutoShootAtDistance(indexer, shooter, acquisition);


private final ShootClosedLoop lowShot = new ShootClosedLoop(indexer, shooter, acquisition,
2000, 0.2);
private final ToggleActuator resetHood = new ToggleActuator(shooter);
private final AimbotLED locked = new AimbotLED(candle);

//Climber
private final ToggleClimber toggleClimb = new ToggleClimber(climb);
Expand Down Expand Up @@ -197,18 +201,22 @@ private void configureButtonBindings() {
ControllerWrapper.DriverRightBumper.whenPressed(shiftGears);
ControllerWrapper.DriverLeftBumper.whenPressed(swap);
ControllerWrapper.DriverButtonA.whenHeld(new DJRobot(driveTrain, 10));
ControllerWrapper.DriverButtonX.whenPressed(aimbot.withTimeout(1));
ControllerWrapper.DriverButtonX.whenPressed(new TurnToAngleRelative(driveTrain).withTimeout(1));
ControllerWrapper.DriverButtonY.whenPressed(tele.aimbotshot);
ControllerWrapper.DriverButtonB.whenPressed(turnToBall);
//ControllerWrapper.DriverButtonB.whenPressed(turnToBall.withTimeout(1));

// Controller


ControllerWrapper.ControlRightBumper.whenHeld(index);
ControllerWrapper.ControlLeftBumper.whenHeld(eject);

ControllerWrapper.ControlButtonY.whenPressed(fenderShot);
ControllerWrapper.ControlButtonB.whenPressed(toggleAcquisition);
ControllerWrapper.ControlButtonX.whenPressed(autoShoot);
ControllerWrapper.ControlButtonX.whenPressed(tele.aimbotshot);
ControllerWrapper.ControlButtonA.whenPressed(toggleClimb);
ControllerWrapper.ControlDPadRight.whenPressed(lowShot);
ControllerWrapper.ControlDPadLeft.whenPressed(new AutoShootAtDistance(indexer, shooter, acquisition, candle));

// RESET BUTTONS
ControllerWrapper.ControlDPadUp.whenPressed(resetHood);
Expand Down Expand Up @@ -238,7 +246,7 @@ public Command getAutonomousCommand() {
auto = auton.ShootMove;
break;
case FourBall:
auto = auton.fourBall_v2;
auto = auton.fourBall_v2_optimized;
break;
case BounceTest:
auto = auton.bounceTest;
Expand All @@ -252,10 +260,11 @@ public Command getAutonomousCommand() {
*/
public void defaultCommands() {
CommandScheduler.getInstance().setDefaultCommand(driveTrain, joystickDrive);
CommandScheduler.getInstance().setDefaultCommand(candle, locked);
}

class TeleopRoutines {
final ParallelRaceGroup aimbotshot = new ParallelRaceGroup(aimbot, autoShoot);
final ParallelCommandGroup aimbotshot = new ParallelCommandGroup(new TurnToAngleRelative(driveTrain).withTimeout(1), new AutoShootAtDistance(indexer, shooter, acquisition, candle));
}

class AutonomousRoutines {
Expand All @@ -269,8 +278,8 @@ class AutonomousRoutines {
new DriveRamsete(driveTrain, "bounce3"));

final SequentialCommandGroup ShootMove = new SequentialCommandGroup(
new ShootAtDistance(indexer, shooter, acquisition, 2),
new DriveRamsete(driveTrain, "2BallAutonomousPart3")
new ShootAtDistance(indexer, shooter, acquisition, candle, 2),
new DriveRamsete(driveTrain, "2BallAutonomous")
);

// Start Position: 7.635, 1.786 - Facing bottom team ball, bumpers against the
Expand All @@ -280,12 +289,12 @@ class AutonomousRoutines {
new WaitCommand(0.5),
new ParallelRaceGroup(new DriveRamsete(driveTrain, "4BallPart1").robotRelative(),
new ManualIndexer(shooter, indexer, acquisition)),
new ShootAtDistance(indexer, shooter, acquisition, 2.432373),
new ShootAtDistance(indexer, shooter, acquisition, candle, 2.432373),
new DriveRamsete(driveTrain, "4BallPart2").robotRelative(),
new ParallelRaceGroup(new DriveRamsete(driveTrain, "4BallPart3").robotRelative(),
new ManualIndexer(shooter, indexer, acquisition)),
new DriveRamsete(driveTrain, "4BallPart4").robotRelative(),
new ShootAtDistance(indexer, shooter, acquisition, 5));
new ShootAtDistance(indexer, shooter, acquisition, candle, 5));

// Start Position: 6.44, 2.62 - Side of bumpers lined up against the tarmac,
// with the front edge facing touching the front tarmac
Expand All @@ -298,18 +307,18 @@ class AutonomousRoutines {
new ManualIndexer(shooter, indexer, acquisition).withTimeout(0.75),
new ParallelCommandGroup(new DriveRamsete(driveTrain, "4Ball_v2Part3"),
new ManualIndexer(shooter, indexer, acquisition).withTimeout(.2)),
new ParallelCommandGroup(aimbot, new ShootAtDistance(indexer, shooter, acquisition, 3.5)));
new ShootAtDistance(indexer, shooter, acquisition, candle, 3.5));

final SequentialCommandGroup fourBall_v2_optimized = new SequentialCommandGroup(
new WaitCommand(0.5),
new ParallelCommandGroup(new DriveRamsete(driveTrain, "4Ball_v2Part1Opt"),
new ParallelCommandGroup(new DriveRamsete(driveTrain, "4BALLTRUE1"),
new ShootAtDistanceTimed(indexer, shooter, acquisition, 3.5, 1700)),
new ParallelRaceGroup(new DriveRamsete(driveTrain, "4Ball_v2Part2Opt"),
new ParallelRaceGroup(new DriveRamsete(driveTrain, "4BALLTRUE2"),
new ManualIndexer(shooter, indexer, acquisition)),
new ManualIndexer(shooter, indexer, acquisition).withTimeout(0.75),
new ParallelCommandGroup(new DriveRamsete(driveTrain, "4Ball_v2Part3Opt"),
new ParallelCommandGroup(new DriveRamsete(driveTrain, "4BALLTRUE3"),
new ManualIndexer(shooter, indexer, acquisition).withTimeout(.5)),
new ParallelCommandGroup(aimbot, new ShootAtDistance(indexer, shooter, acquisition, 3.5)));
new ParallelCommandGroup(new TurnToAngleRelative(driveTrain).withTimeout(1),new ShootAtDistance(indexer, shooter, acquisition, candle, 3.5)));

// Coding gods, take the wheel
final SequentialCommandGroup fiveBall = new SequentialCommandGroup(
Expand All @@ -332,7 +341,7 @@ class AutonomousRoutines {
new ManualIndexer(shooter, indexer, acquisition)),
new ParallelRaceGroup(new DriveRamsete(driveTrain, "2BallAutonomousPart2").robotRelative(),
new ManualIndexer(shooter, indexer, acquisition)),
new ShootAtDistance(indexer, shooter, acquisition, 2));
new ShootAtDistance(indexer, shooter, acquisition, candle, 1.5));

// Start Position: Middle ball of 2 ball autonomous - Bumpers pushed against tarmac, facing
// team ball
Expand All @@ -342,7 +351,7 @@ class AutonomousRoutines {
new ManualIndexer(shooter, indexer, acquisition)),
new ParallelRaceGroup(new DriveRamsete(driveTrain, "2BallAutonomousPart2").robotRelative(),
new ManualIndexer(shooter, indexer, acquisition)),
new ShootAtDistance(indexer, shooter, acquisition, 2),
new ShootAtDistance(indexer, shooter, acquisition, candle, 1.5),
new DriveRamsete(driveTrain, "2BallAutonomousPart3"));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ToggleAcquisition(Acquisition acquisition) {
@Override
public void initialize() {
if(acquisition.acqPos().equals(AcquisitionPosition.up))
acquisition.acquisitionNeutral();
acquisition.acquisitionDown();
else
acquisition.acquisitionUp();
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/team639/commands/AimbotLED.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package org.team639.commands;

import org.team639.subsystems.LED;

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

public class AimbotLED extends CommandBase {
private LED led;
/** Creates a new AimbotLED. */
public AimbotLED(LED led) {
// Use addRequirements() here to declare subsystem dependencies.
this.led = led;
addRequirements(led);
}

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

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
85 changes: 85 additions & 0 deletions src/main/java/org/team639/commands/Drive/ChaseBall.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package org.team639.commands.Drive;

import org.team639.Robot;
import org.team639.RobotContainer;
import org.team639.controlboard.ControllerWrapper;
import org.team639.lib.Constants;
import org.team639.lib.states.AllianceColor;
import org.team639.lib.states.GearMode;
import org.team639.subsystems.DriveTrain;

import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.wpilibj2.command.CommandBase;

public class ChaseBall extends CommandBase {
private DriveTrain driveTrain;
private double setpoint;

private double angle;
private boolean clockwise;

private GearMode lastGear;
private PIDController controller = new PIDController(Constants.AutoConstants.autoRotateP,
Constants.AutoConstants.autoRotateI, Constants.AutoConstants.autoRotateD);

/**
* Chases a ball using visions with a variable setpoint. Should be called when held
* @param driveTrain DriveTrain to use
*/
public ChaseBall(DriveTrain driveTrain) {
this.driveTrain = driveTrain;
addRequirements(driveTrain);
}

public double getSetpoint()
{
angle = RobotContainer.getAllianceColor().equals(AllianceColor.blue) ? Robot.getAngleToBallBlue() % 360.0 : Robot.getAngleToBallRed();
return driveTrain.getHeading() + angle;
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
lastGear = driveTrain.getGearMode();
//angle = RobotContainer.getAllianceColor().equals(AllianceColor.blue) ? Robot.getAngleToBallBlue() % 360.0 : Robot.getAngleToBallRed();
//setpoint = clockwise ? Math.abs(angle) + driveTrain.getHeading() : driveTrain.getHeading() - Math.abs(angle);
clockwise = Math.signum(getSetpoint()) > 0 ? true : false;

controller.setTolerance(Constants.AutoConstants.autoRotateThreshHold,
Constants.AutoConstants.autoRotateThreshHoldVelo);
controller.setSetpoint(getSetpoint());

driveTrain.setSpeedsPercent(0, 0);
if (lastGear.equals(GearMode.high))
driveTrain.toggleGearLow();
System.out.println("Auto rotate initializing");
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
clockwise = Math.signum(getSetpoint()) > 0 ? true : false;
if (clockwise)
driveTrain.PIDLinearInput(ControllerWrapper.DriverController.getLeftY(),controller.calculate(driveTrain.getHeading(), setpoint));
else
driveTrain.PIDLinearInput(ControllerWrapper.DriverController.getLeftY(),-controller.calculate(driveTrain.getHeading(), setpoint));
}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
driveTrain.setSpeedsPercent(0, 0);
if (lastGear.equals(GearMode.high))
driveTrain.toggleGearHigh();
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
7 changes: 5 additions & 2 deletions src/main/java/org/team639/commands/Drive/JoystickDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ public void arcadeDrive(double speed, double turnValue) {
turnMultiplier = 1d / 3d;
if (turnMultiplier > 2d / 3d)
turnMultiplier = 2d / 3d;
turnValue = turnValue * turnMultiplier;
turnValue = turnValue * turnMultiplier * Constants.DriveConstants.rawTurnMultiplier;

double left = speed + turnValue;
double right = speed - turnValue;
//driveTrain.setSpeedsPercent(left, right);

driveTrain.setSpeedsPercent(left * Constants.DriveConstants.driveMultiplier, right * Constants.DriveConstants.driveMultiplier);
//Sets the robot to low speed mode is the left trigger is held
double true_multiplier = ControllerWrapper.DriverLeftTrigger.get() ? Constants.DriveConstants.driveLowSpeed : Constants.DriveConstants.driveMultiplier;

driveTrain.setSpeedsPercent(left * true_multiplier, right * true_multiplier);
}

public void tankDrive(double leftSpeed, double rightSpeed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public void initialize() {
@Override
public void execute() {
if (clockwise)
driveTrain.turnCommandR(controller.calculate(driveTrain.getHeading(), setpoint));
driveTrain.turnCommandR(controller.calculate(driveTrain.getHeading(), setpoint) + Constants.DriveConstants.kRelFric);
else
driveTrain.turnCommandL(-controller.calculate(driveTrain.getHeading(), setpoint));
driveTrain.turnCommandL(-controller.calculate(driveTrain.getHeading(), setpoint) + Constants.DriveConstants.kRelFric);
}

// Called once the command ends or is interrupted.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/team639/commands/Drive/TurnToBall.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TurnToBall extends CommandBase {
Constants.AutoConstants.autoRotateI, Constants.AutoConstants.autoRotateD);

/**
* Creates relative turn to angle that uses vision tracking
* Creates relative turn to ball that uses vision tracking
* @param driveTrain DriveTrain to use
*/
public TurnToBall(DriveTrain driveTrain) {
Expand All @@ -38,7 +38,7 @@ public TurnToBall(DriveTrain driveTrain) {
@Override
public void initialize() {
lastGear = driveTrain.getGearMode();
angle = RobotContainer.getAllianceColor().equals(AllianceColor.blue) ? Robot.getAngleToBallBlue() % 360.0 : Robot.getAngleToBallRed();
angle = RobotContainer.getAllianceColor().equals(AllianceColor.blue) ? Robot.getAngleToBallBlue() % 360.0 : Robot.getAngleToBallRed() % 360.0;
clockwise = Math.signum(angle) > 0 ? true : false;
//setpoint = clockwise ? Math.abs(angle) + driveTrain.getHeading() : driveTrain.getHeading() - Math.abs(angle);
setpoint = driveTrain.getHeading() + angle;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/team639/commands/Indexer/SpitCargo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public SpitCargo(Shooter shooter, Indexer indexer, Acquisition acquisition) {
// Called when the command is initially scheduled.
@Override
public void initialize() {
acquisition.acquisitionNeutral();
//acquisition.acquisitionNeutral();
acquisition.acquisitionDown();
}

// Called every time the scheduler runs while the command is scheduled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@

import edu.wpi.first.wpilibj2.command.CommandBase;
import org.team639.Robot;
import org.team639.controlboard.ControllerWrapper;
import org.team639.lib.Constants;
import org.team639.lib.math.AngleSpeed;
import org.team639.lib.math.ValueFromDistance;
import org.team639.subsystems.Acquisition;
import org.team639.subsystems.Indexer;
import org.team639.subsystems.LED;
import org.team639.subsystems.Shooter;

public class AutoShootAtDistance extends CommandBase {
private Indexer indexer;
private Shooter shooter;
private Acquisition acquisition;
private LED led;

private long startTime;
private AngleSpeed shootAngleSpeed;

public AutoShootAtDistance(Indexer indexer, Shooter shooter, Acquisition acquisition) {
public AutoShootAtDistance(Indexer indexer, Shooter shooter, Acquisition acquisition, LED led) {
this.indexer = indexer;
this.shooter = shooter;
this.acquisition = acquisition;
addRequirements(indexer, shooter, acquisition);
this.led = led;
addRequirements(indexer, shooter, acquisition, led);

}

Expand All @@ -41,7 +45,9 @@ public void initialize() {
shooter.setSpeed(Constants.ShooterConstants.reverseIndexSpeed);
indexer.setIndexMotor(-Constants.IndexerConstants.indexMotorSpeed);

acquisition.acquisitionNeutral();
//acquisition.acquisitionNeutral();
acquisition.acquisitionDown();
led.redFlare();
}

@Override
Expand All @@ -57,6 +63,11 @@ public void execute() {
indexer.setIndexMotor(Constants.IndexerConstants.indexMotorSpeed);
acquisition.spinAcquisition(Constants.AcquisitionConstants.acquisitionSpeedSlow);
}

if(ControllerWrapper.DriverRightTrigger.get() || ControllerWrapper.ControllerRightTrigger.get())
{
end(true);
}
}

@Override
Expand Down
Loading

0 comments on commit 95bc554

Please sign in to comment.