-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
82 additions
and
13 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
51 changes: 51 additions & 0 deletions
51
src/main/java/org/team1540/robot2024/subsystems/indexer/IndexerIOSim.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.team1540.robot2024.subsystems.indexer; | ||
|
||
import edu.wpi.first.math.MathUtil; | ||
import edu.wpi.first.math.controller.PIDController; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.DCMotorSim; | ||
import edu.wpi.first.wpilibj.simulation.SimDeviceSim; | ||
import org.team1540.robot2024.Constants; | ||
|
||
import static org.team1540.robot2024.Constants.Indexer.*; | ||
|
||
public class IndexerIOSim implements IndexerIO { | ||
|
||
|
||
private final DCMotorSim intakeSim = new DCMotorSim(DCMotor.getNEO(1), INTAKE_GEAR_RATIO,0.025); | ||
private final DCMotorSim feederSim = new DCMotorSim(DCMotor.getNEO(1), FEEDER_GEAR_RATIO,0.025); | ||
private final SimDeviceSim beamBreakSim = new SimDeviceSim("Indexer Beam Break"); | ||
private final PIDController feederSimPID = new PIDController(FEEDER_KP, FEEDER_KI,FEEDER_KD); | ||
|
||
@Override | ||
public void updateInputs(IndexerIOInputs inputs) { | ||
intakeSim.update(Constants.LOOP_PERIOD_SECS); | ||
feederSim.update(Constants.LOOP_PERIOD_SECS); | ||
inputs.intakeCurrentAmps = intakeSim.getCurrentDrawAmps(); | ||
// inputs.intakeVoltage = intakeSim.getBusVoltage() * intakeSim.getAppliedOutput(); | ||
inputs.intakeVelocityRPM = intakeSim.getAngularVelocityRPM(); | ||
inputs.feederCurrentAmps = feederSim.getCurrentDrawAmps(); | ||
// inputs.feederVoltage = feederSim.getBusVoltage() * feederSim.getAppliedOutput(); | ||
inputs.feederVelocityRPM = feederSim.getAngularVelocityRPM(); | ||
inputs.noteInIntake = beamBreakSim.getBoolean("Indexer Beam Break").get(); | ||
|
||
// this is a very funny line of code, and absolutely does not belong here, but I don't know how to do this otherwise | ||
feederSim.setState(feederSim.getAngularPositionRad(), feederSimPID.calculate(feederSim.getAngularVelocityRadPerSec())); | ||
|
||
} | ||
|
||
@Override | ||
public void setIntakeVoltage(double volts) { | ||
intakeSim.setInputVoltage(MathUtil.clamp(volts, -12, 12)); | ||
} | ||
|
||
@Override | ||
public void setFeederVelocity(double velocity) { | ||
feederSimPID.setSetpoint(velocity); | ||
} | ||
|
||
@Override | ||
public void setFeederVoltage(double volts) { | ||
feederSim.setInputVoltage(MathUtil.clamp(volts, -12, 12)); | ||
} | ||
} |
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