mirror of
https://github.com/TimeCrafters/FTC_2022
synced 2026-03-23 00:06:13 +00:00
Experimental: Added support to add states directly from a configuration with support for single depth parallel states; requires action comment to start with an @ symbol followed by the class name; assumes that the action name has a dash in its name.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package org.timecrafters.testing.engine;
|
||||
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
||||
|
||||
import org.cyberarm.engine.V2.CyberarmEngine;
|
||||
import org.cyberarm.engine.V2.CyberarmState;
|
||||
import org.timecrafters.TimeCraftersConfigurationTool.library.TimeCraftersConfiguration;
|
||||
|
||||
@TeleOp(name = "DynamicSetupEngine")
|
||||
public class DynamicSetupEngine extends CyberarmEngine {
|
||||
public class Robot {
|
||||
public TimeCraftersConfiguration configuration;
|
||||
|
||||
public Robot() {
|
||||
configuration = new TimeCraftersConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.showStateChildrenListInTelemetry = true;
|
||||
Robot robot = new Robot();
|
||||
|
||||
setupFromConfig(
|
||||
robot.configuration,
|
||||
"org.timecrafters.testing.states",
|
||||
robot,
|
||||
Robot.class,
|
||||
"LeftAutonomous"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.timecrafters.testing.states;
|
||||
|
||||
import org.cyberarm.engine.V2.CyberarmState;
|
||||
import org.timecrafters.testing.engine.DynamicSetupEngine;
|
||||
|
||||
public class DynamicSetupState extends CyberarmState {
|
||||
private long delay;
|
||||
|
||||
public DynamicSetupState(DynamicSetupEngine.Robot robot, String groupName, String actionName) {
|
||||
delay = robot.configuration.variable(groupName, actionName, "delay").value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec() {
|
||||
if (runTime() >= delay) {
|
||||
setHasFinished(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void telemetry() {
|
||||
engine.telemetry.addData("runTime", runTime());
|
||||
engine.telemetry.addData("delay", delay);
|
||||
engine.telemetry.addLine(progressBar(20, (runTime() / delay) * 100));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user