Added runTime method to CyberarmEngine (FTC's getRunTime starts when INIT is pressed, not when START is pressed), RedCrab: Make use of LED(s) for showing when it's time to launch ta drone and hook the bar

This commit is contained in:
2024-01-31 09:53:48 -06:00
parent 688ccdf70e
commit 1c71771034
7 changed files with 43 additions and 10 deletions

View File

@@ -41,6 +41,8 @@ public abstract class CyberarmEngine extends OpMode {
private GamepadChecker gamepadCheckerGamepad1, gamepadCheckerGamepad2;
private boolean useThreads = true;
private long startTime;
/**
* Called when INIT button on Driver Station is pushed
* ENSURE to call super.init() if you override this method
@@ -84,6 +86,8 @@ public abstract class CyberarmEngine extends OpMode {
* ENSURE to call super.start() if you override this method
*/
public void start() {
startTime = System.currentTimeMillis();
if (cyberarmStates.size() > 0) {
runState(cyberarmStates.get(0));
}
@@ -534,4 +538,12 @@ public abstract class CyberarmEngine extends OpMode {
public void threadless() {
useThreads = false;
}
/**
* Time in milliseconds since START button was pushed
* @return runTime
*/
public double runTime() {
return (System.currentTimeMillis() - startTime);
}
}

View File

@@ -91,6 +91,7 @@ public class RedCrabMinibot {
public final boolean LED_OFF = true, LED_ON = false;
final CyberarmEngine engine;
public final boolean autonomous;
public TimeCraftersConfiguration config;
private final PIDFController clawArmPIDFController;
@@ -125,6 +126,7 @@ public class RedCrabMinibot {
public RedCrabMinibot(boolean autonomous) {
engine = CyberarmEngine.instance;
this.autonomous = autonomous;
config = new TimeCraftersConfiguration("cyberarm_RedCrab");
loadConstants();

File diff suppressed because one or more lines are too long

View File

@@ -16,8 +16,31 @@ public abstract class RedCrabEngine extends CyberarmEngine {
super.loop();
if (robot != null)
robot.standardTelemetry();
robot.standardTelemetry();
if (robot.autonomous) {
if (runTime() < 20_000.0) { // KEEP CALM and CARRY ON
robot.redLED.setState(robot.LED_OFF);
robot.greenLED.setState(robot.LED_ON);
} else if (runTime() < 25_000.0) { // RUNNING LOW ON TIME
robot.redLED.setState(robot.LED_ON);
robot.greenLED.setState(robot.LED_ON);
} else { // 5 SECONDS LEFT!
robot.redLED.setState(robot.LED_ON);
robot.greenLED.setState(robot.LED_OFF);
}
} else {
if (runTime() >= 90_000.0) { // LAUNCH DRONE and DO CHIN UP
robot.redLED.setState(robot.LED_OFF);
robot.greenLED.setState(robot.LED_ON);
} else if (runTime() >= 80_000.0) { // GET READY
robot.redLED.setState(robot.LED_ON);
robot.greenLED.setState(robot.LED_ON);
} else { // KEEP CALM and CARRY ON
robot.redLED.setState(robot.LED_ON);
robot.greenLED.setState(robot.LED_OFF);
}
}
}
@Override

View File

@@ -15,8 +15,9 @@ public class RedCrabTeleOpDebuggingOnlyEngine extends RedCrabEngine {
public void setup() {
threadless();
robot = new RedCrabMinibot(false);
addState(new CyberarmState() {
final RedCrabMinibot robot = new RedCrabMinibot(false);
@Override
public void exec() {

View File

@@ -12,7 +12,7 @@ import dev.cyberarm.minibots.red_crab.states.Pilot;
public class RedCrabTeleOpEngine extends RedCrabEngine {
@Override
public void setup() {
RedCrabMinibot robot = new RedCrabMinibot(false);
robot = new RedCrabMinibot(false);
addTask(new ClawArmTask(robot));

View File

@@ -130,11 +130,6 @@ public class Pilot extends CyberarmState {
}
}
@Override
public void telemetry() {
robot.standardTelemetry();
}
private void drivetrain() {
// https://gm0.org/en/latest/docs/software/tutorials/mecanum-drive.html#field-centric