Skip to content

Commit

Permalink
finished mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan1522 authored Oct 9, 2024
1 parent c213c35 commit dd04881
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/main/java/frc/robot/subsystems/indexer/Indexer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package frc.robot.subsystems.indexer;

public class Indexer extends SubsystemBase {
private IndexerIOInputs io
private IndexerIOInputsAutoLogged inputs = new IndexerIOInputsAutoLogged();

public Indexer(IndexerIOInputs io) {
this.io = io;
}

public setIndexerSpeed(double speed) {
io.setSpeed(speed);
Logger.recordOutput("Indexer", speed);
}

public stop() {
io.stop();
}

@Override
public void periodic() {
io.updateInputs(inputs);
Logger.processInputs("Indexer", inputs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package frc.robot.subsystems.indexer;

public final class IndexerConstants {}
28 changes: 28 additions & 0 deletions src/main/java/frc/robot/subsystems/indexer/IndexerIOSim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package frc.robot.subsystems.indexer;

public class IndexerIOSim implements IndexerIO {
private final DCMotorSim indexerSim = new DCMotor(null, 0, 0);

private double indexerAppliedVolts = 0.0;

public IndexerIO() {
indexerSim.update(0.02);

inputs.isConnected = true;

inputs.indexerVelocity = intakeSim.getVelocityRadPerSec() / (Math.PI * 2);
inputs.indexerStatorCurrentAmps = intakeSim.getCurrentDrawAmps();
inputs.indexerAppliedVolts = intakeAppliedVolts;
}

@Override
public void setIndexerSpeed(double speed) {
indexerSim.setInputVoltage(speed);
}

@Override
public void stop() {
indexerSim.setInputVoltage(0);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package frc.robot.subsystems.intake;

public final class IntakeConstants {}
43 changes: 43 additions & 0 deletions src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,47 @@
public class IntakeIOSim {
DCMotorSim intakeSim = new DCMotorSim(null, 0, 0);
SingleJointedArmSim pivotSim = new SingleJointedArmSim(DCMotor.getFalcon500(2), 0, 0, 0, 0, 0, false, 0);
private final Constraints pivotConstraints = new Constraints(0, 0);
private final ProfiledPIDController pivotController =
new ProfiledPIDController(0, 0, 0, pivotConstraints);

private final SimpleMotorFeedforward pivotFF = new SimpleMotorFeedforward(0, 0, 0);

private double intakeAppliedVolts = 0.0;
private double pivotAppliedVolts = 0.0;


public IntakeIOSim() {
intakeSim.update(0.02);
pivotSim.update(0.02);

inputs.intakeVelocity = intakeSim.getVelocityRadPerSec() / (Math.PI * 2);
inputs.intakeCurrentAmps = intakeSim.getCurrentDrawAmps();
inputs.intakeAppliedVolts = intakeAppliedVolts;

inputs.pivotPosition = pivotSim.getAngleRads() / (Math.PI * 2);
inputs.pivotVelocity = pivotSim.getVelocityRadPerSec() / (Math.PI * 2);
inputs.pivotAppliedVolts = pivotAppliedVolts;
inputs.pivotCurrentAmps = pivotSime.getCurrentDrawAmps();
}

@Override
public void setPivotPosition(double position) {
pivotSim.setInputVoltage(pivotController.calculate(position, pivotSim.getAngleRads() / (Math.PI * 2)) + pivotFF.calculate(pivotContoller.getSetpoint().velocity))
}

@Override
public void setIntakeSpeed(double speed) {
intakeSim.setInputVoltage(speed);
}

@Override
public double getIntakeSpeed() {
return intakeSim.getVelocityRadPerSec() / (Math.PI * 2)
}

@Override
public double getPivotPosition() {
return pivotSim.getAngleRads() / (Math.PI * 2);
}
}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/subsystems/pivot/PivotIOSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void updateInputs(PivotIOInputs inputs) {
inputs.leaderPosition = (pivotSim.getAngleRads() / Math.PI * 2); // Rotations
inputs.leaderVelocity = (pivotSim.getVelocityRadPerSec() / Math.PI * 2); // Rotations/Sec
inputs.leaderAppliedVolts = leaderAppliedVolts;
;

inputs.leaderSupplyCurrentAmps = pivotSim.getCurrentDrawAmps();

inputs.followerPosition = (pivotSim.getAngleRads() / Math.PI * 2); // Rotations
Expand Down

0 comments on commit dd04881

Please sign in to comment.