Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ private void configureBindings() {
new Trigger(copilot::getXButton).whileTrue(hood.retractCommand().withInterruptBehavior(InterruptionBehavior.kCancelIncoming));

new Trigger(copilot::getLeftBumperButton).whileTrue(indexer.indexCommand(-IndexerConstants.SPINDEXDER_POWER,
-IndexerConstants.TRANSFER_POWER));
-IndexerConstants.TRANSFER_VELOCITY));
new Trigger(copilot::getRightBumperButton).whileTrue(indexer.indexCommand(IndexerConstants.SPINDEXDER_POWER,
IndexerConstants.TRANSFER_POWER));
IndexerConstants.TRANSFER_VELOCITY));

new Trigger(copilot::getStartButton).onTrue(collector.stowPivotCommand());

Expand Down Expand Up @@ -193,8 +193,7 @@ private void configureBindings() {

// new Trigger(() -> DriverStation.isEnabled()).onTrue(hood.zeroCommand());

new Trigger(copilot::getAButton).whileTrue(indexer.autoIndex(IndexerConstants.SPINDEXDER_POWER, IndexerConstants.TRANSFER_POWER)).onFalse(new InstantCommand(() -> indexer.stop()));

new Trigger(copilot::getAButton).whileTrue(indexer.autoIndex(IndexerConstants.SPINDEXDER_POWER, IndexerConstants.TRANSFER_VELOCITY)).onFalse(new InstantCommand(() -> indexer.stop()));
new Trigger(copilot::getYButton).whileTrue(indexer.indexCommand(-0.5).withTimeout(0.1).andThen(indexer.indexCommand(1)));


Expand Down
45 changes: 31 additions & 14 deletions src/main/java/frc/robot/subsystems/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.DutyCycleOut;
import com.ctre.phoenix6.controls.VelocityVoltage;
import com.ctre.phoenix6.sim.TalonFXSimState;
import com.ctre.phoenix6.sim.TalonFXSimState.MotorType;

Expand Down Expand Up @@ -58,10 +59,15 @@ public class IndexerConstants {
public static final Current TRANSFER_MOTOR_STATOR_LIMIT = Amps.of(40); // temp
public static final boolean TRANSFER_MOTOR_BRAKE_MODE = true; // temp

public static final double TRANSFER_POWER = 0.8;
public static final double TRANSFER_POWER = 0.7;
public static final double TRANSFER_VELOCITY = 70;
public static final Current TRANSFER_SUPPLY_LIMIT = Amps.of(40); // temp
public static final boolean TRANSFER_SUPPLY_LIMIT_ENABLE = true; // temp

public static final double TRANSFER_kP = 0.2; // temp
public static final double TRANSFER_kV = 0.124; // temp
public static final double TRANSFER_kS = 0.25;

// sim
public static final AngularVelocity SIM_INDEX_THRESHOLD = RotationsPerSecond.of(1); // temp
}
Expand All @@ -72,6 +78,8 @@ public class IndexerConstants {
private final DutyCycleOut spindexerDutyCycle;
private final DutyCycleOut transferDutyCycle;

private VelocityVoltage transferVelocityVoltage;

private LinearSystemSim<N1, N1, N1> spindexerSim;
private TalonFXSimState motorSim;

Expand All @@ -88,12 +96,17 @@ public Indexer() {

spindexerDutyCycle = new DutyCycleOut(0d);
transferDutyCycle = new DutyCycleOut(0d);
VelocityVoltage transferVelocityVoltage = new VelocityVoltage(0);

TalonFXConfiguration spindexerConfig = spindexerMotor.getConfig();
TalonFXConfiguration transferConfig = transferMotor.getConfig();

spindexerConfig.CurrentLimits.SupplyCurrentLimitEnable = IndexerConstants.SPINDEXER_SUPPLY_LIMIT_ENABLE;
spindexerConfig.CurrentLimits.SupplyCurrentLimit = IndexerConstants.SPINDEXER_SUPPLY_LIMIT.in(Amps);

transferConfig.Slot0.kP = IndexerConstants.TRANSFER_kP;
transferConfig.Slot0.kV = IndexerConstants.TRANSFER_kV;

transferConfig.CurrentLimits.SupplyCurrentLimitEnable = IndexerConstants.TRANSFER_SUPPLY_LIMIT_ENABLE;
transferConfig.CurrentLimits.SupplyCurrentLimit = IndexerConstants.TRANSFER_SUPPLY_LIMIT.in(Amps);

Expand Down Expand Up @@ -178,6 +191,10 @@ public void setTransferPower(double power) {
transferMotor.setControl(transferDutyCycle.withOutput(power));
}

public void setTransferVelocity(double velocity) {
transferMotor.setControl(transferVelocityVoltage.withVelocity(velocity));
}

/**
* stops all movement to the transfer motor
*/
Expand All @@ -191,12 +208,12 @@ public void stopTransfer() {
*/
public void setPower(double power) {
setSpindexerPower(power);
setTransferPower(power);
setTransferVelocity(power);
}

public void setPower(double spindexerPower, double transferPower) {
setSpindexerPower(spindexerPower);
setTransferPower(transferPower);
setTransferVelocity(transferPower);
}

/**
Expand All @@ -217,25 +234,25 @@ public Command indexCommand(double power) {
return new StartEndCommand(() -> setPower(power), () -> stop(), this);
}

public Command indexCommand(DoubleSupplier spindexerPower, DoubleSupplier transferPower) {
return new StartEndCommand(() -> setPower(spindexerPower.getAsDouble(), transferPower.getAsDouble()), this::stop);
public Command indexCommand(DoubleSupplier spindexerPower, DoubleSupplier transferVelocity) {
return new StartEndCommand(() -> setPower(spindexerPower.getAsDouble(), transferVelocity.getAsDouble()), this::stop);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not just setting the duty cycle still? setPower() still calls setTransferPower which calls the duty cycle.

}

public Command autoIndex(DoubleSupplier spindexerPower, DoubleSupplier transferPower) {
return new InstantCommand(() -> setTransferPower(transferPower.getAsDouble()))
public Command autoIndex(DoubleSupplier spindexerPower, DoubleSupplier transferVelocity) {
return new InstantCommand(() -> setTransferVelocity(transferVelocity.getAsDouble()))
.andThen(new WaitCommand(IndexerConstants.SPINDEXER_DELAY))
.andThen(indexCommand(spindexerPower, transferPower));
.andThen(indexCommand(spindexerPower, transferVelocity));
}

public Command autoIndex(double spindexerPower, double transferPower) {
return autoIndex(() -> spindexerPower, () -> transferPower);
public Command autoIndex(double spindexerPower, double transferVelocity) {
return autoIndex(() -> spindexerPower, () -> transferVelocity);
}

public Command indexCommand(double spindexerPower, double transferPower) {
return indexCommand(() -> spindexerPower, () -> transferPower);
public Command indexCommand(double spindexerPower, double transferVelocity) {
return indexCommand(() -> spindexerPower, () -> transferVelocity);
}

public Command transferCommand(DoubleSupplier transferPower) {
return new RunCommand(() -> setTransferPower(transferPower.getAsDouble()));
public Command transferCommand(DoubleSupplier transferVelocity) {
return new RunCommand(() -> setTransferVelocity(transferVelocity.getAsDouble()));
}
}
Loading