Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
✨ updated updateInputs to not use the real class
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatXliner committed Oct 3, 2024
1 parent 70b6d9c commit d9851ad
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/main/java/frc/robot/subsystems/shooter/ShooterIOSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
import org.littletonrobotics.junction.LoggedRobot;

public class ShooterIOSim extends ShooterIOTalonFX {
private final FlywheelSim leftFlywheelSimModel =
new FlywheelSim(
ShooterConstants.kUseFOC ? DCMotor.getKrakenX60Foc(1) : DCMotor.getKrakenX60(1),
ShooterConstants.kLeftGearingRatio,
ShooterConstants.kLeftMomentOfInertia);
private final FlywheelSim rightFlywheelSimModel =
new FlywheelSim(
ShooterConstants.kUseFOC ? DCMotor.getKrakenX60Foc(1) : DCMotor.getKrakenX60(1),
ShooterConstants.kRightGearingRatio,
ShooterConstants.kRightMomentOfInertia);
private final FlywheelSim leftFlywheelSimModel = new FlywheelSim(
ShooterConstants.kUseFOC ? DCMotor.getKrakenX60Foc(1) : DCMotor.getKrakenX60(1),
ShooterConstants.kLeftGearingRatio,
ShooterConstants.kLeftMomentOfInertia);
private final FlywheelSim rightFlywheelSimModel = new FlywheelSim(
ShooterConstants.kUseFOC ? DCMotor.getKrakenX60Foc(1) : DCMotor.getKrakenX60(1),
ShooterConstants.kRightGearingRatio,
ShooterConstants.kRightMomentOfInertia);
private final TalonFXSimState shooterMotorSim;
private final TalonFXSimState shooterFollowerMotorSim;

Expand All @@ -35,8 +33,27 @@ public ShooterIOSim() {

@Override
public void updateInputs(ShooterIOInputs inputs) {
// TODO: Don't use super.updateInputs(inputs)
super.updateInputs(inputs);
// For Advantage Kit >>>
inputs.shooterMotorVoltage = shooterMotorSim.getMotorVoltage();
inputs.shooterMotorVelocity = leftFlywheelSimModel.getAngularVelocityRPM() / 60;
// In a perfect motor, the supply current and stator current would be equal
inputs.shooterMotorStatorCurrent = shooterMotorSim.getSupplyCurrent();
inputs.shooterMotorSupplyCurrent = shooterMotorSim.getSupplyCurrent();
inputs.shooterMotorTemperature = 0.0; // In a perfect motor, no heat is generated
// XXX:
// 1. This could be optimized
// 2. what about BaseStatusSignal.refreshAll
// 3. I'm not even sure if this work in sim
inputs.shooterMotorReferenceSlope = super.getMotor().getClosedLoopReferenceSlope().getValueAsDouble();

inputs.shooterMotorFollowerVoltage = shooterFollowerMotorSim.getMotorVoltage();
inputs.shooterMotorFollowerVelocity = rightFlywheelSimModel.getAngularVelocityRPM() / 60;
inputs.shooterMotorFollowerStatorCurrent = shooterFollowerMotorSim.getSupplyCurrent();
inputs.shooterMotorFollowerSupplyCurrent = shooterFollowerMotorSim.getSupplyCurrent();
inputs.shooterMotorFollowerTemperature = 0.0;
inputs.shooterMotorFollowerReferenceSlope = super.getFollowerMotor().getClosedLoopReferenceSlope()
.getValueAsDouble();
// <<< For Advantage Kit
leftFlywheelSimModel.setInput(shooterMotorSim.getMotorVoltage());
leftFlywheelSimModel.update(LoggedRobot.defaultPeriodSecs);
rightFlywheelSimModel.setInput(shooterFollowerMotorSim.getMotorVoltage());
Expand Down

0 comments on commit d9851ad

Please sign in to comment.