55import edu .wpi .first .math .MathUtil ;
66import edu .wpi .first .math .controller .ProfiledPIDController ;
77import edu .wpi .first .math .controller .SimpleMotorFeedforward ;
8+ import edu .wpi .first .math .system .LinearSystem ;
89import edu .wpi .first .math .system .plant .DCMotor ;
910import edu .wpi .first .math .trajectory .TrapezoidProfile ;
1011import edu .wpi .first .wpilibj .simulation .FlywheelSim ;
11-
12+ import org .littletonrobotics .junction .AutoLog ;
13+ import org .littletonrobotics .junction .Logger ;
1214
1315import edu .wpi .first .math .util .Units ;
1416
1517public 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