Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2-ball Internals #20

Merged
merged 7 commits into from
Feb 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions src/main/java/frc/robot/subsystems/internals/InternalSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ public InternalSubsystem(TurretSubsystem turretSubsystem) {
public void periodic() {
// Check sensors for incoming and exiting balls and update ball counts accordingly
boolean entranceDetected = entrance.get() >= 0.4;
if (!prevEntranceDetected && entranceDetected) entranceStorageBallCount++;
if (!prevEntranceDetected && entranceDetected) {
entranceStorageBallCount++;
System.out.println("entrance ball detected");
//TODO shouldn't this set rejectingChecked to false?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not, because we only want to tell the turret to reject based on the color of the first ball. That's why rejectingChecked exists in the first place -- to not have a second ball in storage override the rejection logic for the first ball.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oop i thought i deleted that TODO but yes, i did follow that logic

}
prevEntranceDetected = entranceDetected;

Color storageColor = matchColor(colorSensorThread.getLastStorage());
//System.out.println("storage color:: " + colorToString(storageColor));
boolean storageDetected = isBall(storageColor);
if (storageDetected) System.out.println("storage ball detected");
if (!prevStorageDetected && storageDetected) {
// If we haven't already checked rejection logic, reject the ball if it doesn't match alliance color
if (!rejectingChecked) {
Expand All @@ -114,13 +120,17 @@ public void periodic() {
}
entranceStorageBallCount--;
storageStagingBallCount++;
System.out.println();
System.out.println("new storage detected, - entrance + storage from prev storage detected");
}
prevStorageDetected = storageDetected;

boolean stagingDetected = staging.get() >= 0.2;
boolean stagingDetected = staging.get() >= 0.13;
if (stagingDetected) System.out.println("staging ball detected");
if (!prevStagingDetected && stagingDetected) {
storageStagingBallCount--;
stagingExitBallCount++;
System.out.println("ball moved from storage to staging");
}
prevStagingDetected = stagingDetected;

Expand All @@ -145,20 +155,28 @@ public void periodic() {
if (shotRequested /* && turretSubsystem.getState() == TurretSubsystem.ModuleState.HIGH_TOLERANCE
|| rejecting && turretSubsystem.getState() == TurretSubsystem.ModuleState.LOW_TOLERANCE */) {
// Spin the top motor on a timer
exitTimer.start();
motorTop.set(0.5);

// If 1.5 seconds have elapsed, mark the shot as finished
if (exitTimer.hasElapsed(1.5)) {
exitTimer.stop();
exitTimer.reset();
motorTop.set(0);

// Reset states
if (!stagingDetected) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't set shotRequested to false if there's not a ball in staging. The idea of shotRequested is that the driver tells internals to shoot by setting the boolean to true, and internals will fire the ball as soon as everything is ready; shotRequested is just a way of saying "please shoot the next ball you get". Setting it to false if there's not a staging ball would break being able to press it when internals isn't fully ready yet.

shotRequested = false;
rejectingChecked = false;
stagingExitBallCount--;
System.out.println("false alarm");
} else {
exitTimer.start();
motorTop.set(0.5);

// If 1.5 seconds have elapsed, mark the shot as finished
if (exitTimer.hasElapsed(1.5)) {
exitTimer.stop();
exitTimer.reset();
motorTop.set(0);

// Reset states
shotRequested = false;
rejectingChecked = false;
stagingExitBallCount--;
System.out.println("ball exited");
}
}

}
}
}
Expand Down