diff --git a/src/main/java/org/sciborgs1155/robot/Robot.java b/src/main/java/org/sciborgs1155/robot/Robot.java index c99532d..aa9dbbb 100644 --- a/src/main/java/org/sciborgs1155/robot/Robot.java +++ b/src/main/java/org/sciborgs1155/robot/Robot.java @@ -3,6 +3,7 @@ import edu.wpi.first.wpilibj.DataLogManager; import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import io.github.oblarg.oblog.Loggable; import io.github.oblarg.oblog.Logger; @@ -11,6 +12,7 @@ import org.sciborgs1155.lib.DeferredCommand; import org.sciborgs1155.robot.Ports.OI; import org.sciborgs1155.robot.commands.Autos; +import org.sciborgs1155.robot.exampleMechanism.Subsystem; /** * This class is where the bulk of the robot should be declared. Since Command-based is a @@ -25,6 +27,7 @@ public class Robot extends CommandRobot implements Loggable { private final CommandXboxController driver = new CommandXboxController(OI.DRIVER); // SUBSYSTEMS + @Log Subsystem mech = Subsystem.create(); // COMMANDS @Log Autos autos = new Autos(); @@ -60,7 +63,10 @@ private void configureGameBehavior() { private void configureSubsystemDefaults() {} /** Configures trigger -> command bindings */ - private void configureBindings() {} + private void configureBindings() { + // failing behavior + mech.onFailing(Commands.runOnce(() -> {})); + } /** The commamnd to be ran in autonomous */ public Command getAutonomousCommand() { diff --git a/src/main/java/org/sciborgs1155/robot/exampleMechanism/Subsystem.java b/src/main/java/org/sciborgs1155/robot/exampleMechanism/Subsystem.java index 5b30aeb..3a4d7d1 100644 --- a/src/main/java/org/sciborgs1155/robot/exampleMechanism/Subsystem.java +++ b/src/main/java/org/sciborgs1155/robot/exampleMechanism/Subsystem.java @@ -6,30 +6,29 @@ import edu.wpi.first.wpilibj2.command.CommandBase; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import io.github.oblarg.oblog.Loggable; +import io.github.oblarg.oblog.annotations.Log; import java.util.List; import org.sciborgs1155.lib.failure.Fallible; import org.sciborgs1155.lib.failure.HardwareFault; import org.sciborgs1155.robot.Robot; -import org.sciborgs1155.robot.exampleMechanism.exampleSubmechanism.EmptySubmech; -import org.sciborgs1155.robot.exampleMechanism.exampleSubmechanism.RealSubmech; -import org.sciborgs1155.robot.exampleMechanism.exampleSubmechanism.SimSubmech; -import org.sciborgs1155.robot.exampleMechanism.exampleSubmechanism.SubmechIO; +import org.sciborgs1155.robot.exampleMechanism.exampleSubmechanism.*; -public class Subsystem extends SubsystemBase implements Fallible, AutoCloseable { +public class Subsystem extends SubsystemBase implements Loggable, Fallible, AutoCloseable { - public static Subsystem createEmpty() { - return new Subsystem(new EmptySubmech()); + public static Subsystem createNone() { + return new Subsystem(new NoSubmech()); } public static Subsystem create() { return new Subsystem(Robot.isReal() ? new RealSubmech() : new SimSubmech()); } - private final SubmechIO mech; + @Log private final SubmechIO submech; /** Creates a new ExampleSubsystem. */ - public Subsystem(SubmechIO mech) { - this.mech = mech; + public Subsystem(SubmechIO submech) { + this.submech = submech; } /** @@ -53,7 +52,7 @@ public CommandBase exampleMethodCommand() { */ public boolean exampleCondition() { // Query some boolean state, such as a digital sensor. - return false; + return submech.condition(); } @Override @@ -69,12 +68,12 @@ public void simulationPeriodic() { @Override public List getFaults() { // TODO Auto-generated method stub - return mech.getFaults(); + return submech.getFaults(); } @Override public void close() throws Exception { - mech.close(); + submech.close(); // close all hardware that is AutoClosable. Used for unit tests } } diff --git a/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/EmptySubmech.java b/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/NoSubmech.java similarity index 72% rename from src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/EmptySubmech.java rename to src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/NoSubmech.java index d0d8e92..a132440 100644 --- a/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/EmptySubmech.java +++ b/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/NoSubmech.java @@ -3,9 +3,14 @@ import java.util.List; import org.sciborgs1155.lib.failure.HardwareFault; -public class EmptySubmech implements SubmechIO { +public class NoSubmech implements SubmechIO { - public EmptySubmech() {} + public NoSubmech() {} + + @Override + public boolean condition() { + return false; + } @Override public List getFaults() { diff --git a/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/RealSubmech.java b/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/RealSubmech.java index bf4d653..8fa2db6 100644 --- a/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/RealSubmech.java +++ b/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/RealSubmech.java @@ -8,6 +8,12 @@ public class RealSubmech implements SubmechIO { public RealSubmech() {} + @Override + public boolean condition() { + // TODO Auto-generated method stub + return true; + } + @Override public void close() throws Exception { // TODO Auto-generated method stub diff --git a/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/SimSubmech.java b/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/SimSubmech.java index 6dee117..63a6988 100644 --- a/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/SimSubmech.java +++ b/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/SimSubmech.java @@ -7,6 +7,11 @@ public class SimSubmech implements SubmechIO { public SimSubmech() {} + @Override + public boolean condition() { + return true; + } + @Override public void close() throws Exception { // TODO Auto-generated method stub diff --git a/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/SubmechIO.java b/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/SubmechIO.java index 03c19e2..7982aeb 100644 --- a/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/SubmechIO.java +++ b/src/main/java/org/sciborgs1155/robot/exampleMechanism/exampleSubmechanism/SubmechIO.java @@ -6,9 +6,10 @@ public interface SubmechIO extends Fallible, Sendable, AutoCloseable { + public boolean condition(); + @Override default void initSendable(SendableBuilder builder) { - // TODO Auto-generated method stub - + builder.addBooleanProperty("condition", this::condition, null); } } diff --git a/src/test/java/org/sciborgs1155/robot/subsystems/ExampleSubsystemTest.java b/src/test/java/org/sciborgs1155/robot/exampleMechanism/SubsystemTest.java similarity index 70% rename from src/test/java/org/sciborgs1155/robot/subsystems/ExampleSubsystemTest.java rename to src/test/java/org/sciborgs1155/robot/exampleMechanism/SubsystemTest.java index 5c50d08..963d453 100644 --- a/src/test/java/org/sciborgs1155/robot/subsystems/ExampleSubsystemTest.java +++ b/src/test/java/org/sciborgs1155/robot/exampleMechanism/SubsystemTest.java @@ -1,11 +1,10 @@ -package org.sciborgs1155.robot.subsystems; +package org.sciborgs1155.robot.exampleMechanism; import org.junit.jupiter.api.*; -import org.sciborgs1155.robot.exampleMechanism.Subsystem; import org.sciborgs1155.robot.testingUtil.BasicPackage; // TODO: add comments -public class ExampleSubsystemTest { +public class SubsystemTest { Subsystem exampleSubsystem; @@ -16,7 +15,9 @@ void setup() { } @Test - void test() {} + void conditionTest() { + assert exampleSubsystem.exampleCondition(); + } @AfterEach void reset() throws Exception {