Skip to content

Commit 76bd815

Browse files
committed
subsystem written, add constants and motor configs
1 parent c567192 commit 76bd815

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.stuypulse.robot.subsystems.indexer;
2+
3+
import com.stuypulse.robot.Robot;
4+
5+
import edu.wpi.first.wpilibj2.command.SubsystemBase;
6+
7+
public abstract class Indexer extends SubsystemBase {
8+
9+
private static final Indexer instance;
10+
11+
static {
12+
if (Robot.isReal()) {
13+
instance = new IndexerImpl();
14+
} else {
15+
instance = new IndexerImpl(); // update
16+
}
17+
}
18+
19+
public static Indexer getInstance() {
20+
return instance;
21+
}
22+
23+
public enum IndexerState {
24+
INTAKE(1),
25+
OUTTAKE(-1),
26+
STANDBY(0);
27+
28+
private double speed;
29+
30+
private IndexerState(double speed) {
31+
this.speed = speed;
32+
}
33+
public double getSpeed() {
34+
return speed;
35+
}
36+
}
37+
38+
private IndexerState state;
39+
40+
public Indexer() {
41+
this.state = IndexerState.STANDBY;
42+
}
43+
44+
public IndexerState getState() {
45+
return state;
46+
}
47+
48+
public void setState(IndexerState state) {
49+
this.state = state;
50+
}
51+
52+
public abstract boolean coralInPlace();
53+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.stuypulse.robot.subsystems.indexer;
2+
3+
import com.ctre.phoenix6.hardware.TalonFX;
4+
import com.stuypulse.robot.constants.Settings;
5+
import com.stuypulse.stuylib.streams.booleans.BStream;
6+
import com.stuypulse.stuylib.streams.booleans.filters.BDebounce;
7+
8+
import edu.wpi.first.wpilibj.DigitalInput;
9+
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
10+
11+
public class IndexerImpl extends Indexer {
12+
13+
private final TalonFX leftMotor;
14+
private final TalonFX rightMotor;
15+
private final DigitalInput frontBeamBreak;
16+
private final DigitalInput backBeamBreak;
17+
private final BStream passedFrontBeam;
18+
private final BStream passedBackBeam;
19+
20+
public IndexerImpl() {
21+
22+
leftMotor = new TalonFX(0,"");
23+
rightMotor = new TalonFX(1, "");
24+
// motor configs go here
25+
frontBeamBreak = new DigitalInput(0);
26+
backBeamBreak = new DigitalInput(1);
27+
28+
passedFrontBeam = BStream.create(frontBeamBreak).not()
29+
.filtered(new BDebounce.Both(0.01));
30+
passedBackBeam = BStream.create(backBeamBreak).not()
31+
.filtered(new BDebounce.Both(0.01));
32+
}
33+
34+
public boolean coralInPlace() {
35+
if (passedFrontBeam.get() && passedBackBeam.get()) {
36+
return true;
37+
}
38+
return false;
39+
}
40+
41+
@Override
42+
public void periodic() {
43+
super.periodic();
44+
45+
leftMotor.set(getState().getSpeed());
46+
rightMotor.set(getState().getSpeed());
47+
48+
SmartDashboard.putBoolean("Shooter/Coral in Place", coralInPlace());
49+
50+
51+
}
52+
}

0 commit comments

Comments
 (0)