|
10 | 10 | import com.revrobotics.spark.SparkBase.ControlType; |
11 | 11 | import com.revrobotics.spark.SparkClosedLoopController; |
12 | 12 | import com.revrobotics.spark.SparkLowLevel.MotorType; |
| 13 | +import com.revrobotics.spark.SparkMax; |
13 | 14 | import com.revrobotics.spark.config.SparkBaseConfig; |
14 | 15 | import com.revrobotics.spark.config.SparkBaseConfig.IdleMode; |
15 | 16 | import com.revrobotics.spark.config.SparkMaxConfig; |
16 | | -import com.revrobotics.spark.SparkMax; |
17 | 17 | import edu.wpi.first.wpilibj2.command.Command; |
| 18 | +import org.team340.lib.tunable.TunableTable; |
| 19 | +import org.team340.lib.tunable.Tunables; |
| 20 | +import org.team340.lib.tunable.Tunables.TunableDouble; |
18 | 21 | import org.team340.lib.util.command.GRRSubsystem; |
19 | 22 | import org.team340.robot.Constants.RobotMap; |
20 | 23 |
|
21 | 24 | public class Shootake extends GRRSubsystem { |
22 | 25 |
|
23 | 26 | private final SparkMax hopper; |
24 | 27 | private final SparkMax shooter; |
| 28 | + |
| 29 | + private static final TunableTable tunables = Tunables.getNested("shooter"); |
| 30 | + private static final TunableDouble shootingSpeed = tunables.value("velocity", 2000.0); |
25 | 31 | SparkClosedLoopController shooterController; |
| 32 | + |
26 | 33 | /** Creates a new Shootake. */ |
27 | 34 | public Shootake() { |
28 | 35 | hopper = new SparkMax(RobotMap.HOPPER_MOTOR, MotorType.kBrushless); |
29 | 36 | shooter = new SparkMax(RobotMap.INTAKE_SHOOTER_MOTOR, MotorType.kBrushless); |
30 | 37 | SparkBaseConfig shooterConfig = new SparkMaxConfig(); |
31 | | - shooterConfig.voltageCompensation(12) |
32 | | - .idleMode(IdleMode.kCoast) |
33 | | - .closedLoop |
34 | | - .feedbackSensor(FeedbackSensor.kPrimaryEncoder) |
35 | | - .pid(0.01, 0, 0) |
36 | | - .feedForward.kS(0.0) |
37 | | - .kV(.13); |
| 38 | + shooterConfig |
| 39 | + .voltageCompensation(12) |
| 40 | + .idleMode(IdleMode.kCoast) |
| 41 | + .closedLoop.feedbackSensor(FeedbackSensor.kPrimaryEncoder) |
| 42 | + .pid(0.01, 0, 0) |
| 43 | + .feedForward.kS(0.0) |
| 44 | + .kV(.13); |
38 | 45 | shooterConfig.encoder |
39 | | - .positionConversionFactor(1.0) |
40 | | - .velocityConversionFactor(1.0 / 60.0) |
41 | | - .uvwMeasurementPeriod(16) |
42 | | - .uvwAverageDepth(2); |
43 | | - hopperConfig.voltageCompensation(12) |
44 | | - .idleMode(IdleMode.kBrake) |
| 46 | + .positionConversionFactor(1.0) |
| 47 | + .velocityConversionFactor(1.0) |
| 48 | + .uvwMeasurementPeriod(16) |
| 49 | + .uvwAverageDepth(2); |
| 50 | + SparkBaseConfig hopperConfig = new SparkMaxConfig(); |
| 51 | + hopperConfig.voltageCompensation(12).idleMode(IdleMode.kBrake); |
45 | 52 | shooter.configure(shooterConfig, ResetMode.kNoResetSafeParameters, PersistMode.kPersistParameters); |
46 | 53 | shooterController = shooter.getClosedLoopController(); |
47 | 54 | } |
@@ -78,13 +85,13 @@ public Command barf() { |
78 | 85 | public Command shoot() { |
79 | 86 | return commandBuilder() |
80 | 87 | .onExecute(() -> { |
81 | | - shooterController.setSetpoint(2, ControlType.kVelocity); |
| 88 | + shooterController.setSetpoint(shootingSpeed.getAsDouble(), ControlType.kVelocity); |
82 | 89 | }) |
83 | 90 | .withTimeout(.5) |
84 | 91 | .andThen( |
85 | 92 | commandBuilder() |
86 | 93 | .onExecute(() -> { |
87 | | - shooterController.setSetpoint(2, ControlType.kVelocity); |
| 94 | + shooterController.setSetpoint(shootingSpeed.getAsDouble(), ControlType.kVelocity); |
88 | 95 | hopper.set(-1); |
89 | 96 | }) |
90 | 97 | .onEnd(() -> { |
|
0 commit comments