mirror of
https://github.com/Team4388/2025RidgeScape.git
synced 2026-06-09 00:38:02 -06:00
Merge DeferredBlockMulti
This commit is contained in:
@@ -20,7 +20,6 @@ import edu.wpi.first.wpilibj2.command.CommandScheduler;
|
|||||||
import frc4388.robot.constants.BuildConstants;
|
import frc4388.robot.constants.BuildConstants;
|
||||||
import frc4388.robot.constants.Constants.SimConstants;
|
import frc4388.robot.constants.Constants.SimConstants;
|
||||||
import frc4388.utility.DeferredBlock;
|
import frc4388.utility.DeferredBlock;
|
||||||
import frc4388.utility.DeferredBlockMulti;
|
|
||||||
import frc4388.utility.Trim;
|
import frc4388.utility.Trim;
|
||||||
import frc4388.utility.compute.RobotTime;
|
import frc4388.utility.compute.RobotTime;
|
||||||
import frc4388.utility.status.FaultReporter;
|
import frc4388.utility.status.FaultReporter;
|
||||||
@@ -95,7 +94,6 @@ public class Robot extends LoggedRobot {
|
|||||||
@Override
|
@Override
|
||||||
public void disabledExit() {
|
public void disabledExit() {
|
||||||
DeferredBlock.execute();
|
DeferredBlock.execute();
|
||||||
DeferredBlockMulti.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ import frc4388.robot.subsystems.SwerveDrive;
|
|||||||
|
|
||||||
// Utilites
|
// Utilites
|
||||||
import frc4388.utility.DeferredBlock;
|
import frc4388.utility.DeferredBlock;
|
||||||
import frc4388.utility.DeferredBlockMulti;
|
|
||||||
import frc4388.utility.compute.TimesNegativeOne;
|
import frc4388.utility.compute.TimesNegativeOne;
|
||||||
import frc4388.utility.compute.ReefPositionHelper.Side;
|
import frc4388.utility.compute.ReefPositionHelper.Side;
|
||||||
|
|
||||||
@@ -590,12 +589,14 @@ public class RobotContainer {
|
|||||||
|
|
||||||
configureButtonBindings();
|
configureButtonBindings();
|
||||||
configureVirtualButtonBindings();
|
configureVirtualButtonBindings();
|
||||||
new DeferredBlock(() -> { // Called on first robot enable
|
|
||||||
|
DeferredBlock.addBlock(() -> { // Called on first robot enable
|
||||||
m_robotSwerveDrive.resetGyro();
|
m_robotSwerveDrive.resetGyro();
|
||||||
});
|
}, false);
|
||||||
new DeferredBlockMulti(() -> { // Called on every robot enable
|
DeferredBlock.addBlock(() -> { // Called on every robot enable
|
||||||
TimesNegativeOne.update();
|
TimesNegativeOne.update();
|
||||||
});
|
}, true);
|
||||||
|
|
||||||
DriverStation.silenceJoystickConnectionWarning(true);
|
DriverStation.silenceJoystickConnectionWarning(true);
|
||||||
// CameraServer.startAutomaticCapture();
|
// CameraServer.startAutomaticCapture();
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class DiffDrive extends SubsystemBase implements Queryable {
|
|||||||
private TalonFX m_leftBackMotor;
|
private TalonFX m_leftBackMotor;
|
||||||
private TalonFX m_rightBackMotor;
|
private TalonFX m_rightBackMotor;
|
||||||
private DifferentialDrive m_driveTrain;
|
private DifferentialDrive m_driveTrain;
|
||||||
private Pigeon2 m_gyro;
|
// private Pigeon2 m_gyro;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add your docs here.
|
* Add your docs here.
|
||||||
@@ -51,7 +51,7 @@ public class DiffDrive extends SubsystemBase implements Queryable {
|
|||||||
m_leftBackMotor .setControl(new Follower(m_leftFrontMotor.getDeviceID(), false));
|
m_leftBackMotor .setControl(new Follower(m_leftFrontMotor.getDeviceID(), false));
|
||||||
m_rightBackMotor.setControl(new Follower(m_rightBackMotor.getDeviceID(), false));
|
m_rightBackMotor.setControl(new Follower(m_rightBackMotor.getDeviceID(), false));
|
||||||
m_driveTrain = driveTrain;
|
m_driveTrain = driveTrain;
|
||||||
m_gyro = gyro;
|
// m_gyro = gyro;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,22 +2,40 @@ package frc4388.utility;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
// Class for running code snippets whenever the robot is enabled.
|
||||||
public class DeferredBlock {
|
public class DeferredBlock {
|
||||||
private static ArrayList<Runnable> m_blocks = new ArrayList<>();
|
private static ArrayList<Runnable> m_blocks_norerun = new ArrayList<>();
|
||||||
|
private static ArrayList<Runnable> m_blocks_rerun = new ArrayList<>();
|
||||||
private static boolean m_hasRun = false;
|
private static boolean m_hasRun = false;
|
||||||
|
|
||||||
public DeferredBlock(Runnable block) {
|
public static void addBlock(Runnable block) {
|
||||||
m_blocks.add(block);
|
addBlock(block, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void addBlock(Runnable block, boolean rerun) {
|
||||||
|
if(rerun) {
|
||||||
|
m_blocks_rerun.add(block);
|
||||||
|
} else {
|
||||||
|
m_blocks_norerun.add(block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void execute() {
|
public static void execute() {
|
||||||
if (m_hasRun) return;
|
|
||||||
|
|
||||||
for (Runnable block : m_blocks) {
|
// Run blocks that run multiple times.
|
||||||
|
for (Runnable block : m_blocks_rerun) {
|
||||||
block.run();
|
block.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_blocks.clear(); // for garbage collection
|
// Run blocks that only run once
|
||||||
|
if (m_hasRun) return;
|
||||||
|
|
||||||
|
for (Runnable block : m_blocks_norerun) {
|
||||||
|
block.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_blocks_norerun.clear(); // for garbage collection
|
||||||
m_hasRun = true;
|
m_hasRun = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
package frc4388.utility;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class DeferredBlockMulti {
|
|
||||||
private static ArrayList<Runnable> m_blocks = new ArrayList<>();
|
|
||||||
|
|
||||||
public DeferredBlockMulti(Runnable block) {
|
|
||||||
m_blocks.add(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void execute() {
|
|
||||||
|
|
||||||
for (Runnable block : m_blocks) {
|
|
||||||
block.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user