Skip to content

Commit

Permalink
add set output methods to scoring to remove activation of motors
Browse files Browse the repository at this point in the history
  • Loading branch information
linglejack06 committed Sep 10, 2024
1 parent e755e95 commit 35cb5c0
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"editor.rulers": [
100
],
"java.debug.settings.onBuildFailureProceed": true
"java.debug.settings.onBuildFailureProceed": true,
"java.format.settings.url": "eclipse-formatter.xml"
}
1 change: 1 addition & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static final class FeatureFlags {
public static final boolean runEndgame = false;
public static final boolean runDrive = true;
public static final boolean demoMode = false;
public static final boolean outputScore = false;

public static final boolean enableLEDS = true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public void configureSubsystems() {
if (FeatureFlags.demoMode) {
scoringSubsystem.setDemo(true);
}
if (!FeatureFlags.outputScore) {
scoringSubsystem.setScoringOutput(false);
}
}

if (FeatureFlags.runEndgame) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/subsystems/scoring/AimerIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ public default void setBrakeMode(boolean brake) {}

public default void setStatorCurrentLimit(double limit) {}

public default void setMotorDisabled(boolean disabled) {}
public default void setOutput(boolean output) {}
}
17 changes: 10 additions & 7 deletions src/main/java/frc/robot/subsystems/scoring/AimerIORoboRio.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import edu.wpi.first.math.trajectory.TrapezoidProfile.State;
import edu.wpi.first.wpilibj.DutyCycleEncoder;
import edu.wpi.first.wpilibj.Timer;
import frc.robot.Constants.FeatureFlags;
import frc.robot.Constants.ScoringConstants;
import org.littletonrobotics.junction.Logger;

Expand Down Expand Up @@ -59,7 +60,7 @@ public class AimerIORoboRio implements AimerIO {
double lastPosition = 0.0;
double lastTime = Utils.getCurrentTimeSeconds();

boolean motorDisabled = false;
boolean enableOutput = true;

public AimerIORoboRio() {
aimerLeft.setControl(new Follower(ScoringConstants.aimRightMotorId, true));
Expand All @@ -81,7 +82,9 @@ public AimerIORoboRio() {
.withStatorCurrentLimit(60)
.withStatorCurrentLimitEnable(true));

aimerRight.setPosition(0.0);
if (FeatureFlags.outputScore) {
aimerRight.setPosition(0.0);
}

controller.setTolerance(0.015);
}
Expand Down Expand Up @@ -183,8 +186,8 @@ public void setStatorCurrentLimit(double limit) {
}

@Override
public void setMotorDisabled(boolean disabled) {
motorDisabled = disabled;
public void setOutput(boolean output) {
enableOutput = output;
}

@Override
Expand All @@ -202,7 +205,7 @@ public void updateInputs(AimerIOInputs inputs) {
double velocitySetpoint = trapezoidSetpoint.velocity;

if (getEncoderPosition() == -1.75) {
motorDisabled = true;
enableOutput = false;
}

if (override) {
Expand All @@ -214,13 +217,13 @@ public void updateInputs(AimerIOInputs inputs) {
}

appliedVolts = MathUtil.clamp(appliedVolts, -12.0, 12.0);
if (!motorDisabled || override) {
if (enableOutput || override) {
aimerRight.setVoltage(appliedVolts);
} else {
aimerRight.setVoltage(0.0);
}

Logger.recordOutput("Scoring/motorDisabled", motorDisabled);
Logger.recordOutput("Scoring/Aimer/OutputEnabled", enableOutput);

inputs.aimGoalAngleRad = goalAngleRad;
inputs.aimProfileGoalAngleRad = controlSetpoint;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/subsystems/scoring/HoodIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public default void setOverrideVolts(double volts) {}

public default void home() {}

public default void setOutput(boolean output) {}

public default void setPID(double p, double i, double d) {}

public default void setBrakeMode(boolean brake) {}
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/frc/robot/subsystems/scoring/HoodIOSparkFlex.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.wpi.first.math.trajectory.TrapezoidProfile.State;
import edu.wpi.first.wpilibj.Timer;
import frc.robot.Constants.ScoringConstants;
import org.littletonrobotics.junction.Logger;

public class HoodIOSparkFlex implements HoodIO {
private final CANSparkFlex hoodMotor =
Expand All @@ -22,6 +23,7 @@ public class HoodIOSparkFlex implements HoodIO {
ScoringConstants.hoodMaxAcceleration));

private boolean override = false;
private boolean enableOutput = true;
private boolean homing = false;

double overrideVolts = 0.0;
Expand Down Expand Up @@ -99,6 +101,11 @@ public void setBrakeMode(boolean brake) {
hoodMotor.setIdleMode(brake ? CANSparkFlex.IdleMode.kBrake : CANSparkFlex.IdleMode.kCoast);
}

@Override
public void setOutput(boolean output) {
enableOutput = output;
}

@Override
public void updateInputs(HoodIOInputs inputs) {
State trapezoidSetpoint =
Expand All @@ -107,6 +114,8 @@ public void updateInputs(HoodIOInputs inputs) {
new State(initialAngle, initialVelocity),
new State(goalAngleRad, 0.0));

Logger.recordOutput("Scoring/Hood/OutputEnabled", enableOutput);

// if (homing) {
// if (hoodMotor.getOutputCurrent() > ScoringConstants.hoodHomeAmps
// && homeTimer.get() > 0.4) {
Expand All @@ -130,7 +139,9 @@ public void updateInputs(HoodIOInputs inputs) {
// if (hoodMotor.getOutputCurrent() > 70) {
// hoodMotor.setVoltage(0.0);
// } else {
hoodMotor.setVoltage(overrideVolts);
if (enableOutput) {
hoodMotor.setVoltage(overrideVolts);
}
// }

inputs.hoodAngleRad = hoodMotor.getEncoder().getPosition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,13 @@ public void setDemo(boolean demo) {
}

public void setArmDisabled(boolean disabled) {
aimerIo.setMotorDisabled(disabled);
aimerIo.setOutput(!disabled);
}

public void setScoringOutput(boolean output) {
aimerIo.setOutput(output);
hoodIo.setOutput(output);
shooterIo.setOutput(output);
}

public void forceHood(boolean hoodForced) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/subsystems/scoring/ShooterIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public default void setKickerVolts(double volts) {}

public default void setOverrideMode(boolean override) {}

public default void setOutput(boolean output) {}

public default void setOverrideVolts(double volts) {}

public default void setPID(double p, double i, double d) {}
Expand Down
38 changes: 25 additions & 13 deletions src/main/java/frc/robot/subsystems/scoring/ShooterIOTalon.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import frc.robot.Constants.ConversionConstants;
import frc.robot.Constants.ScoringConstants;
import frc.robot.Constants.SensorConstants;
import org.littletonrobotics.junction.Logger;

public class ShooterIOTalon implements ShooterIO {
private final TalonFX kicker = new TalonFX(ScoringConstants.kickerMotorId);
Expand All @@ -22,6 +23,7 @@ public class ShooterIOTalon implements ShooterIO {
DigitalInput bannerSensor = new DigitalInput(SensorConstants.indexerSensorPort);

private boolean override = false;
private boolean enableOutput = true;
private double overrideVolts = 0.0;

double goalLeftVelocityRPM = 0.0;
Expand Down Expand Up @@ -70,30 +72,38 @@ public ShooterIOTalon() {
public void setShooterVelocityRPM(double velocity) {
goalLeftVelocityRPM = velocity;
goalRightVelocityRPM = velocity * ScoringConstants.shooterOffsetAdjustment;

if (velocity == 0.0) {
shooterLeft.setVoltage(0.0);
shooterRight.setVoltage(0.0);
} else {
shooterLeft.setControl(
new VelocityDutyCycle(
goalLeftVelocityRPM / ConversionConstants.kMinutesToSeconds));
shooterRight.setControl(
new VelocityDutyCycle(
goalRightVelocityRPM / ConversionConstants.kMinutesToSeconds));
if (enableOutput) {
if (velocity == 0.0) {
shooterLeft.setVoltage(0.0);
shooterRight.setVoltage(0.0);
} else {
shooterLeft.setControl(
new VelocityDutyCycle(
goalLeftVelocityRPM / ConversionConstants.kMinutesToSeconds));
shooterRight.setControl(
new VelocityDutyCycle(
goalRightVelocityRPM / ConversionConstants.kMinutesToSeconds));
}
}
}

@Override
public void setKickerVolts(double volts) {
kicker.setVoltage(volts);
if (enableOutput) {
kicker.setVoltage(volts);
}
}

@Override
public void setOverrideMode(boolean override) {
this.override = override;
}

@Override
public void setOutput(boolean output) {
enableOutput = output;
}

@Override
public void setOverrideVolts(double volts) {
overrideVolts = volts;
Expand Down Expand Up @@ -121,11 +131,13 @@ public void setFF(double kS, double kV, double kA) {

@Override
public void updateInputs(ShooterIOInputs inputs) {
if (override) {
if (override && enableOutput) {
shooterLeft.setVoltage(overrideVolts);
shooterRight.setVoltage(overrideVolts);
}

Logger.recordOutput("Scoring/Shooter/OutputEnabled", enableOutput);

inputs.shooterLeftVelocityRPM =
shooterLeft.getVelocity().getValueAsDouble()
/ ConversionConstants.kSecondsToMinutes;
Expand Down

0 comments on commit 35cb5c0

Please sign in to comment.