Skip to content

Commit fc298d2

Browse files
author
ethan jones
committed
simmed beambreaks
1 parent 1ba87d8 commit fc298d2

File tree

5 files changed

+92
-26
lines changed

5 files changed

+92
-26
lines changed

Diff for: src/main/java/org/sciborgs1155/robot/commands/NoteVisualizer.java

+38-18
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class NoteVisualizer implements Logged {
4949
private static boolean carryingNote = true;
5050
private static List<Pose3d> pathPosition = new ArrayList<>();
5151

52+
private static boolean intakeBeam = true;
53+
private static boolean feederBeam = true;
54+
5255
// suppliers
5356
private static Supplier<Pose2d> drive = Pose2d::new;
5457
private static Supplier<Pose3d> shooter = Pose3d::new;
@@ -99,24 +102,31 @@ public static Command intake() {
99102
if (carryingNote) {
100103
return Commands.none();
101104
}
102-
return Commands.run(
103-
() -> {
104-
Pose2d intakePose = drive.get();
105-
for (Pose3d note : notes) {
106-
double distance =
107-
Math.abs(
108-
note.getTranslation()
109-
.toTranslation2d()
110-
.getDistance(intakePose.getTranslation()));
111-
if (distance > 0.6) {
112-
continue;
113-
}
114-
carryingNote = true;
115-
notes.remove(note);
116-
notesPub.set(notes.toArray(new Pose3d[0]));
117-
break;
118-
}
119-
});
105+
return Commands.runOnce(
106+
() -> {
107+
intakeBeam = false;
108+
Pose2d intakePose = drive.get();
109+
for (Pose3d note : notes) {
110+
double distance =
111+
Math.abs(
112+
note.getTranslation()
113+
.toTranslation2d()
114+
.getDistance(intakePose.getTranslation()));
115+
if (distance > 0.6) {
116+
continue;
117+
}
118+
notes.remove(note);
119+
notesPub.set(notes.toArray(new Pose3d[0]));
120+
break;
121+
}
122+
})
123+
.andThen(
124+
Commands.waitSeconds(.3),
125+
Commands.runOnce(
126+
() -> {
127+
carryingNote = true;
128+
intakeBeam = true;
129+
}));
120130
},
121131
Set.of()))
122132
.unless(Robot::isReal);
@@ -126,6 +136,7 @@ public static Command shoot() {
126136
return new ScheduleCommand(
127137
Commands.defer(
128138
() -> {
139+
feederBeam = false;
129140
var poses = generatePath();
130141
if (poses.length == 0) return Commands.runOnce(() -> {});
131142
step = 0;
@@ -142,6 +153,7 @@ public static Command shoot() {
142153
shotNotePub.set(new Pose3d());
143154
notePathPub.set(new Pose3d[0]);
144155
carryingNote = false;
156+
feederBeam = true;
145157
});
146158
},
147159
Set.of()))
@@ -154,6 +166,14 @@ public static boolean hasNote() {
154166
return carryingNote;
155167
}
156168

169+
public static boolean intakeBeam() {
170+
return intakeBeam;
171+
}
172+
173+
public static boolean feederBeam() {
174+
return feederBeam;
175+
}
176+
157177
private static Pose3d[] generatePath() {
158178
double shotVelocity = velocity.getAsDouble();
159179
ChassisSpeeds driveSpeeds = speeds.get();

Diff for: src/main/java/org/sciborgs1155/robot/feeder/Feeder.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package org.sciborgs1155.robot.feeder;
22

33
import static edu.wpi.first.units.Units.Seconds;
4-
import static org.sciborgs1155.robot.feeder.FeederConstants.DEBOUNCE_TIME;
54
import static org.sciborgs1155.robot.feeder.FeederConstants.POWER;
65
import static org.sciborgs1155.robot.feeder.FeederConstants.TIMEOUT;
76

8-
import edu.wpi.first.math.filter.Debouncer.DebounceType;
97
import edu.wpi.first.math.system.plant.DCMotor;
108
import edu.wpi.first.wpilibj2.command.Command;
119
import edu.wpi.first.wpilibj2.command.Commands;
@@ -22,7 +20,7 @@ public class Feeder extends SubsystemBase implements AutoCloseable, Logged {
2220

2321
/** Creates a real or non-existent feeder based on {@link Robot#isReal()}. */
2422
public static Feeder create() {
25-
return Robot.isReal() ? new Feeder(new RealFeeder()) : new Feeder(new NoFeeder());
23+
return Robot.isReal() ? new Feeder(new RealFeeder()) : new Feeder(new SimFeeder());
2624
}
2725

2826
/** Creates a non-existent feeder. */
@@ -32,6 +30,7 @@ public static Feeder none() {
3230

3331
public Feeder(FeederIO feeder) {
3432
this.feeder = feeder;
33+
noteAtShooter().onTrue(Commands.runOnce(() -> System.out.println("note at shooter")));
3534
}
3635

3736
public Command runFeeder(double power) {
@@ -60,6 +59,7 @@ public Command backward() {
6059
*/
6160
public Command eject() {
6261
return Commands.waitUntil(noteAtShooter())
62+
.andThen(Commands.runOnce(() -> System.out.println("moved on")))
6363
.andThen(Commands.waitUntil(noteAtShooter().negate()))
6464
.deadlineWith(forward())
6565
.alongWith(NoteVisualizer.shoot())
@@ -76,9 +76,13 @@ public Command retract() {
7676
* @return A trigger based on the upper feeder beambreak.
7777
*/
7878
public Trigger noteAtShooter() {
79-
return new Trigger(feeder::beambreak)
80-
.negate()
81-
.debounce(DEBOUNCE_TIME.in(Seconds), DebounceType.kFalling);
79+
return new Trigger(feeder::beambreak).negate();
80+
// .debounce(DEBOUNCE_TIME.in(Seconds), DebounceType.kFalling);
81+
}
82+
83+
@Log.NT
84+
public boolean beambreak() {
85+
return feeder.beambreak();
8286
}
8387

8488
@Log.NT

Diff for: src/main/java/org/sciborgs1155/robot/feeder/SimFeeder.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import edu.wpi.first.wpilibj.simulation.DCMotorSim;
99
import monologue.Annotations.Log;
1010
import org.sciborgs1155.robot.Constants;
11+
import org.sciborgs1155.robot.commands.NoteVisualizer;
1112

1213
public class SimFeeder implements FeederIO {
1314
private final DCMotorSim sim =
@@ -22,7 +23,7 @@ public void setPower(double voltage) {
2223
@Override
2324
@Log.NT
2425
public boolean beambreak() {
25-
return true;
26+
return NoteVisualizer.feederBeam();
2627
}
2728

2829
@Override

Diff for: src/main/java/org/sciborgs1155/robot/intake/Intake.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
public class Intake extends SubsystemBase implements Logged, AutoCloseable {
2020
public static Intake create() {
21-
return Robot.isReal() ? new Intake(new RealIntake()) : new Intake(new NoIntake());
21+
return Robot.isReal() ? new Intake(new RealIntake()) : new Intake(new SimIntake());
2222
}
2323

2424
public static Intake none() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.sciborgs1155.robot.intake;
2+
3+
import static edu.wpi.first.units.Units.Seconds;
4+
import static org.sciborgs1155.robot.feeder.FeederConstants.*;
5+
6+
import edu.wpi.first.math.system.plant.DCMotor;
7+
import edu.wpi.first.math.system.plant.LinearSystemId;
8+
import edu.wpi.first.wpilibj.simulation.DCMotorSim;
9+
import monologue.Annotations.Log;
10+
import org.sciborgs1155.robot.Constants;
11+
import org.sciborgs1155.robot.commands.NoteVisualizer;
12+
13+
public class SimIntake implements IntakeIO {
14+
private final DCMotorSim sim =
15+
new DCMotorSim(LinearSystemId.createDCMotorSystem(kV, kA), DCMotor.getNeoVortex(1), GEARING);
16+
17+
@Override
18+
public void setPower(double voltage) {
19+
sim.setInputVoltage(voltage);
20+
sim.update(Constants.PERIOD.in(Seconds));
21+
}
22+
23+
@Override
24+
@Log.NT
25+
public boolean beambreak() {
26+
return NoteVisualizer.feederBeam();
27+
}
28+
29+
@Override
30+
public double current() {
31+
return sim.getCurrentDrawAmps();
32+
}
33+
34+
@Override
35+
public boolean seenNote() {
36+
return NoteVisualizer.hasNote();
37+
}
38+
39+
@Override
40+
public void close() throws Exception {}
41+
}

0 commit comments

Comments
 (0)