diff --git a/src/main/java/org/lasarobotics/fsm/StateCommand.java b/src/main/java/org/lasarobotics/fsm/StateCommand.java new file mode 100644 index 00000000..eeb9f28f --- /dev/null +++ b/src/main/java/org/lasarobotics/fsm/StateCommand.java @@ -0,0 +1,76 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package org.lasarobotics.fsm; + +import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; + +import java.util.function.Supplier; + +import edu.wpi.first.util.sendable.SendableBuilder; +import edu.wpi.first.wpilibj2.command.Command; + +/** + * A command composition that runs one of a selection of commands using a selector and a key to + * command mapping. + * + *
The rules for command compositions apply: command instances that are passed to it cannot be + * added to any other composition or scheduled individually, and the composition requires all + * subsystems its components require. + * + *
This class is provided by the NewCommands VendorDep
+ *
+ * @param
+ * ONLY TO BE USED BY {@link StateCommand#end(boolean)}
+ */
+ void setState(SystemState state) {
+ m_currentState = state;
+ }
+
+ /**
+ * Get current system state
+ * @return Current system state
+ */
+ public SystemState getState() {
+ return m_currentState;
+ }
+
+ @Override
+ public void setDefaultCommand(Command commmand) {
+ return;
+ }
+}
diff --git a/src/main/java/org/lasarobotics/fsm/SystemState.java b/src/main/java/org/lasarobotics/fsm/SystemState.java
new file mode 100644
index 00000000..f00916d2
--- /dev/null
+++ b/src/main/java/org/lasarobotics/fsm/SystemState.java
@@ -0,0 +1,25 @@
+package org.lasarobotics.fsm;
+
+public interface SystemState {
+ /**
+ * Initial action of state. Called once when state is initially scheduled
+ */
+ public default void initialize() {}
+
+ /**
+ * Main body of state. Called repeatedly when state is scheduled.
+ */
+ public default void execute() {}
+
+ /**
+ * The action to take when the state ends. Called when either the state finishes normally, or when it interrupted/canceled.
+ * @param interrupted Whether the state was interrupted or cancelled
+ */
+ public default void end(boolean interrupted) {}
+
+ /**
+ * Get next state based on variety of inputs. Also used to know if current state is complete.
+ * @return Next state
+ */
+ public SystemState nextState();
+}