Skip to content

Commit 49a629e

Browse files
still need to figure out linear system
1 parent 1137b31 commit 49a629e

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/main/java/frc/robot/subsystems/Shooter/ShooterConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ public class ShooterConstants {
55
public static double kI = 0.0;
66
public static double kD = 0.0;
77

8+
public static double kV = 0.2; // Volts per (RPM)
9+
public static double kA = 0.1; // Volts per (RPM/s)
10+
811
public static final double MAX_VELOCITY = 5000.0;
912
public static final double MAX_ACCELERATION = 3000.0;
1013

src/main/java/frc/robot/subsystems/Shooter/ShooterIOSim.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,34 @@
55
import edu.wpi.first.math.MathUtil;
66
import edu.wpi.first.math.controller.ProfiledPIDController;
77
import edu.wpi.first.math.controller.SimpleMotorFeedforward;
8+
import edu.wpi.first.math.system.LinearSystem;
89
import edu.wpi.first.math.system.plant.DCMotor;
910
import edu.wpi.first.math.trajectory.TrapezoidProfile;
1011
import edu.wpi.first.wpilibj.simulation.FlywheelSim;
11-
12+
import org.littletonrobotics.junction.AutoLog;
13+
import org.littletonrobotics.junction.Logger;
1214

1315
import edu.wpi.first.math.util.Units;
1416

1517
public class ShooterIOSim implements ShooterIO {
1618
public void updateInputs(ShooterIOInputs inputs) {
1719
leftSim.update(0.020);
1820
rightSim.update(0.020);
19-
//need to figure out simpler way for if statements (verbose site)
21+
if (leftSetpointRPM != null) {
22+
leftAppliedVolts =
23+
pidController.calculate(leftSim.getAngularVelocityRPM(), leftSetpointRPM)
24+
+ leftFF.calculate(leftSetpointRPM);
25+
leftSim.setInputVoltage(MathUtil.clamp(leftAppliedVolts, -12.0, 12.0));
26+
Logger.recordOutput("Shooter Voltage Left", MathUtil.clamp(leftAppliedVolts, -12.0, 12.0));
27+
} // if the value is NOT null - calculate what the applied voltage should be and record it accordingly
28+
29+
if (rightSetpointRPM != null) {
30+
rightAppliedVolts =
31+
pidController.calculate(rightSim.getAngularVelocityRPM(), rightSetpointRPM)
32+
+ rightFF.calculate(rightSetpointRPM);
33+
rightSim.setInputVoltage(MathUtil.clamp(rightAppliedVolts, -12.0, 12.0));
34+
Logger.recordOutput("Shooter Voltage Right", MathUtil.clamp(rightAppliedVolts, -12.0, 12.0));
35+
} // if the value is NOT null - calculate what the applied voltage should be and record it accordingly
2036
}
2137
private double leftAppliedVolts = 0.0;
2238
private double rightAppliedVolts = 0.0;
@@ -35,9 +51,13 @@ public void updateInputs(ShooterIOInputs inputs) {
3551
)
3652
);
3753

38-
FlywheelSim rightSim = new FlywheelSim(null, DCMotor.getNeoVortex(1), 6.7);
54+
55+
FlywheelSim rightSim = new FlywheelSim(system, DCMotor.getNeoVortex(1), 6.7);
3956
FlywheelSim leftSim = new FlywheelSim(null, DCMotor.getNeoVortex(1), 6.7);
4057

58+
//what is a linear system + why do we need it
59+
60+
4161
private SimpleMotorFeedforward leftFF = new SimpleMotorFeedforward(0.0, 0.0, 0.0);
4262
private SimpleMotorFeedforward rightFF = new SimpleMotorFeedforward(0.0, 0.0, 0.0);
4363

0 commit comments

Comments
 (0)