-
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.
Basic indexer implemented to help with Shooter testing
- Loading branch information
1 parent
9a3e1c2
commit 52f4572
Showing
10 changed files
with
166 additions
and
5 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
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
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,17 @@ | ||
package frc.robot.subsystems.indexer; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.Commands; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public class Indexer extends SubsystemBase { | ||
private IndexerIO m_io; | ||
|
||
public Indexer(IndexerIO io) { | ||
m_io = io; | ||
} | ||
|
||
public Command runIndexer(double voltage) { | ||
return Commands.runOnce(() -> m_io.setVoltage(voltage)); | ||
} | ||
} |
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,19 @@ | ||
package frc.robot.subsystems.indexer; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
import frc.lib.advantagekit.LoggedIO; | ||
|
||
public interface IndexerIO extends LoggedIO<IndexerIO.IndexerInputs> { | ||
@AutoLog | ||
public static class IndexerInputs { | ||
public double curVelocity; | ||
public double curVoltage; | ||
public double curAmps; | ||
public boolean beamBreakOneBroken; | ||
public boolean beamBreakTwoBroken; | ||
} | ||
|
||
public void setVoltage(double voltage); | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/frc/robot/subsystems/indexer/IndexerIOFalcon.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,48 @@ | ||
package frc.robot.subsystems.indexer; | ||
|
||
import com.ctre.phoenix6.BaseStatusSignal; | ||
import com.ctre.phoenix6.StatusSignal; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
|
||
import edu.wpi.first.math.util.Units; | ||
import edu.wpi.first.wpilibj.DigitalInput; | ||
|
||
public class IndexerIOFalcon implements IndexerIO { | ||
private TalonFX m_indexerMotor; | ||
private DigitalInput m_beamBreakOne; | ||
private DigitalInput m_beamBreakTwo; | ||
|
||
private StatusSignal<Double> m_curVelocity; | ||
private StatusSignal<Double> m_curVoltage; | ||
private StatusSignal<Double> m_curAmps; | ||
|
||
public IndexerIOFalcon(int motorPort, int beamBreakOnePort, int beamBreakTwoPort) { | ||
m_indexerMotor = new TalonFX(motorPort); | ||
m_beamBreakOne = new DigitalInput(beamBreakOnePort); | ||
m_beamBreakTwo = new DigitalInput(beamBreakTwoPort); | ||
|
||
m_curVelocity = m_indexerMotor.getVelocity(); | ||
m_curVoltage = m_indexerMotor.getMotorVoltage(); | ||
m_curAmps = m_indexerMotor.getSupplyCurrent(); | ||
} | ||
|
||
@Override | ||
public void updateInputs(IndexerInputs inputs) { | ||
BaseStatusSignal.refreshAll( | ||
m_curVelocity, | ||
m_curVoltage, | ||
m_curAmps | ||
); | ||
|
||
inputs.curVelocity = Units.rotationsToRadians(m_curVelocity.getValue()); | ||
inputs.curVoltage = m_curVoltage.getValue(); | ||
inputs.curAmps = m_curAmps.getValue(); | ||
inputs.beamBreakOneBroken = m_beamBreakOne.get(); | ||
inputs.beamBreakTwoBroken = m_beamBreakTwo.get(); | ||
} | ||
|
||
@Override | ||
public void setVoltage(double voltage) { | ||
m_indexerMotor.setVoltage(voltage); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/frc/robot/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,43 @@ | ||
package frc.robot.subsystems.indexer; | ||
|
||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.DCMotorSim; | ||
import edu.wpi.first.wpilibj.simulation.DIOSim; | ||
import frc.robot.Constants.Ports; | ||
|
||
public class IndexerIOSim implements IndexerIO { | ||
private DCMotorSim m_motorSim; | ||
private double m_curVoltage; | ||
private DIOSim m_beamBreakOne; | ||
private DIOSim m_beamBreakTwo; | ||
|
||
public IndexerIOSim() { | ||
double simGearing = 1.0; | ||
double simJkGMetersSquared = 1.0; | ||
m_motorSim = new DCMotorSim( | ||
DCMotor.getFalcon500(1), | ||
simGearing, | ||
simJkGMetersSquared | ||
); | ||
|
||
m_beamBreakOne = new DIOSim(Ports.kIndexerBeamBreakOne); | ||
m_beamBreakTwo = new DIOSim(Ports.kIndexerBeamBreakTwo); | ||
} | ||
|
||
@Override | ||
public void updateInputs(IndexerInputs inputs) { | ||
m_motorSim.update(0.02); | ||
|
||
inputs.curVoltage = m_curVoltage; | ||
inputs.curVelocity = m_motorSim.getAngularVelocityRadPerSec(); | ||
inputs.curAmps = m_motorSim.getCurrentDrawAmps(); | ||
inputs.beamBreakOneBroken = m_beamBreakOne.getValue(); | ||
inputs.beamBreakTwoBroken = m_beamBreakTwo.getValue(); | ||
} | ||
|
||
@Override | ||
public void setVoltage(double voltage) { | ||
m_motorSim.setInputVoltage(voltage); | ||
m_curVoltage = voltage; | ||
} | ||
} |