diff --git a/src/org/parts3492/partslib/PARTsCandle.java b/src/org/parts3492/partslib/PARTsCandle.java index 5e3cb48..d799d81 100644 --- a/src/org/parts3492/partslib/PARTsCandle.java +++ b/src/org/parts3492/partslib/PARTsCandle.java @@ -171,7 +171,8 @@ public PARTsCandle(String className, int canID, int ledLength, String canBusName /*---------------------------------- Custom Private Functions ---------------------------------*/ protected void setColor(Color color) { setControl(new EmptyAnimation(0)); - setControl(new SolidColor(0, LED_LENGTH).withColor(new RGBWColor(color.r, color.g, color.b))); + setControl( + new SolidColor(0, LED_LENGTH).withColor(new RGBWColor(color.r, color.g, color.b))); } protected void setNoColor() { @@ -412,24 +413,17 @@ public void periodic() { @Override public void outputTelemetry() { - super.partsNT.putString("Animation", candle.getAppliedControl().getName()); } @Override public void stop() { - // TODO Auto-generated method stub - // throw new UnsupportedOperationException("Unimplemented method 'stop'"); } @Override public void reset() { - // TODO Auto-generated method stub - // throw new UnsupportedOperationException("Unimplemented method 'reset'"); } @Override public void log() { - // TODO Auto-generated method stub - super.partsLogger.logString("Animation", candle.getAppliedControl().getName()); } } diff --git a/src/org/parts3492/partslib/PARTsLogger.java b/src/org/parts3492/partslib/PARTsLogger.java index b3bed3f..32668b7 100644 --- a/src/org/parts3492/partslib/PARTsLogger.java +++ b/src/org/parts3492/partslib/PARTsLogger.java @@ -23,7 +23,8 @@ public class PARTsLogger { /** * Create a new PARTsLogger. * - *
By default, logging is disabled. + *
+ * By default, logging is disabled. */ public PARTsLogger() { instantiate(false); @@ -43,7 +44,8 @@ public PARTsLogger(boolean allowLogging) { /** * Create a new PARTsLogger with the following name. * - *
By default, logging is disabled. + *
+ * By default, logging is disabled. */ public PARTsLogger(String name) { instantiate(false); @@ -65,9 +67,11 @@ public PARTsLogger(String name, boolean allowLogging) { /** * Create a new PARTsLogger with the object's class name. * - *
E.g. PARTsLogger.
+ *
+ * E.g. PARTsLogger.
*
- *
By default, logging is disabled. + *
+ * By default, logging is disabled. */ public PARTsLogger(Object o) { name = o.getClass().getSimpleName(); @@ -77,7 +81,8 @@ public PARTsLogger(Object o) { /** * Create a new PARTsLogger with the object's class name. * - *
E.g. PARTsLogger.
+ *
+ * E.g. PARTsLogger.
*
*
*
@@ -90,11 +95,12 @@ public PARTsLogger(Object o, boolean allowLogging) {
private void instantiate(boolean allowLogging) {
loggingEnabled = allowLogging;
- if (loggingEnabled) {
- // Starts recording to data log
- DataLogManager.start();
+ if (loggingEnabled) {
- if (log == null) log = DataLogManager.getLog();
+ if (log == null){
+ // Starts recording to data log
+ DataLogManager.start();
+ log = DataLogManager.getLog();}
}
}
@@ -108,67 +114,73 @@ public void disableLogging() {
instantiate(false);
}
- public boolean logBoolean(String key, boolean b) {
- if (loggingEnabled) {
+ public boolean logBoolean(String key, boolean b, boolean logEntry) {
+ if (loggingEnabled && logEntry) {
new BooleanLogEntry(log, name.length() > 0 ? String.format("%s/%s", name, key) : key)
.append(b);
return true;
- } else return false;
+ } else
+ return false;
}
- public boolean logDouble(String key, double d) {
- if (loggingEnabled) {
+ public boolean logDouble(String key, double d, boolean logEntry) {
+ if (loggingEnabled && logEntry) {
new DoubleLogEntry(log, name.length() > 0 ? String.format("%s/%s", name, key) : key)
.append(d);
return true;
- } else return false;
+ } else
+ return false;
}
- public boolean logString(String key, String s) {
- if (loggingEnabled) {
+ public boolean logString(String key, String s, boolean logEntry) {
+ if (loggingEnabled && logEntry) {
new StringLogEntry(log, name.length() > 0 ? String.format("%s/%s", name, key) : key)
.append(s);
return true;
- } else return false;
+ } else
+ return false;
}
- public void logCommandScheduler() {
-
- // Set the scheduler to log events for command initialize, interrupt, finish
- CommandScheduler.getInstance()
- .onCommandInitialize(
- command -> {
- logString(command.getName(), "Command initialized");
- });
- CommandScheduler.getInstance()
- .onCommandInterrupt(
- command -> {
- logString(command.getName(), "Command interrupted");
- });
- CommandScheduler.getInstance()
- .onCommandFinish(
- command -> {
- logString(command.getName(), "Command finished");
- });
+ public void logCommandScheduler(boolean logEntry) {
+ if (logEntry) {
+ // Set the scheduler to log events for command initialize, interrupt, finish
+ CommandScheduler.getInstance()
+ .onCommandInitialize(
+ command -> {
+ logString(command.getName(), "Command initialized", true);
+ });
+ CommandScheduler.getInstance()
+ .onCommandInterrupt(
+ command -> {
+ logString(command.getName(), "Command interrupted", true);
+ });
+ CommandScheduler.getInstance()
+ .onCommandFinish(
+ command -> {
+ logString(command.getName(), "Command finished", true);
+ });
+ }
}
- public void logPathPlanner() {
- // Logging callback for target robot pose
- PathPlannerLogging.setLogTargetPoseCallback(
- (pose) -> {
- // Do whatever you want with the pose here
- FieldBase.FIELD2D
- .getObject("target pose")
- .setPose(FieldBase.conditionallyTransformToOppositeAlliance(pose));
- });
-
- // Logging callback for the active path, this is sent as a list of poses
- PathPlannerLogging.setLogActivePathCallback(
- (poses) -> {
- // Do whatever you want with the poses here
- FieldBase.FIELD2D
- .getObject("path")
- .setPoses(FieldBase.conditionallyTransformToOppositeAlliance(poses));
- });
+ public void logPathPlanner(boolean logEntry) {
+ if (logEntry) {
+ // Logging callback for target robot pose
+ PathPlannerLogging.setLogTargetPoseCallback(
+ (pose) -> {
+ // Do whatever you want with the pose here
+ FieldBase.FIELD2D
+ .getObject("target pose")
+ .setPose(FieldBase.conditionallyTransformToOppositeAlliance(pose));
+ });
+
+ // Logging callback for the active path, this is sent as a list of poses
+ PathPlannerLogging.setLogActivePathCallback(
+ (poses) -> {
+ // Do whatever you want with the poses here
+ FieldBase.FIELD2D
+ .getObject("path")
+ .setPoses(FieldBase.conditionallyTransformToOppositeAlliance(poses));
+ });
+ }
}
}
diff --git a/src/org/parts3492/partslib/network/PARTsDashboard.java b/src/org/parts3492/partslib/network/PARTsDashboard.java
index a1d246f..3b46785 100644
--- a/src/org/parts3492/partslib/network/PARTsDashboard.java
+++ b/src/org/parts3492/partslib/network/PARTsDashboard.java
@@ -6,13 +6,13 @@
import org.parts3492.partslib.command.IPARTsSubsystem;
-import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import java.util.ArrayList;
public class PARTsDashboard {
private static DashboardTab state = DashboardTab.AUTONOMOUS;
+ private static final PARTsNT partsNT = new PARTsNT();
public enum DashboardTab {
AUTONOMOUS("Autonomous"),
@@ -26,14 +26,17 @@ public enum DashboardTab {
}
}
- public PARTsDashboard() {}
+ public PARTsDashboard() {
+ }
- public static void setSubsystems(ArrayList {@code PARTsNT partsNT = new PARTsNT(this)}
+ *
+ * {@code PARTsNT partsNT = new PARTsNT(this)}
*
- * This class is meant to be used as an instance for each class.
+ *
+ * This class is meant to be used as an instance for each class.
*/
public class PARTsNT {
public String name = "Generic";
@@ -36,13 +38,15 @@ public class PARTsNT {
/**
* Generic topic entry that is not designed to be used by itself.
*
- * Use the other chilld classes instead.
+ *
+ * Use the other chilld classes instead.
*/
private class EasyGenericEntry {
/** The NetworkTables topic name. */
public String topicName;
- public EasyGenericEntry() {}
+ public EasyGenericEntry() {
+ }
}
class EasyBooleanEntry extends EasyGenericEntry {
@@ -55,7 +59,9 @@ class EasyBooleanEntry extends EasyGenericEntry {
/**
* The value last gotten from set or get.
*
- * Its purpose here is to provide a way to get the previous cached result, saving some
+ *
+ * Its purpose here is to provide a way to get the previous cached result,
+ * saving some
* time.
*/
public boolean cachedValue;
@@ -85,7 +91,9 @@ class EasyIntegerEntry extends EasyGenericEntry {
/**
* The value last gotten from set or get.
*
- * Its purpose here is to provide a way to get the previous cached result, saving some
+ *
+ * Its purpose here is to provide a way to get the previous cached result,
+ * saving some
* time.
*/
public int cachedValue;
@@ -115,7 +123,9 @@ class EasyDoubleEntry extends EasyGenericEntry {
/**
* The value last gotten from set or get.
*
- * Its purpose here is to provide a way to get the previous cached result, saving some
+ *
+ * Its purpose here is to provide a way to get the previous cached result,
+ * saving some
* time.
*/
public double cachedValue;
@@ -145,7 +155,9 @@ class EasyStringEntry extends EasyGenericEntry {
/**
* The value last gotten from set or get.
*
- * Its purpose here is to provide a way to get the previous cached result, saving some
+ *
+ * Its purpose here is to provide a way to get the previous cached result,
+ * saving some
* time.
*/
public String cachedValue;
@@ -175,7 +187,8 @@ public EasyStringEntry(String name, String value) {
/**
* Sets up the master list and the entry lists.
*
- * Internal function.
+ *
+ * Internal function.
*/
private void setupEntryLists() {
topicsList = new ArrayList<>();
@@ -194,9 +207,11 @@ private void setupEntryLists() {
/**
* Creates a new PARTsNT instance.
*
- * Creates/uses the subtable "Generic" instead of the class subtable.
+ *
+ * Creates/uses the subtable "Generic" instead of the class subtable.
*
- * The object variation should be used instead.
+ *
+ * The object variation should be used instead.
*/
public PARTsNT() {
table = nt_Instance.getTable("PARTs").getSubTable("Generic");
@@ -206,7 +221,8 @@ public PARTsNT() {
/**
* Creates a new PARTsNT instance.
*
- * Creates/uses the class subtable.
+ *
+ * Creates/uses the class subtable.
*
* @param o The class object. (E.g. passing in 'this'.)
*/
@@ -219,9 +235,11 @@ public PARTsNT(Object o) {
/**
* Creates a new PARTsNT instance.
*
- * Creates/uses the subtable of the class via its name.
+ *
+ * Creates/uses the subtable of the class via its name.
*
- * If the name is empty, then the "Generic" table will be used instead.
+ *
+ * If the name is empty, then the "Generic" table will be used instead.
*
* @param className The name of the class.
*/
@@ -255,10 +273,12 @@ private void addEntryToList(EasyGenericEntry entry) {
* @param name The name of the entry.
* @return The entry if it exists, otherwise null.
*/
- private EasyGenericEntry getEntry(String name) {
- for (EasyGenericEntry entry : topicsList) {
- if (entry.topicName.equals(name)) return entry;
- }
+ private EasyGenericEntry getEntry(String name, boolean pull) {
+ if (pull)
+ for (EasyGenericEntry entry : topicsList) {
+ if (entry.topicName.equals(name))
+ return entry;
+ }
return null;
}
@@ -270,10 +290,12 @@ private EasyGenericEntry getEntry(String name) {
* @param name The name of the entry.
* @return The entry if it exists, otherwise null.
*/
- private EasyBooleanEntry getBooleanEntry(String name) {
- for (EasyBooleanEntry entry : booleanEntries) {
- if (entry.topicName.equals(name)) return entry;
- }
+ private EasyBooleanEntry getBooleanEntry(String name, boolean pull) {
+ if (pull)
+ for (EasyBooleanEntry entry : booleanEntries) {
+ if (entry.topicName.equals(name))
+ return entry;
+ }
return null;
}
@@ -283,10 +305,12 @@ private EasyBooleanEntry getBooleanEntry(String name) {
* @param name The name of the entry.
* @return The entry if it exists, otherwise null.
*/
- private EasyIntegerEntry getIntegerEntry(String name) {
- for (EasyIntegerEntry entry : integerEntries) {
- if (entry.topicName.equals(name)) return entry;
- }
+ private EasyIntegerEntry getIntegerEntry(String name, boolean pull) {
+ if (pull)
+ for (EasyIntegerEntry entry : integerEntries) {
+ if (entry.topicName.equals(name))
+ return entry;
+ }
return null;
}
@@ -296,10 +320,12 @@ private EasyIntegerEntry getIntegerEntry(String name) {
* @param name The name of the entry.
* @return The entry if it exists, otherwise null.
*/
- private EasyDoubleEntry getDoubleEntry(String name) {
- for (EasyDoubleEntry entry : doubleEntries) {
- if (entry.topicName.equals(name)) return entry;
- }
+ private EasyDoubleEntry getDoubleEntry(String name, boolean pull) {
+ if (pull)
+ for (EasyDoubleEntry entry : doubleEntries) {
+ if (entry.topicName.equals(name))
+ return entry;
+ }
return null;
}
@@ -309,10 +335,12 @@ private EasyDoubleEntry getDoubleEntry(String name) {
* @param name The name of the entry.
* @return The entry if it exists, otherwise null.
*/
- private EasyStringEntry getStringEntry(String name) {
- for (EasyStringEntry entry : stringEntries) {
- if (entry.topicName.equals(name)) return entry;
- }
+ private EasyStringEntry getStringEntry(String name, boolean pull) {
+ if (pull)
+ for (EasyStringEntry entry : stringEntries) {
+ if (entry.topicName.equals(name))
+ return entry;
+ }
return null;
}
@@ -324,24 +352,25 @@ private EasyStringEntry getStringEntry(String name) {
* @param name The topic name.
* @return Returns the boolean value if entry is found, otherwise returns false.
*/
- public boolean getBoolean(String name) {
- EasyBooleanEntry entry = getBooleanEntry(name);
+ public boolean getBoolean(String name, boolean pull) {
+ EasyBooleanEntry entry = getBooleanEntry(name, pull);
return (entry == null) ? false : (entry.cachedValue = entry.entry.get());
}
/**
* Sets the boolean value for the requested entry.
*
- * @param name The name of the entry.
+ * @param name The name of the entry.
* @param value The new value to publish to the entry.
*/
- public void putBoolean(String name, boolean value) {
- EasyBooleanEntry entry = getBooleanEntry(name);
- if (entry == null) {
- booleanEntries.add(new EasyBooleanEntry(name, value));
- } else if (entry.cachedValue != value) {
- entry.entry.set((entry.cachedValue = value));
- }
+ public void putBoolean(String name, boolean value, boolean post) {
+ EasyBooleanEntry entry = getBooleanEntry(name, post);
+ if (post)
+ if (entry == null) {
+ booleanEntries.add(new EasyBooleanEntry(name, value));
+ } else if (entry.cachedValue != value) {
+ entry.entry.set((entry.cachedValue = value));
+ }
}
// * -------- INTEGER FUNCTIONS -------- *//
@@ -352,24 +381,25 @@ public void putBoolean(String name, boolean value) {
* @param name The name of the entry.
* @return Returns the value if entry is found, otherwise returns zero.
*/
- public int getInteger(String name) {
- EasyIntegerEntry entry = getIntegerEntry(name);
+ public int getInteger(String name, boolean pull) {
+ EasyIntegerEntry entry = getIntegerEntry(name, pull);
return (entry == null) ? 0 : (entry.cachedValue = Math.toIntExact(entry.entry.get()));
}
/**
* Sets the integer value for the requested entry.
*
- * @param name The name of the entry.
+ * @param name The name of the entry.
* @param value The new value to publish to the entry.
*/
- public void putInteger(String name, int value) {
- EasyIntegerEntry entry = getIntegerEntry(name);
- if (entry == null) {
- integerEntries.add(new EasyIntegerEntry(name, value));
- } else if (entry.cachedValue != value) {
- entry.entry.set((entry.cachedValue = value));
- }
+ public void putInteger(String name, int value, boolean post) {
+ EasyIntegerEntry entry = getIntegerEntry(name, post);
+ if (post)
+ if (entry == null) {
+ integerEntries.add(new EasyIntegerEntry(name, value));
+ } else if (entry.cachedValue != value) {
+ entry.entry.set((entry.cachedValue = value));
+ }
}
// * -------- DOUBLE FUNCTIONS -------- *//
@@ -380,44 +410,45 @@ public void putInteger(String name, int value) {
* @param name The name of the entry.
* @return Returns the value if entry is found, otherwise returns zero.
*/
- public double getDouble(String name) {
- EasyDoubleEntry entry = getDoubleEntry(name);
+ public double getDouble(String name, boolean pull) {
+ EasyDoubleEntry entry = getDoubleEntry(name, pull);
return (entry == null) ? 0 : (entry.cachedValue = entry.entry.get());
}
/**
* Sets the double value for the requested entry.
*
- * @param name The name of the entry.
+ * @param name The name of the entry.
* @param value The new value to publish to the entry.
*/
- public void putDouble(String name, double value) {
- EasyDoubleEntry entry = getDoubleEntry(name);
- if (entry == null) {
- doubleEntries.add(new EasyDoubleEntry(name, value));
- } else if (entry.cachedValue != value) {
- entry.entry.set((entry.cachedValue = value));
- }
+ public void putDouble(String name, double value, boolean post) {
+ EasyDoubleEntry entry = getDoubleEntry(name, post);
+ if (post)
+ if (entry == null) {
+ doubleEntries.add(new EasyDoubleEntry(name, value));
+ } else if (entry.cachedValue != value) {
+ entry.entry.set((entry.cachedValue = value));
+ }
}
/**
* Sets the double value for the requested entry.
*
- * @param name The name of the entry.
+ * @param name The name of the entry.
* @param value The new value to publish to the entry.
*/
- public void putNumber(String name, double value) {
- putDouble(name, value);
+ public void putNumber(String name, double value, boolean post) {
+ putDouble(name, value, post);
}
/**
* Sets the integer value for the requested entry.
*
- * @param name The name of the entry.
+ * @param name The name of the entry.
* @param value The new value to publish to the entry.
*/
- public void putNumber(String name, int value) {
- putInteger(name, value);
+ public void putNumber(String name, int value, boolean post) {
+ putInteger(name, value, post);
}
// * -------- STRING FUNCTIONS -------- *//
@@ -426,26 +457,28 @@ public void putNumber(String name, int value) {
* Gets the string value from the requested entry.
*
* @param name The name of the entry.
- * @return Returns the value if entry is found, otherwise returns an empty string.
+ * @return Returns the value if entry is found, otherwise returns an empty
+ * string.
*/
- public String getString(String name) {
- EasyStringEntry entry = getStringEntry(name);
+ public String getString(String name, boolean pull) {
+ EasyStringEntry entry = getStringEntry(name, pull);
return (entry == null) ? "" : (entry.cachedValue = entry.entry.get());
}
/**
* Sets the string value for the requested entry.
*
- * @param name The name of the entry.
+ * @param name The name of the entry.
* @param value The new value to publish to the entry.
*/
- public void putString(String name, String value) {
- EasyStringEntry entry = getStringEntry(name);
- if (entry == null) {
- stringEntries.add(new EasyStringEntry(name, value));
- } else if (entry.cachedValue != value) {
- entry.entry.set((entry.cachedValue = value));
- }
+ public void putString(String name, String value, boolean post) {
+ EasyStringEntry entry = getStringEntry(name, post);
+ if (post)
+ if (entry == null) {
+ stringEntries.add(new EasyStringEntry(name, value));
+ } else if (entry.cachedValue != value) {
+ entry.entry.set((entry.cachedValue = value));
+ }
}
// * -------- REMOVAL FUNCTIONS -------- *//
@@ -481,7 +514,11 @@ public void removeEntry(String name) {
*
* @param data The sendable to add.
*/
- public void putSmartDashboardSendable(String key, Sendable data) {
- SmartDashboard.putData(String.format("%s/%s", name, key), data);
+ public void putSmartDashboardSendable(String key, Sendable data, boolean post) {
+ String topic = key;
+ if (!name.equals("Generic"))
+ topic = String.format("%s/%s", name, key);
+ if (post)
+ SmartDashboard.putData(topic, data); // loop-overrun
}
}