Skip to content

Commit 340796a

Browse files
authored
Merge pull request #11 from joelzoto/main
Tested out Indexer and Flywheel Commands
2 parents 363b3c1 + efe1433 commit 340796a

File tree

9 files changed

+55
-32
lines changed

9 files changed

+55
-32
lines changed

src/main/java/frc/robot/Robot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import edu.wpi.first.wpilibj2.command.Command;
1414
import edu.wpi.first.wpilibj2.command.CommandScheduler;
1515
import frc.crevolib.configs.CTREConfigs;
16+
import frc.robot.driver.Driver;
1617
import frc.robot.driver.DriverXbox;
1718
import frc.robot.operator.OperatorXbox;
1819

@@ -46,7 +47,7 @@ public static void resetCommandsAndButtons() {
4647
// Reset Config for all gamepads and other button bindings
4748
// Driver.getInstance().resetConfig();
4849
// Operator.getInstance().resetConfig();
49-
DriverXbox.getInstance().resetConfig();
50+
Driver.getInstance().resetConfig();
5051
OperatorXbox.getInstance().resetConfig();
5152
}
5253

src/main/java/frc/robot/algaeflywheel/AlgaeFlyWheel.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
/** Add your docs here. */
1919
public class AlgaeFlyWheel extends SubsystemBase{
2020
public static class Settings {
21-
static final int kLeftId = 27;
22-
static final int kRightId = 28;
21+
static final int kLeftId = 15;
22+
static final int kRightId = 16;
2323

24-
static final InvertedValue kAlgaeScoringInverted = InvertedValue.Clockwise_Positive;
25-
static final InvertedValue kAlgaeIntakingInverted = InvertedValue.CounterClockwise_Positive;
24+
public static final InvertedValue kAlgaeScoringInverted = InvertedValue.Clockwise_Positive;
25+
public static final InvertedValue kAlgaeIntakingInverted = InvertedValue.CounterClockwise_Positive;
2626

2727
static final Slot0Configs kAlgaeFlyWheelConfigs = new Slot0Configs()
2828
.withKS(0.0)
@@ -44,15 +44,15 @@ public static class Settings {
4444

4545

4646
private AlgaeFlyWheel() {
47-
LeftFlyWheel = new TalonFX(Settings.kLeftId, "Canivore");
48-
var leftTalonFXConfigurator = LeftFlyWheel.getConfigurator();
47+
LeftFlyWheel = new TalonFX(Settings.kLeftId);
48+
leftTalonFXConfigurator = LeftFlyWheel.getConfigurator();
4949
leftMotorConfigs = new MotorOutputConfigs();
5050

5151
leftTalonFXConfigurator.apply(Settings.kAlgaeFlyWheelConfigs);
5252

5353

54-
RightFlyWheel = new TalonFX(Settings.kRightId, "Canivore");
55-
var rightTalonFXConfigurator = RightFlyWheel.getConfigurator();
54+
RightFlyWheel = new TalonFX(Settings.kRightId);
55+
rightTalonFXConfigurator = RightFlyWheel.getConfigurator();
5656
rightMotorConfigs = new MotorOutputConfigs();
5757

5858
rightTalonFXConfigurator.apply(Settings.kAlgaeFlyWheelConfigs);
@@ -65,17 +65,17 @@ public static AlgaeFlyWheel getInstance() {
6565
return mInstance;
6666
}
6767

68-
public void setLeftFlywheelVelocity(Rotation2d velocity, InvertedValue kInvertedValue) {
68+
public void setLeftFlywheelVelocity(Rotation2d velocity, InvertedValue kLeftInvertedValue) {
6969
// set invert to CW+ and apply config change
70-
leftMotorConfigs.Inverted = kInvertedValue;
70+
leftMotorConfigs.Inverted = kLeftInvertedValue;
7171
leftTalonFXConfigurator.apply(leftMotorConfigs);
7272

7373
LeftFlyWheel.setControl(new VelocityVoltage(velocity.getRotations()));
7474
}
7575

76-
public void setRightFlywheelVelocity(Rotation2d velocity, InvertedValue kInvertedValue) {
76+
public void setRightFlywheelVelocity(Rotation2d velocity, InvertedValue kRightInvertedValue) {
7777
// set invert to CW+ and apply config change
78-
rightMotorConfigs.Inverted = kInvertedValue;
78+
rightMotorConfigs.Inverted = kRightInvertedValue;
7979
rightTalonFXConfigurator.apply(rightMotorConfigs);
8080

8181
RightFlyWheel.setControl(new VelocityVoltage(velocity.getRotations()));

src/main/java/frc/robot/algaeflywheel/commands/AlgaeFlyWheelCommands.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import com.ctre.phoenix6.signals.InvertedValue;
99

1010
public class AlgaeFlyWheelCommands {
11-
public static Command setAngularVelocity(Supplier<Rotation2d> leftVelocitySupplier, Supplier<Rotation2d> rightVelocitySupplier, InvertedValue kInvertedValue) {
12-
return new SetVelocityAlgaeFlyWheel(leftVelocitySupplier, rightVelocitySupplier, kInvertedValue);
11+
public static Command setAngularVelocity(Supplier<Rotation2d> leftVelocitySupplier, Supplier<Rotation2d> rightVelocitySupplier, InvertedValue kLeftInvertedValue, InvertedValue kRightInvertedValue) {
12+
return new SetVelocityAlgaeFlyWheel(leftVelocitySupplier, rightVelocitySupplier, kLeftInvertedValue, kRightInvertedValue);
1313
}
1414

15-
public static Command setAngularVelocity(Supplier<Rotation2d> velocitySupplier, InvertedValue kInvertedValue) {
16-
return setAngularVelocity(velocitySupplier, velocitySupplier, kInvertedValue);
15+
public static Command setAngularVelocity(Supplier<Rotation2d> velocitySupplier, InvertedValue kLeftInvertedValue, InvertedValue kRightInvertedValue) {
16+
return setAngularVelocity(velocitySupplier, velocitySupplier, kLeftInvertedValue, kRightInvertedValue);
1717
}
1818
}

src/main/java/frc/robot/algaeflywheel/commands/SetVelocityAlgaeFlyWheel.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,28 @@
1414
public class SetVelocityAlgaeFlyWheel extends Command {
1515
private final AlgaeFlyWheel flywheel;
1616
private final Supplier<Rotation2d> leftVelocitySupplier, rightVelocitySupplier;
17-
private final InvertedValue kInvertedValue;
17+
private final InvertedValue kLeftInvertedValue, kRightInvertedValue;
1818

1919
private final Rotation2d kAllowedError = Rotation2d.fromRotations(5); // 300 RPM
2020

21-
SetVelocityAlgaeFlyWheel(Supplier<Rotation2d> leftVelocitySupplier, Supplier<Rotation2d> rightVelocitySupplier, InvertedValue kInvertedValue) {
21+
SetVelocityAlgaeFlyWheel(Supplier<Rotation2d> leftVelocitySupplier, Supplier<Rotation2d> rightVelocitySupplier, InvertedValue kLeftInvertedValue, InvertedValue kRightInvertedValue) {
2222
flywheel = AlgaeFlyWheel.getInstance();
2323
this.leftVelocitySupplier = leftVelocitySupplier;
2424
this.rightVelocitySupplier = rightVelocitySupplier;
25-
this.kInvertedValue = kInvertedValue;
25+
this.kLeftInvertedValue = kLeftInvertedValue;
26+
this.kRightInvertedValue = kRightInvertedValue;
2627
}
2728

28-
SetVelocityAlgaeFlyWheel(Supplier<Rotation2d> velocitySupplier, InvertedValue kInvertedValue) {
29-
this(velocitySupplier, velocitySupplier, kInvertedValue);
29+
SetVelocityAlgaeFlyWheel(Supplier<Rotation2d> velocitySupplier, InvertedValue kLeftInvertedValue, InvertedValue kRightInvertedValue) {
30+
this(velocitySupplier, velocitySupplier, kLeftInvertedValue, kRightInvertedValue);
3031
}
3132

3233
@Override
3334
public void execute() {
3435
final var leftVel = leftVelocitySupplier.get();
3536
final var rightVel = rightVelocitySupplier.get();
36-
flywheel.setRightFlywheelVelocity(leftVel, kInvertedValue);
37-
flywheel.setLeftFlywheelVelocity(rightVel, kInvertedValue);
37+
flywheel.setRightFlywheelVelocity(leftVel, kRightInvertedValue);
38+
flywheel.setLeftFlywheelVelocity(rightVel, kLeftInvertedValue);
3839

3940
SmartDashboard.putBoolean("Shooter Ready (left)", (Math.abs(leftVel.getRotations()) - (Math.abs(flywheel.getLeftFlywheelVelocity().getRotations()))) < kAllowedError.getRotations());
4041
SmartDashboard.putBoolean("Shooter Ready (right)", (Math.abs(rightVel.getRotations()) - (Math.abs(flywheel.getRightFlywheelVelocity().getRotations()))) < kAllowedError.getRotations());
@@ -55,7 +56,7 @@ public boolean isFinished() {
5556

5657
@Override
5758
public void end(boolean isInterrupted) {
58-
flywheel.setRightFlywheelVelocity(Rotation2d.fromDegrees(0), kInvertedValue);
59-
flywheel.setLeftFlywheelVelocity(Rotation2d.fromDegrees(0), kInvertedValue);
59+
flywheel.setRightFlywheelVelocity(Rotation2d.fromDegrees(0), kRightInvertedValue);
60+
flywheel.setLeftFlywheelVelocity(Rotation2d.fromDegrees(0), kLeftInvertedValue);
6061
}
6162
}

src/main/java/frc/robot/algaepivot/AlgaeShooterPivot.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.ctre.phoenix6.configs.MotorOutputConfigs;
88
import com.ctre.phoenix6.configs.Slot0Configs;
9+
import com.ctre.phoenix6.configs.TalonFXConfigurator;
910
import com.ctre.phoenix6.hardware.CANcoder;
1011
import com.ctre.phoenix6.hardware.TalonFX;
1112
import com.ctre.phoenix6.signals.InvertedValue;
@@ -48,12 +49,14 @@ public class Settings{
4849
private Constraints mConstraints;
4950
private final ProfiledPIDController mPPIDController;
5051
private final ArmFeedforward mFFController;
52+
private MotorOutputConfigs motorConfigs;
53+
private TalonFXConfigurator talonFXConfigurator;
5154

5255
public AlgaeShooterPivot() {
5356
mKraken = new TalonFX(Settings.kAlgaePivotTalonID,"Canivore");
5457

55-
var talonFXConfigurator = mKraken.getConfigurator();
56-
var motorConfigs = new MotorOutputConfigs();
58+
talonFXConfigurator = mKraken.getConfigurator();
59+
motorConfigs = new MotorOutputConfigs();
5760

5861
motorConfigs.Inverted = InvertedValue.Clockwise_Positive;
5962
talonFXConfigurator.apply(motorConfigs);

src/main/java/frc/robot/driver/Driver.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
import edu.wpi.first.wpilibj2.command.InstantCommand;
88
import frc.crevolib.util.ExpCurve;
99
import frc.crevolib.util.Gamepad;
10+
import frc.crevolib.util.XboxGamepad;
1011
import frc.robot.Robot;
12+
import frc.robot.algaeflywheel.AlgaeFlyWheel;
13+
import frc.robot.algaeflywheel.commands.AlgaeFlyWheelCommands;
14+
import frc.robot.indexer.commands.IndexerCommands;
1115

12-
public class Driver extends Gamepad {
16+
public class Driver extends XboxGamepad {
1317
private static class Settings {
1418
static final int port = 0;
1519
static final String name = "driver";
@@ -38,9 +42,18 @@ public static Driver getInstance() {
3842

3943
@Override
4044
public void setupTeleopButtons() {
45+
controller.a().whileTrue(
46+
AlgaeFlyWheelCommands.setAngularVelocity(
47+
() -> AlgaeFlyWheel.Settings.kMaxAngularVelocity.times(0.8),
48+
AlgaeFlyWheel.Settings.kAlgaeScoringInverted,
49+
AlgaeFlyWheel.Settings.kAlgaeIntakingInverted
50+
));
51+
52+
controller.b().whileTrue(IndexerCommands.setOutput(() ->0.10));
4153
// Drivetrain Commands
4254

4355

56+
4457
}
4558

4659
@Override

src/main/java/frc/robot/driver/DriverXbox.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
import frc.crevolib.util.ExpCurve;
1515
import frc.crevolib.util.XboxGamepad;
1616
import frc.robot.Robot;
17+
import frc.robot.algaeflywheel.AlgaeFlyWheel;
18+
import frc.robot.algaeflywheel.commands.AlgaeFlyWheelCommands;
19+
import frc.robot.algaeflywheel.commands.SetVelocityAlgaeFlyWheel;
1720

1821

1922
public class DriverXbox extends XboxGamepad {
@@ -31,6 +34,7 @@ private static class Settings {
3134
private static ExpCurve rotationStickCurve;
3235
public boolean autoAim;
3336
private double reqAngularVel;
37+
3438

3539
private DriverXbox() {
3640
super(DriverXbox.Settings.name, DriverXbox.Settings.port);
@@ -48,6 +52,7 @@ public static DriverXbox getInstance() {
4852

4953
@Override
5054
public void setupTeleopButtons() {
55+
5156
// Drivetrain Commands
5257

5358

src/main/java/frc/robot/indexer/Indexer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class Indexer extends SubsystemBase{
1212
public static class Settings {
13-
static int kTalonID = 10;
13+
static int kTalonID = 17;
1414
static final double kMaxVoltage = 12.0;
1515
static final int kCurrentLimit = 200;
1616
static final int kCurrentThreshold = 100;
@@ -25,7 +25,7 @@ public Indexer() {
2525
var talonFXConfigurator = mKraken.getConfigurator();
2626
var motorConfigs = new MotorOutputConfigs();
2727

28-
motorConfigs.Inverted = InvertedValue.Clockwise_Positive;
28+
motorConfigs.Inverted = InvertedValue.CounterClockwise_Positive;
2929
talonFXConfigurator.apply(motorConfigs);
3030

3131
}

src/main/java/frc/robot/vision/Vision.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,4 @@ private void updateEstimationStdDevs(Optional<EstimatedRobotPose> estimatedPose,
134134
public Matrix<N3, N1> getEstimationStdDevs() {
135135
return curStdDevs;
136136
}
137-
}
137+
}

0 commit comments

Comments
 (0)