-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 21 additions & 42 deletions
63
src/main/java/frc/robot/subsystems/shooter/ShooterIOSim.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,37 @@ | ||
//thomas jin fix this | ||
//i just copy pasta from flywheel sim | ||
//type shi pray emoji | ||
// thomas jin fix this | ||
// i just copy pasta from flywheel sim | ||
// type shi pray emoji | ||
package frc.robot.subsystems.shooter; | ||
|
||
import edu.wpi.first.math.MathUtil; | ||
import edu.wpi.first.math.controller.PIDController; | ||
import edu.wpi.first.math.controller.SimpleMotorFeedforward; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.FlywheelSim; | ||
import edu.wpi.first.wpilibj.simulation.DCMotorSim; | ||
|
||
public class FlywheelIOSim implements FlywheelIO { | ||
private FlywheelSim sim = new FlywheelSim(DCMotor.getNEO(1), 1.5, 0.004); | ||
private PIDController pid = new PIDController(0.0, 0.0, 0.0); | ||
|
||
private boolean closedLoop = false; | ||
private double ffVolts = 0.0; | ||
public class ShooterIOSim implements ShooterIO { | ||
private DCMotorSim sim = new DCMotorSim(DCMotor.getNEO(1), 1.5, 0.004); | ||
private double appliedVolts = 0.0; | ||
private SimpleMotorFeedforward ffmodel = new SimpleMotorFeedforward(0, 0); | ||
|
||
@Override | ||
public void updateInputs(FlywheelIOInputs inputs) { | ||
if (closedLoop) { | ||
appliedVolts = | ||
MathUtil.clamp(pid.calculate(sim.getAngularVelocityRadPerSec()) + ffVolts, -12.0, 12.0); | ||
sim.setInputVoltage(appliedVolts); | ||
} | ||
|
||
sim.update(0.02); | ||
|
||
inputs.positionRad = 0.0; | ||
inputs.velocityRadPerSec = sim.getAngularVelocityRadPerSec(); | ||
inputs.appliedVolts = appliedVolts; | ||
inputs.currentAmps = new double[] {sim.getCurrentDrawAmps()}; | ||
} | ||
|
||
@Override | ||
public void setVoltage(double volts) { | ||
closedLoop = false; | ||
appliedVolts = volts; | ||
sim.setInputVoltage(volts); | ||
public void setVoltage(double voltage) { | ||
appliedVolts = voltage; | ||
sim.setInputVoltage(voltage); | ||
} | ||
|
||
@Override | ||
public void setVelocity(double velocityRadPerSec, double ffVolts) { | ||
closedLoop = true; | ||
pid.setSetpoint(velocityRadPerSec); | ||
this.ffVolts = ffVolts; | ||
public void setVelocity(double velocity) { | ||
setVoltage(ffmodel.calculate(velocity)); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
setVoltage(0.0); | ||
} | ||
public void updateInputs(ShooterIOInputs inputs) { | ||
sim.update(0.02); | ||
|
||
@Override | ||
public void configurePID(double kP, double kI, double kD) { | ||
pid.setPID(kP, kI, kD); | ||
inputs.topMotorVelocity = sim.getAngularVelocityRPM(); | ||
inputs.bottomMotorVelocity = sim.getAngularVelocityRPM(); | ||
inputs.topAppliedVolts = appliedVolts; | ||
inputs.bottomAppliedVolts = appliedVolts; | ||
inputs.topOutputCurrent = sim.getCurrentDrawAmps(); | ||
inputs.bottomOutputCurrent = sim.getCurrentDrawAmps(); | ||
} | ||
} |