Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ri #96

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open

Ri #96

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
5548b2d
Added ID function to flow operatiors
Feb 17, 2017
b0eacd1
Merge branch 'master' of https://github.com/FRC125/FRamework
Feb 17, 2017
3a736ac
??
Feb 17, 2017
8693141
Fixed robot and made disposable flow operator
Feb 18, 2017
ed36a47
Merge branch 'master' of https://github.com/FRC125/FRamework
Feb 18, 2017
65b7061
Merge branch 'master' into auto-master
Feb 18, 2017
be674c7
initial commit
lydiaxing Feb 18, 2017
828bb9d
working????
camilo86 Feb 18, 2017
09a10d2
merged with week0
lydiaxing Feb 18, 2017
dcec602
Added Ashers fix to terminate commands
Feb 18, 2017
7b43c52
command update
Feb 18, 2017
cf0df59
Merge branch 'week0-cmd' into week0
Feb 18, 2017
56398bc
merged auto stuff
Feb 18, 2017
60f2ce4
updated
Feb 18, 2017
6eea67f
auto
camilo86 Feb 18, 2017
86a343d
Merge branch 'master' of https://github.com/FRC125/FRamework
Feb 19, 2017
06cbd85
added registerTele command
camilo86 Feb 19, 2017
c1dcb2b
had to make toFlowBackpressure backpressureless, and other minor tune…
camilo86 Feb 19, 2017
e13b529
Made RevServo controller events and functionality...
Feb 20, 2017
cd89660
Merge branch 'master' of https://github.com/FRC125/FRamework
Feb 20, 2017
9a7ad43
Merge branch 'master' into Servo-Controller
Feb 20, 2017
e23bc5e
edited speed of serial
lydiaxing Feb 20, 2017
62d8d02
some command changes... hope this still works
Feb 20, 2017
46f2410
more bug fixes and tests
Feb 20, 2017
68bf785
fixed streammanager bug
camilo86 Feb 20, 2017
87a6da0
fixed climbtake bug
lydiaxing Feb 20, 2017
f304ec3
step 1 completed
lydiaxing Feb 21, 2017
ec2f76c
update variable stays null
lydiaxing Feb 21, 2017
3755bcf
merged with master
lydiaxing Feb 21, 2017
5e5a319
removed print statements and accidentally refactoring of build files
lydiaxing Feb 21, 2017
f554608
Merge branch 'master' of https://github.com/FRC125/FRamework
Feb 21, 2017
4bbdc7a
Merge branch 'master' into Servo-Controller
Feb 21, 2017
9b8bd9c
added rotation2d for distance
lydiaxing Feb 21, 2017
f184476
Fixed Changes
Feb 22, 2017
6984e87
Fixed Errors :C
Feb 22, 2017
1837abb
Fixed dumb style errors
Feb 22, 2017
a1e9948
added toFlowFast
lydiaxing Feb 24, 2017
27c0241
updated fromSwitch to work, and added / modified tests
Feb 25, 2017
e44bf5e
fixed some style
Feb 25, 2017
b0655e6
moved libKudos254 to nu-17 Framework'
lydiaxing Feb 27, 2017
c53c33e
fromSwitch idempotency fixed, changed method signature to enable diff…
Feb 28, 2017
d52b720
merged auto selector
camilo86 Mar 2, 2017
f624c16
added radio box
camilo86 Mar 2, 2017
80e55a5
merged command switch fix
camilo86 Mar 2, 2017
052a83f
added defer command constructor
camilo86 Mar 2, 2017
4e24d48
added test to make sure Connectable Flowables work the way we expect
Mar 3, 2017
9b36010
merged servo stuff in
Mar 3, 2017
496e424
40kpa auto now working, just short
camilo86 Mar 3, 2017
de2b6d8
added pdLoop operator, fixed small possible bug in Parrallel + Serial…
Mar 4, 2017
9e7ff62
Merge branch 'florida-PD' into florida
Mar 4, 2017
a9a12d1
updated command subscription shenanigans
Mar 4, 2017
fb9db0b
actually really actually fixed memory
Mar 7, 2017
fb01fef
added virtual controller support to events
Mar 15, 2017
e72580a
switching to this method doesn't seem to cause a (or as bad of a) mem…
Mar 16, 2017
3558eeb
Auto triggers more frequently, and uses hot stream
Mar 22, 2017
eee6cdc
fixed imports
Mar 22, 2017
2b96166
Added current getter implementation
Mar 22, 2017
2f48746
Committed FRamework submodule
Mar 22, 2017
98b930e
Merge remote-tracking branch 'origin/current-implementation' into eff…
AndreasLc1103 Mar 23, 2017
63d85db
added ramping - untested
NUTRONSDS Mar 28, 2017
1a60b4e
implemented voltage method in virtual speed controller
Mar 29, 2017
484c312
The deadband reassign stuffs i forgot to push to a branch
AndreasLc1103 Apr 18, 2017
ad3c622
fixed deadbandassign
lydiaxing Apr 19, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .idea/FRamework.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions FRamework.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="TalonSRXLibJava2" level="project" />
<orderEntry type="library" name="lib7" level="project" />
<orderEntry type="library" name="lib6" level="project" />
</component>
</module>
12 changes: 6 additions & 6 deletions docs/google_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,32 @@
value="Type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MemberName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<property name="format" value="^[a-zPos][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ParameterName">
<property name="id" value="ParameterNameNonPublic"/>
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="format" value="^[a-zPos]([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="excludeScope" value="public"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ParameterName">
<property name="id" value="ParameterNamePublic"/>
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<property name="format" value="^[a-zPos][a-z0-9][a-zA-Z0-9]*$"/>
<property name="scope" value="public"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="CatchParameterName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<property name="format" value="^[a-zPos][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LocalVariableName">
<property name="tokens" value="VARIABLE_DEF"/>
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<property name="format" value="^[a-zPos][a-z0-9][a-zA-Z0-9]*$"/>
<property name="allowOneCharVarInForLoop" value="true"/>
<message key="name.invalidPattern"
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
Expand Down Expand Up @@ -221,7 +221,7 @@
<property name="allowThrowsTagsForSubclasses" value="true"/>
</module>
<module name="MethodName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
<property name="format" value="^[a-zPos][a-z0-9][a-zA-Z0-9_]*$"/>
<message key="name.invalidPattern"
value="Method name ''{0}'' must match pattern ''{1}''."/>
</module>
Expand Down
1 change: 1 addition & 0 deletions ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<dependency org="org.apache.ant" name="ant-junit" rev="1.9.7"/>
<dependency org="com.puppycrawl.tools" name="checkstyle" rev="7.4"/>
<dependency org="org.mockito" name="mockito-core" rev="2.7.0"/>
<dependency org="com.googlecode.json-simple" name="json-simple" rev="1.1.1"/>
</dependencies>
</ivy-module>
9 changes: 4 additions & 5 deletions src/com/nutrons/framework/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import static com.nutrons.framework.util.CompMode.AUTO;
import static com.nutrons.framework.util.CompMode.TELE;
import static com.nutrons.framework.util.CompMode.TEST;
import static io.reactivex.Flowable.combineLatest;

import com.nutrons.framework.commands.Command;
import com.nutrons.framework.util.CompMode;
import com.nutrons.framework.util.FlowOperators;
import edu.wpi.first.wpilibj.SampleRobot;
import io.reactivex.Flowable;
import io.reactivex.schedulers.Schedulers;
import java.util.concurrent.TimeUnit;

public abstract class Robot extends SampleRobot {

Expand Down Expand Up @@ -62,9 +61,9 @@ public final Flowable<Boolean> enabledStream() {
*/
public final Flowable<CompMode> competitionStream() {
return Flowable.merge(
FlowOperators.toFlow(this::isAutonomous).filter(x -> x).map((x) -> AUTO),
FlowOperators.toFlow(this::isAutonomous, 50, TimeUnit.MILLISECONDS).filter(x -> x).map((x) -> AUTO),
FlowOperators.toFlow(this::isOperatorControl).filter(x -> x).map((x) -> TELE),
FlowOperators.toFlow(this::isTest).filter(x -> x).map((x) -> TEST)).distinctUntilChanged();
FlowOperators.toFlow(this::isTest).filter(x -> x).map((x) -> TEST)).distinctUntilChanged().replay(1).autoConnect();
// filter(x -> x) will filter all false values from the stream.
}

Expand Down Expand Up @@ -140,4 +139,4 @@ public final boolean isOperatorControl() {
public final boolean isNewDataAvailable() {
return super.isNewDataAvailable();
}
}
}
17 changes: 10 additions & 7 deletions src/com/nutrons/framework/StreamManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.nutrons.framework;

import static com.nutrons.framework.util.CompMode.AUTO;
import static com.nutrons.framework.util.CompMode.TELE;
import static io.reactivex.Flowable.combineLatest;

import com.nutrons.framework.commands.Command;
import com.nutrons.framework.util.CompMode;
import io.reactivex.Flowable;
Expand All @@ -10,9 +14,7 @@
import java.util.List;
import java.util.function.Supplier;

import static com.nutrons.framework.util.CompMode.AUTO;
import static com.nutrons.framework.util.CompMode.TELE;
import static io.reactivex.Flowable.combineLatest;


/**
* This class sets up the I/O factories and initializes subsystems.
Expand All @@ -38,7 +40,7 @@ public StreamManager(Robot robot) {
* Subclasses should register subsystems in their constructor.
*
* @param enabled a Flowable of booleans, representing changes in the enabled state of the robot
* @param mode a Flowable of CompModes, representing changes in the competition game mode
* @param mode a Flowable of CompModes, representing changes in the competition game mode
*/
public StreamManager(Flowable<Boolean> enabled, Flowable<CompMode> mode) {
this.subsystems = new ArrayList<>();
Expand All @@ -50,7 +52,8 @@ public StreamManager(Flowable<Boolean> enabled, Flowable<CompMode> mode) {
* Called to by the bootstrapper to subscribe subsystem streams,
* and start the competition loop.
*/
public final void startCompetition(Supplier<Command> autoSupplier, Supplier<Command> teleopSupplier) {
public final void startCompetition(Supplier<Command> autoSupplier,
Supplier<Command> teleopSupplier) {
Observable.fromIterable(this.subsystems).blockingSubscribe(x -> {
System.out.println("registering " + x.getClass().getName());
x.registerSubscriptions();
Expand All @@ -59,7 +62,7 @@ public final void startCompetition(Supplier<Command> autoSupplier, Supplier<Comm
System.out.println("all subsystems registered");
Command auto = autoSupplier.get();
if (auto != null) {
combineLatest(this.enabled, this.mode, (x, y) -> x && y.compareTo(AUTO) == 0)
combineLatest(this.enabled, this.mode, (x, y) -> x && y.compareTo(AUTO) == 0).onBackpressureDrop()
.subscribeOn(Schedulers.io())
.filter(x -> x)
.map((a) -> {
Expand All @@ -70,7 +73,7 @@ public final void startCompetition(Supplier<Command> autoSupplier, Supplier<Comm
}
Command tele = teleopSupplier.get();
if (tele != null) {
combineLatest(this.enabled, this.mode, (x, y) -> x && y.compareTo(TELE) == 0)
combineLatest(this.enabled, this.mode, (x, y) -> x && y.compareTo(TELE) == 0).onBackpressureDrop()
.subscribeOn(Schedulers.io())
.filter(x -> x)
.map((a) -> {
Expand Down
93 changes: 65 additions & 28 deletions src/com/nutrons/framework/commands/Command.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.nutrons.framework.commands;

import static com.nutrons.framework.util.FlowOperators.toFlow;

import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.flowables.ConnectableFlowable;
import io.reactivex.schedulers.Schedulers;
import org.reactivestreams.Publisher;

import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import static com.nutrons.framework.util.FlowOperators.toFlow;
import org.reactivestreams.Publisher;

public class Command implements CommandWorkUnit {

Expand Down Expand Up @@ -71,31 +70,56 @@ public static Command parallel(Command... commands) {
return new Command(new ParallelCommand(commands));
}

public static Command fromSwitch(Publisher<? extends CommandWorkUnit> commandStream, boolean subcommandsSelfTerminate) {
return fromSwitch(commandStream, subcommandsSelfTerminate, true);
}

/**
* Creates a command that runs sequentially to another.
* Creates a command that runs commands in a stream.
*
* @param commandStream A flowable of commands
* @param commandStream A flowable of commands
* @param subcommandsSelfTerminate if true, commands in the stream will self terminate;
* @param subcommandsForceTerminate if true, commands in the stream will terminate the previous command.
* @retuns Second command after first is executed.
*/
public static Command fromSwitch(Publisher<? extends CommandWorkUnit> commandStream) {
return new Command(x -> Flowable.defer(() ->
Flowable.switchOnNext(Flowable.fromPublisher(commandStream).map(y -> y.execute(x))
.subscribeOn(Schedulers.io()))).scan((a, b) -> {
a.run();
return b;
}));
public static Command fromSwitch(Publisher<? extends CommandWorkUnit> commandStream,
boolean subcommandsSelfTerminate,
boolean subcommandsForceTerminate) {
return new Command(x -> Flowable.fromPublisher(commandStream)
.concatMap(y -> Flowable.<Terminator>just(FlattenedTerminator.from(y.execute(subcommandsSelfTerminate)))
.subscribeOn(Schedulers.trampoline()))
.scan((a, b) -> {
if (subcommandsForceTerminate) {
a.run();
}
return b;
}));
}

public static Command defer(Supplier<Command> supplier) {
return Command.just(x -> {
Command actual = supplier.get();
return actual.execute(x);
});
}

/**
* Adds a command that will terminate the current command.
*
* @param terminator Terminator command you wish to add.
* @return teriminatable command.
*/
public Command addFinalTerminator(Terminator terminator) {
return Command.just(x -> this.source.execute(x).flatMap(y -> Flowable.<Terminator>just(y, terminator)).subscribeOn(Schedulers.io()));
return Command.just(x -> this.source.execute(x)
.flatMap(y -> Flowable.<Terminator>just(y, terminator)));
}

/**
* Copies this command into one which will not execute until 'starter' emits an item.
*/
public Command startable(Publisher<?> starter) {
return new Command(new SerialCommand(
Command.just(x -> Flowable.defer(() -> Flowable.<Terminator>never().takeUntil(starter))),
Command.just(x -> Flowable.<Terminator>never().takeUntil(starter)),
this));
}

Expand All @@ -104,8 +128,7 @@ public Command startable(Publisher<?> starter) {
* will delay the execution of all actions until startCondition returns true.
*/
public Command when(Supplier<Boolean> startCondition) {
Flowable ignition = Flowable
.defer(() -> emptyPulse.map(x -> startCondition.get()).filter(x -> x).onBackpressureDrop());
Flowable ignition = emptyPulse.map(x -> startCondition.get()).filter(x -> x).onBackpressureDrop();
return this.startable(ignition);
}

Expand All @@ -120,15 +143,15 @@ public Command terminable(Publisher<?> terminator) {
/**
* Copies this command into one which will end when terminator emits an item.
*
* @param terminatesAtEnd if true, the command will terminate only when the end is reached,
* if false, the command may terminate before the end is reached.
* @param terminatesAtEnd if true, the command will terminate only when the end is reached, if
* false, the command may terminate before the end is reached.
*/
public Command endsWhen(Publisher<?> terminator, boolean terminatesAtEnd) {
return Command.just(x -> {
Flowable<Terminator> sourceTerminator = this.execute(terminatesAtEnd);
Flowable<? extends Terminator> sourceTerminator = this.execute(terminatesAtEnd);
Terminator multi = FlattenedTerminator.from(sourceTerminator);
return Flowable.defer(() -> Flowable.<Terminator>never().takeUntil(terminator)
.mergeWith(Flowable.just(multi::run)));
return Flowable.<Terminator>never().takeUntil(terminator)
.mergeWith(Flowable.just(multi));
});
}

Expand All @@ -137,7 +160,8 @@ public Command endsWhen(Publisher<?> terminator, boolean terminatesAtEnd) {
* will only complete once endCondition returns true.
*/
public Command until(Supplier<Boolean> endCondition) {
ConnectableFlowable<?> terminator = emptyPulse.map(x -> endCondition.get()).filter(x -> x).onBackpressureDrop().publish();
ConnectableFlowable<?> terminator = emptyPulse.map(x -> endCondition.get()).filter(x -> x)
.onBackpressureDrop().publish();
terminator.connect();
return this.terminable(terminator);
}
Expand All @@ -153,7 +177,7 @@ public Command then(Command next) {
* Copies this command into one which will delay execution for a period of time.
*/
public Command delayStart(long delay, TimeUnit unit) {
return this.startable(Flowable.timer(delay, unit));
return this.startable(Flowable.timer(delay, unit).onBackpressureBuffer());
}

/**
Expand All @@ -163,18 +187,31 @@ public Command delayFinish(long delay, TimeUnit unit) {
return this.terminable(Flowable.timer(delay, unit));
}

/**
* End and terminate this command only after the specified time has passed.
* Kills a command after a given time and unit
*
* @param delay a number in relation to a unit 1000 = 1 ms if unit is ms.
* @param unit unit you wish to count in.
* @return a command that will terminate after a given time.
*/
public Command killAfter(long delay, TimeUnit unit) {
return Command.just(x -> {
Flowable<Terminator> terms = this.terminable(Flowable.timer(delay, unit)).execute(x);
Flowable<? extends Terminator> terms = this.terminable(Flowable.timer(delay, unit))
.execute(x);
return terms;
});
}

@Override
public Flowable<Terminator> execute(boolean selfTerminating) {
Flowable<Terminator> terms = source.execute(selfTerminating).subscribeOn(Schedulers.io());
public Flowable<? extends Terminator> execute(boolean selfTerminating) {
Flowable<? extends Terminator> terms = source.execute(selfTerminating)
.subscribeOn(Schedulers.trampoline());
if (selfTerminating) {
terms.toList().subscribe(x -> Observable.fromIterable(x).blockingSubscribe(Terminator::run));
terms.toList().map(Observable::fromIterable).subscribeOn(Schedulers.trampoline())
.subscribe(x -> x.subscribe(Terminator::run));
} else {
terms.subscribe();
}
return terms;
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/nutrons/framework/commands/CommandWorkUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import io.reactivex.Flowable;

public interface CommandWorkUnit {
Flowable<Terminator> execute(boolean selfTerminating);
Flowable<? extends Terminator> execute(boolean selfTerminating);
}
10 changes: 5 additions & 5 deletions src/com/nutrons/framework/commands/FlattenedTerminator.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class FlattenedTerminator implements Terminator {

private final AtomicBoolean lock;
private final ArrayList<Terminator> terminators;
private final Flowable<Terminator> terminatorStream;
private final Flowable<? extends Terminator> terminatorStream;

private FlattenedTerminator(Flowable<Terminator> terminators) {
private FlattenedTerminator(Flowable<? extends Terminator> terminators) {
this.lock = new AtomicBoolean(false);
this.terminators = new ArrayList<>();
this.terminatorStream = terminators;
terminators.subscribeOn(Schedulers.io()).subscribe(x -> {
terminators.subscribe(x -> {
if (!lock.get()) {
synchronized (lock) {
if (!lock.get()) {
Expand All @@ -29,13 +29,13 @@ private FlattenedTerminator(Flowable<Terminator> terminators) {
});
}

static FlattenedTerminator from(Flowable<Terminator> terminators) {
static FlattenedTerminator from(Flowable<? extends Terminator> terminators) {
return new FlattenedTerminator(terminators);
}

public Flowable<? extends Terminator> toSingle() {
return Flowable.just(this).mergeWith(terminatorStream.ignoreElements().toFlowable())
.subscribeOn(Schedulers.io());
.subscribeOn(Schedulers.trampoline());
}

@Override
Expand Down
Loading