Skip to content

Commit

Permalink
Dcm pfixing auto intaking (#174)
Browse files Browse the repository at this point in the history
* changed command structure off intake and raising arm command

* changed auto to start after intake command during rase arm to insert it into preveous cycle. FIxed issue where the intake was "too fast" and reflective sensor was triggering seemingly earlier in auto

* spot :/
  • Loading branch information
LucasPowellRiedl authored Apr 5, 2024
1 parent 66fdb26 commit ade03f3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{
"type": "named",
"data": {
"name": "raiseArmAndWaitWhileAdvancingPiece"
"name": "raiseArmAndWait"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/main/deploy/pathplanner/autos/B-TwoPieceFar1.auto
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
{
"type": "named",
"data": {
"name": "raiseArmAndWaitWhileAdvancingPiece"
"name": "raiseArmAndWait"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/deploy/pathplanner/autos/R-TheTwoPieceNear.auto
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{
"type": "named",
"data": {
"name": "raiseArmAndWaitWhileAdvancingPiece"
"name": "raiseArmAndWait"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{
"type": "named",
"data": {
"name": "raiseArmAndWaitWhileAdvancingPiece"
"name": "raiseArmAndWait"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/main/deploy/pathplanner/autos/R-TwoPieceFar1.auto
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
{
"type": "named",
"data": {
"name": "raiseArmAndWaitWhileAdvancingPiece"
"name": "raiseArmAndWait"
}
},
{
Expand Down
33 changes: 18 additions & 15 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ private void createNamedCommands() {
NamedCommands.registerCommand("raiseArmAndWait",
m_arm.createDeployCommand()
.andThen(new WaitCommand(1.8)));

NamedCommands.registerCommand("raiseArmAndWaitWhileAdvancingPiece",
m_arm.createDeployCommand().alongWith(m_intake.createSetVelocityCommand(0.5))
.andThen(new WaitCommand(1.8)).andThen(m_intake.createStopIntakeCommand()));

NamedCommands.registerCommand("resetArmAndIntake",
m_arm.createStowCommand()
Expand All @@ -259,8 +255,11 @@ private void createNamedCommands() {
.withTimeout(0.7));

NamedCommands.registerCommand("intakePiece",
createAutoIntakeCommandSequence()
);
m_arm.createStowCommand()
.andThen(m_intake.createIntakeCommand()).until(m_intake.hasNote)
.andThen(m_arm.createCarryCommand()
.alongWith(m_intake.createAdvanceAfterIntakingCommand()))
);

NamedCommands.registerCommand("stopIntake",
m_intake.createStopIntakeCommand());
Expand Down Expand Up @@ -288,16 +287,18 @@ private void configureDriverButtonBindings() {
new JoystickButton(m_driver,OIConstants.kZorroAIn)
.whileTrue((new ZorroDriveCommand(m_swerve, DriveConstants.kDriveKinematicsDriveFromArm, m_driver)));


Trigger armDeployed = new Trigger(m_arm.stateChecker(ArmState.DEPLOYED));
JoystickButton D_Button = new JoystickButton(m_driver, OIConstants.kZorroDIn);

// Reverse intake to outake or reject intaking Note
D_Button.and(armDeployed.negate())
.whileTrue(m_arm.createStowCommand().andThen(new WaitCommand(0.2).andThen(m_intake.createOuttakeToFloorCommand())));
// Shoot Note into Amp
.whileTrue(m_arm.createStowCommand()
.andThen(new WaitCommand(0.2)
.andThen(m_intake.createOuttakeToFloorCommand())));

// Shoot Note into Amp
D_Button.and(armDeployed)
.whileTrue(m_intake.createOuttakeToAmpCommand());
.whileTrue(m_intake.createOuttakeToAmpCommand());
}
// spotless:on

Expand All @@ -307,7 +308,6 @@ private void configureOperatorButtonBindings() {
JoystickButton leftBumper = new JoystickButton(m_operator, Button.kLeftBumper.value);
JoystickButton leftJoystickDown = new JoystickButton(m_operator, Button.kLeftStick.value);

Trigger hasNote = new Trigger(m_intake.eitherSensorSupplier());
Trigger armDeployed = new Trigger(m_arm.stateChecker(ArmState.DEPLOYED));

// CLIMBER
Expand All @@ -333,16 +333,19 @@ private void configureOperatorButtonBindings() {
// Control position of Note in intake
Trigger leftStick = new Trigger(() -> Math.abs(m_operator.getLeftY()) > 0.2);
//While arm is down
leftStick.and(armDeployed.negate()).whileTrue(m_intake.createJoystickControlCommand(m_operator, IntakeConstants.kRepositionSpeedArmDown));
leftStick.and(armDeployed.negate())
.whileTrue(m_intake.createJoystickControlCommand(m_operator, IntakeConstants.kRepositionSpeedArmDown));

//While arm is up
leftStick.and(armDeployed).whileTrue(m_intake.createJoystickControlCommand(m_operator, IntakeConstants.kRepositionSpeedArmUp));
leftStick.and(armDeployed)
.whileTrue(m_intake.createJoystickControlCommand(m_operator, IntakeConstants.kRepositionSpeedArmUp));

// Intake Note from floor
rightBumper.and(hasNote.negate())
rightBumper.and(m_intake.hasNote.negate())
.whileTrue(m_arm.createStowCommand()
.andThen(m_intake.createIntakeCommand()));

hasNote.and(m_intake.stateChecker(IntakeState.INTAKING)).and(() -> RobotState.isTeleop())
m_intake.hasNote.and(m_intake.stateChecker(IntakeState.INTAKING)).and(() -> RobotState.isTeleop())
.onTrue(m_arm.createCarryCommand()
.andThen(m_intake.createAdvanceAfterIntakingCommand().withInterruptBehavior(InterruptionBehavior.kCancelIncoming)));

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/frc/robot/intake/Intake.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.FunctionalCommand;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.Constants.IntakeConstants;
import frc.robot.Constants.IntakeConstants.IntakeState;
import java.util.function.BooleanSupplier;
Expand Down Expand Up @@ -61,6 +62,7 @@ public Intake() {
m_velocityController.setD(IntakeConstants.kVelocityD);

m_positionController.setTolerance(IntakeConstants.kPositionTolerance);
m_positionController.setGoal(17);

m_relativeEncoder = m_motor.getEncoder();
m_relativeEncoder.setPosition(0.0);
Expand Down Expand Up @@ -88,23 +90,30 @@ public Command createStopIntakeCommand() {
}

private void configurePositionController(double targetPosition) {
SmartDashboard.putNumber("ResetBeam", 1);
m_positionController.reset(m_relativeEncoder.getPosition(), m_relativeEncoder.getVelocity());
m_positionController.setGoal(m_relativeEncoder.getPosition() + targetPosition);
m_positionController.calculate(m_relativeEncoder.getPosition());
}

// spotless:off
private void advanceAfterIntaking(double targetPosition) {
m_secondSensorTriggered.rising().ifHigh(
() -> {
SmartDashboard.putNumber("RealativeEncoderReset", 0);
m_positionController.reset(
m_relativeEncoder.getPosition(), m_relativeEncoder.getVelocity());
SmartDashboard.putNumber("RealativeEncoderReset", 1);
m_positionController.setGoal(m_relativeEncoder.getPosition() + targetPosition);
SmartDashboard.putNumber("RealativeEncoderReset", 2);
});
setState(IntakeState.PROCESSING);
m_motor.set(m_positionController.calculate(m_relativeEncoder.getPosition()));
}
// spotless:on

public Trigger hasNote = new Trigger(this.eitherSensorSupplier());

public Command createIntakeCommand() {
return this.run(
() -> {
Expand Down Expand Up @@ -182,6 +191,8 @@ public void periodic() {
SmartDashboard.putNumber(
"IntakeSensorRetroReflective", !m_noteSensorRetroReflective.get() ? 1d : 0d);
SmartDashboard.putNumber("IntakeSensorBeamBreak", !m_noteSensorBeamBreak.get() ? 1d : 0d);
SmartDashboard.putNumber("RealativeEncoderReset", -1);
SmartDashboard.putNumber("ResetBeam", -1);

if (m_state != null) SmartDashboard.putString("Intake State", m_state.name());
}
Expand Down

0 comments on commit ade03f3

Please sign in to comment.