Skip to content

Commit

Permalink
rough draft? def needs more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sigalrmp committed Aug 24, 2023
1 parent a69609d commit a3914da
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 22 deletions.
8 changes: 7 additions & 1 deletion src/main/java/org/sciborgs1155/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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
Expand All @@ -69,12 +68,12 @@ public void simulationPeriodic() {
@Override
public List<HardwareFault> 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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<HardwareFault> getFaults() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -16,7 +15,9 @@ void setup() {
}

@Test
void test() {}
void conditionTest() {
assert exampleSubsystem.exampleCondition();
}

@AfterEach
void reset() throws Exception {
Expand Down

0 comments on commit a3914da

Please sign in to comment.