Skip to content

Commit

Permalink
Release 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SMEZ1234 committed Feb 7, 2020
1 parent d2d3bb9 commit ce61213
Show file tree
Hide file tree
Showing 47 changed files with 1,048 additions and 422 deletions.
51 changes: 51 additions & 0 deletions src/main/java/arachne/lib/AutoManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package arachne.lib;

import arachne.lib.scheduler.Schedulable;
import arachne.lib.sequences.ActionConductor;
import arachne.lib.sequences.Actionable;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;

public class AutoManager<AutoT extends Enum<?> & Actionable> implements Schedulable
{
protected static final String DASHBOARD_TAB = "Autonomous";
protected static final String SELECTION_KEY = "Auto selection";

protected final ActionConductor conductor;
protected final SendableChooser<AutoT> autoChooser;

public AutoManager(AutoT defaultAuto, AutoT[] autos) {
this.conductor = new ActionConductor();

this.autoChooser = new SendableChooser<AutoT>();
this.autoChooser.setDefaultOption(defaultAuto.toString(), defaultAuto);

for(AutoT auto : autos) {
if(auto != defaultAuto) autoChooser.addOption(auto.toString(), auto);
}

Shuffleboard.getTab(DASHBOARD_TAB).add(SELECTION_KEY, autoChooser);
}

public void startAuto() {
startAuto(autoChooser.getSelected());
}

public void startAuto(AutoT auto) {
stopAuto();
conductor.add(auto);
}

public void stopAuto() {
conductor.interrupt();
}

public boolean isRunning() {
return conductor.hasActions();
}

@Override
public void run() {
conductor.run();
}
}
36 changes: 36 additions & 0 deletions src/main/java/arachne/lib/function/BooleanPredicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,40 @@ default BooleanPredicate or(BooleanPredicate other) {
Objects.requireNonNull(other);
return (value) -> test(value) || other.test(value);
}

/**
* Returns a composed operator that first applies the {@code before}
* operator to its input, and then applies this operator to the result.
* If evaluation of either operator throws an exception, it is relayed to
* the caller of the composed operator.
*
* @param before the operator to apply before this operator is applied
* @return a composed operator that first applies the {@code before}
* operator and then applies this operator
* @throws NullPointerException if before is null
*
* @see #andThen(BooleanPredicate)
*/
default BooleanPredicate compose(BooleanPredicate before) {
Objects.requireNonNull(before);
return (boolean v) -> test(before.test(v));
}

/**
* Returns a composed operator that first applies this operator to
* its input, and then applies the {@code after} operator to the result.
* If evaluation of either operator throws an exception, it is relayed to
* the caller of the composed operator.
*
* @param after the operator to apply after this operator is applied
* @return a composed operator that first applies this operator and then
* applies the {@code after} operator
* @throws NullPointerException if after is null
*
* @see #compose(DoubleUnaryOperator)
*/
default BooleanPredicate andThen(BooleanPredicate after) {
Objects.requireNonNull(after);
return (boolean t) -> after.test(test(t));
}
}
14 changes: 6 additions & 8 deletions src/main/java/arachne/lib/hardware/DifferentialDrivetrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import arachne.lib.io.SettableDouble;
import arachne.lib.listeners.DoubleProperty;
import arachne.lib.listeners.SimpleDoubleProperty;
import arachne.lib.pipeline.DoublePipe;
import arachne.lib.pipeline.DoubleSource;
import arachne.lib.pipeline.SimpleDoublePipe;
import arachne.lib.systems.Subsystem;

public abstract class DifferentialDrivetrain extends Subsystem
Expand All @@ -25,10 +23,10 @@ public DifferentialDrivetrain(DoubleUnaryOperator outputModifier) {
tankSource = new TankSource();
arcadeSource = new ArcadeSource();

leftOutput = new SimpleDoublePipe();
leftOutput = new DoublePipe();
leftOutput.setModifier(outputModifier);

rightOutput = new SimpleDoublePipe();
rightOutput = new DoublePipe();
rightOutput.setModifier(outputModifier);
}

Expand All @@ -44,8 +42,8 @@ public class TankSource {
protected final DoublePipe leftInput, rightInput;

protected TankSource() {
leftInput = new SimpleDoublePipe();
rightInput = new SimpleDoublePipe();
leftInput = new DoublePipe();
rightInput = new DoublePipe();
}

public SettableDouble getLeftInput() {
Expand All @@ -61,8 +59,8 @@ public class ArcadeSource {
protected final DoubleProperty speedInput, rotationInput;

protected ArcadeSource() {
speedInput = new SimpleDoubleProperty();
rotationInput = new SimpleDoubleProperty();
speedInput = new DoubleProperty();
rotationInput = new DoubleProperty();
}

public SettableDouble getSpeedInput() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import arachne.lib.io.SettableBoolean;
import arachne.lib.listeners.BooleanProperty;
import arachne.lib.listeners.DoubleChangeHandler;
import arachne.lib.listeners.SimpleBooleanProperty;
import arachne.lib.logic.ArachneMath;

public class SimpleDifferentialDrivetrain extends DifferentialDrivetrain
Expand All @@ -17,7 +16,7 @@ public SimpleDifferentialDrivetrain() {
}

public SimpleDifferentialDrivetrain(boolean isInitiallyTankDrive, boolean squareInputs) {
this.isTankState = new SimpleBooleanProperty(isInitiallyTankDrive);
this.isTankState = new BooleanProperty(isInitiallyTankDrive);
}

@Override
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/arachne/lib/io/Gettable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

import arachne.lib.logging.ArachneLogger;

@FunctionalInterface
public interface Gettable<T> extends Supplier<T>
{
Expand All @@ -15,7 +17,28 @@ default GettableBoolean is(Predicate<T> predicate) {
return () -> predicate.test(get());
}

default Gettable<T> withModifier(UnaryOperator<T> modifier) {
default Gettable<T> change(UnaryOperator<T> modifier) {
return () -> modifier.apply(get());
}

public static <T> Gettable<T> create(Gettable<T> lambda) {
return lambda;
}

public static final class Wrapper<T> implements Gettable<T> {
protected Gettable<T> gettable;

public Wrapper<T> wrap(Gettable<T> gettable) {
this.gettable = gettable;
return this;
}

@Override
public T get() {
if(gettable != null) return gettable.get();

ArachneLogger.getInstance().error("Tried to get Gettable wrapper with no contained gettable, returning null");
return null;
}
}
}
22 changes: 22 additions & 0 deletions src/main/java/arachne/lib/io/GettableBoolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.function.BooleanSupplier;

import arachne.lib.function.BooleanPredicate;
import arachne.lib.logging.ArachneLogger;
import arachne.lib.sequences.Action;
import arachne.lib.sequences.Actionable;
import arachne.lib.sequences.HostAction;
Expand Down Expand Up @@ -48,4 +49,25 @@ default GettableBoolean or(GettableBoolean other) {
default GettableBoolean xor(GettableBoolean other) {
return () -> this.get() != other.get();
}

public static GettableBoolean create(GettableBoolean lambda) {
return lambda;
}

public static final class Wrapper implements GettableBoolean {
protected GettableBoolean gettable;

public Wrapper wrap(GettableBoolean gettable) {
this.gettable = gettable;
return this;
}

@Override
public boolean get() {
if(gettable != null) return gettable.get();

ArachneLogger.getInstance().error("Tried to get GettableBoolean wrapper with no contained gettable, returning false");
return false;
}
}
}
41 changes: 20 additions & 21 deletions src/main/java/arachne/lib/io/GettableDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import java.util.function.DoubleSupplier;
import java.util.function.DoubleUnaryOperator;

import edu.wpi.first.wpilibj.PIDSource;
import edu.wpi.first.wpilibj.PIDSourceType;
import arachne.lib.logging.ArachneLogger;

@FunctionalInterface
public interface GettableDouble extends DoubleSupplier
Expand All @@ -25,28 +24,28 @@ default GettableBoolean is(DoublePredicate predicate) {
return () -> predicate.test(get());
}

default GettableDouble withModifier(DoubleUnaryOperator modifier) {
default GettableDouble change(DoubleUnaryOperator modifier) {
return () -> modifier.applyAsDouble(get());
}

default PIDSource asPIDSource(PIDSourceType pidSource) {
return new PIDSource() {
private PIDSourceType type = pidSource;

@Override
public double pidGet() {
return GettableDouble.this.get();
}

@Override
public PIDSourceType getPIDSourceType() {
return type;
}
public static GettableDouble create(GettableDouble lambda) {
return lambda;
}

public static final class Wrapper implements GettableDouble {
protected GettableDouble gettable;

public Wrapper wrap(GettableDouble gettable) {
this.gettable = gettable;
return this;
}

@Override
public double get() {
if(gettable != null) return gettable.get();

@Override
public void setPIDSourceType(PIDSourceType pidSource) {
this.type = pidSource;
}
};
ArachneLogger.getInstance().error("Tried to get GettableDouble wrapper with no contained gettable, returning 0");
return 0;
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/arachne/lib/io/Settable.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
@FunctionalInterface
public interface Settable<T> extends Consumer<T>
{
// Empty, exists for future features
public static <T> Settable<T> create(Settable<T> lambda) {
return lambda;
}
}
4 changes: 3 additions & 1 deletion src/main/java/arachne/lib/io/SettableBoolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
@FunctionalInterface
public interface SettableBoolean extends BooleanConsumer
{
// Empty, exists for future features
public static SettableBoolean create(SettableBoolean lambda) {
return lambda;
}
}
9 changes: 3 additions & 6 deletions src/main/java/arachne/lib/io/SettableDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import java.util.function.DoubleConsumer;

import edu.wpi.first.wpilibj.PIDOutput;

@FunctionalInterface
public interface SettableDouble extends DoubleConsumer, PIDOutput
public interface SettableDouble extends DoubleConsumer
{
@Override
default void pidWrite(double output) {
accept(output);
public static SettableDouble create(SettableDouble lambda) {
return lambda;
}
}
37 changes: 37 additions & 0 deletions src/main/java/arachne/lib/io/sensors/BooleanSensor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package arachne.lib.io.sensors;

import arachne.lib.io.GettableBoolean;
import arachne.lib.io.SettableBoolean;
import arachne.lib.logging.ArachneLogger;

public interface BooleanSensor extends GettableBoolean, SettableBoolean, Resettable
{
public static final class Wrapper implements BooleanSensor {
protected BooleanSensor sensor;

public Wrapper wrap(BooleanSensor sensor) {
this.sensor = sensor;
return this;
}

@Override
public boolean get() {
if(sensor != null) return sensor.get();

ArachneLogger.getInstance().error("Tried to get BooleanSensor wrapper with no contained sensor, returning 0");
return false;
}

@Override
public void accept(boolean value) {
if(sensor != null) sensor.accept(value);
else ArachneLogger.getInstance().error("Tried to set BooleanSensor wrapper with no contained sensor");
}

@Override
public void reset() {
if(sensor != null) sensor.reset();
else ArachneLogger.getInstance().error("Tried to reset BooleanSensor wrapper with no contained sensor");
}
}
}
37 changes: 37 additions & 0 deletions src/main/java/arachne/lib/io/sensors/DoubleSensor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package arachne.lib.io.sensors;

import arachne.lib.io.GettableDouble;
import arachne.lib.io.SettableDouble;
import arachne.lib.logging.ArachneLogger;

public interface DoubleSensor extends GettableDouble, SettableDouble, Resettable
{
public static final class Wrapper implements DoubleSensor {
protected DoubleSensor sensor;

public Wrapper wrap(DoubleSensor sensor) {
this.sensor = sensor;
return this;
}

@Override
public double get() {
if(sensor != null) return sensor.get();

ArachneLogger.getInstance().error("Tried to get DoubleSensor wrapper with no contained sensor, returning 0");
return 0;
}

@Override
public void accept(double value) {
if(sensor != null) sensor.accept(value);
else ArachneLogger.getInstance().error("Tried to set DoubleSensor wrapper with no contained sensor");
}

@Override
public void reset() {
if(sensor != null) sensor.reset();
else ArachneLogger.getInstance().error("Tried to reset DoubleSensor wrapper with no contained sensor");
}
}
}
Loading

0 comments on commit ce61213

Please sign in to comment.