Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions src/com/nutrons/framework/controllers/Tuneable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.nutrons.framework.controllers;

import edu.wpi.first.wpilibj.Preferences;

public class Tuneable {

private final String label;
private final double defaultValue;

public Tuneable(String label, double defaultValue) {
this.label = label;
this.defaultValue = defaultValue;
Preferences.getInstance().putDouble(label, defaultValue);
}

public double get() {
return Preferences.getInstance().getDouble(label, defaultValue);
}
}
27 changes: 27 additions & 0 deletions src/com/nutrons/framework/controllers/TuneablePID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.nutrons.framework.controllers;

public class TuneablePID {

private final String label;
private final Tuneable tuneableP;
private final Tuneable tuneableI;
private final Tuneable tuneableD;
private final Tuneable tuneableF;

public TuneablePID(String label, double defaultP, double defaultI, double defaultD, double defaultF) {
this.label = label;
this.tuneableP = new Tuneable(label + "_P", defaultP);
this.tuneableI = new Tuneable(label + "_I", defaultI);
this.tuneableD = new Tuneable(label + "_D", defaultD);
this.tuneableF = new Tuneable(label + "_F", defaultF);
}

public TuneablePID(String label) {
this(label, 0, 0, 0, 0);
}

public ControllerEvent getPID() {
return Events.pid(tuneableP.get(), tuneableI.get(), tuneableD.get(),
tuneableF.get());
}
}
8 changes: 3 additions & 5 deletions src/com/nutrons/framework/subsystems/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ public class Settings implements Subsystem {
/**
* Provides a Flowable for a specific property on the WpiSmartDashboard's settings table.
*/
public Flowable<Double> getProperty(String key) {
return FlowOperators.toFlow(() -> Preferences
.getInstance()
.getDouble(key, 0.0))
public Flowable<Double> getProperty(String key, double backup) {
return FlowOperators.toFlow(() ->
Preferences.getInstance().getDouble(key, backup))
.distinctUntilChanged();
//TODO: don't emit anything if it's 0.0, store last value and send that as backup
}

@Override
Expand Down