Skip to content

Commit f62de9b

Browse files
committed
use motion magic velocity control in CoralHolderSub
1 parent 80ab0c9 commit f62de9b

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/main/java/frc/robot/constants/CoralHolderConstants.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
public class CoralHolderConstants {
99
public static final Time OUTTAKE_DURATION = Seconds.of(0.5);
1010
public static final Time INTAKE_DURATION = Seconds.of(1);
11-
public static final double THROTTLE = 0.2;
12-
public static final FalconMotorSupplier MOTOR_ID = new FalconMotorSupplier(5).withInvert();
11+
public static final double SPEED_RPS = 1;
12+
public static final FalconMotorSupplier MOTOR_ID = new FalconMotorSupplier(5)
13+
.withPID(1, 0, 0)
14+
.withEncoder(9)
15+
.withInvert();
1316
}

src/main/java/frc/robot/subsystems/CoralHolderSub.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package frc.robot.subsystems;
22

3+
import com.ctre.phoenix6.controls.MotionMagicVelocityDutyCycle;
34
import com.ctre.phoenix6.hardware.TalonFX;
45

56
import edu.wpi.first.util.sendable.Sendable;
@@ -11,21 +12,22 @@
1112

1213
public class CoralHolderSub extends SubsystemBase {
1314
private final TalonFX motor = CoralHolderConstants.MOTOR_ID.get();
15+
private final MotionMagicVelocityDutyCycle control = new MotionMagicVelocityDutyCycle(0);
1416

1517
public CoralHolderSub() {
1618
setupSmartDash();
1719
}
1820

1921
public void forward() {
20-
motor.set(CoralHolderConstants.THROTTLE);
22+
motor.setControl(control.withVelocity(CoralHolderConstants.SPEED_RPS));
2123
}
2224

2325
public void reverse() {
24-
motor.set(-CoralHolderConstants.THROTTLE);
26+
motor.setControl(control.withVelocity(-CoralHolderConstants.SPEED_RPS));
2527
}
2628

2729
public void stop() {
28-
motor.set(0);
30+
motor.setControl(control.withVelocity(0));
2931
}
3032

3133
public Command manualOutCommand() {

src/main/java/frc/robot/utils/TypeSupliers/motorsupplier/FalconMotorSupplier.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public FalconMotorSupplier withInvert() {
2828
return this;
2929
}
3030

31+
public FalconMotorSupplier withFeedForward(double s, double v, double a) {
32+
motorConfig.Slot0.kS = s;
33+
motorConfig.Slot0.kV = v;
34+
motorConfig.Slot0.kA = a;
35+
36+
return this;
37+
}
38+
3139
public FalconMotorSupplier withPID(double p, double i, double d) {
3240
motorConfig.Slot0.kP = p;
3341
motorConfig.Slot0.kI = i;

0 commit comments

Comments
 (0)