Improve Storage Commands

This commit is contained in:
Keenan D. Buckley
2020-03-08 13:33:57 -06:00
parent 32152080f2
commit 0db12332dc
4 changed files with 22 additions and 21 deletions
+1 -1
View File
@@ -162,7 +162,7 @@ public final class Constants {
public static final double STORAGE_PARTIAL_BALL = 2; public static final double STORAGE_PARTIAL_BALL = 2;
public static final double STORAGE_FULL_BALL = 7; public static final double STORAGE_FULL_BALL = 7;
public static final double STORAGE_SPEED = 0.5; public static final double STORAGE_SPEED = 0.5;
public static final double STORAGE_TIMEOUT = 2000; public static final double STORAGE_TIMEOUT = 3000;
/* Storage Characteristics */ /* Storage Characteristics */
public static final double MOTOR_ROTS_PER_STORAGE_ROT = 1; //For the first storage belt public static final double MOTOR_ROTS_PER_STORAGE_ROT = 1; //For the first storage belt
@@ -15,6 +15,9 @@ import frc4388.robot.subsystems.Storage;
public class ManageStorage extends CommandBase { public class ManageStorage extends CommandBase {
Storage m_storage; Storage m_storage;
/* Timer */
long m_resetStartTime;
/* Keeps track of which beam breaks are pressed */ /* Keeps track of which beam breaks are pressed */
boolean isBallInIntake = false; boolean isBallInIntake = false;
boolean isBallInStorage = false; boolean isBallInStorage = false;
@@ -46,6 +49,10 @@ public class ManageStorage extends CommandBase {
isBallInShooter = !m_storage.getBeamShooter(); isBallInShooter = !m_storage.getBeamShooter();
m_isStorageEmpty = !isBallInStorage; m_isStorageEmpty = !isBallInStorage;
if (m_storageMode == StorageMode.RESET) {
m_resetStartTime = System.currentTimeMillis();
}
} }
// Called every time the scheduler runs while the command is scheduled. // Called every time the scheduler runs while the command is scheduled.
@@ -76,13 +83,17 @@ public class ManageStorage extends CommandBase {
* storage sensor and the intake ball has taken its place. * storage sensor and the intake ball has taken its place.
*/ */
private void runIntake() { private void runIntake() {
m_storage.runStorage(StorageConstants.STORAGE_SPEED); if (!isBallInShooter) { // Intake balls as long as there is not a ball at the shooter
m_storage.runStorage(StorageConstants.STORAGE_SPEED);
if (!m_isStorageEmpty && !isBallInStorage) { if (!m_isStorageEmpty && !isBallInStorage) { // If ball moves out of storage, set storage to empty
m_isStorageEmpty = true; m_isStorageEmpty = true;
} }
if (m_isStorageEmpty && isBallInStorage) { if (m_isStorageEmpty && isBallInStorage) { // If Ball moves into storage, set storage to full and swtich to idle mode
m_isStorageEmpty = false; m_isStorageEmpty = false;
m_storageMode = StorageMode.IDLE;
}
} else {
m_storageMode = StorageMode.IDLE; m_storageMode = StorageMode.IDLE;
} }
} }
@@ -108,7 +119,7 @@ public class ManageStorage extends CommandBase {
private void runReset() { private void runReset() {
m_storage.runStorage(-StorageConstants.STORAGE_SPEED); m_storage.runStorage(-StorageConstants.STORAGE_SPEED);
if (isBallInIntake) { if (isBallInIntake || (m_resetStartTime + StorageConstants.STORAGE_TIMEOUT) < System.currentTimeMillis()) {
m_storageMode = StorageMode.INTAKE; m_storageMode = StorageMode.INTAKE;
} }
m_isStorageEmpty = !isBallInStorage; m_isStorageEmpty = !isBallInStorage;
@@ -35,7 +35,6 @@ public class StorageFire extends CommandBase {
// Called once the command ends or is interrupted. // Called once the command ends or is interrupted.
@Override @Override
public void end(boolean interrupted) { public void end(boolean interrupted) {
m_storage.runStorage(0);
} }
// Returns true when the command should end. // Returns true when the command should end.
@@ -7,7 +7,6 @@
package frc4388.robot.commands.storage; package frc4388.robot.commands.storage;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase; import edu.wpi.first.wpilibj2.command.CommandBase;
import frc4388.robot.Constants.StorageConstants; import frc4388.robot.Constants.StorageConstants;
import frc4388.robot.subsystems.Storage; import frc4388.robot.subsystems.Storage;
@@ -33,12 +32,7 @@ public class StoragePrep extends CommandBase {
// Called every time the scheduler runs while the command is scheduled. // Called every time the scheduler runs while the command is scheduled.
@Override @Override
public void execute() { public void execute() {
if (m_storage.getBeamShooter()){ m_storage.runStorage(StorageConstants.STORAGE_SPEED);
//m_storage.runStorage(StorageConstants.STORAGE_SPEED);
}
else{
m_storage.runStorage(0);
}
} }
// Called once the command ends or is interrupted. // Called once the command ends or is interrupted.
@@ -49,13 +43,10 @@ public class StoragePrep extends CommandBase {
// Returns true when the command should end. // Returns true when the command should end.
@Override @Override
public boolean isFinished() { public boolean isFinished() {
/*if (!m_storage.getBeam(1) || startTime + StorageConstants.STORAGE_TIMEOUT <= System.currentTimeMillis()){ if (!m_storage.getBeamShooter() || (startTime + StorageConstants.STORAGE_TIMEOUT) < System.currentTimeMillis()) {
m_storage.m_isStorageReadyToFire = true;
return true; return true;
} else { } else {
m_storage.m_isStorageReadyToFire = false;
return false; return false;
}*/ }
return true;
} }
} }