diff --git a/README.md b/README.md index 6fd57fb..e216d25 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ https://raw.githubusercontent.com/ThePinkAlliance/core/main/ThePinkAlliance.json ## Linear Interpolation -The linear interpolation class takes a list of integer pairs and will interpolate between the input (the first number in the pair) to the calculated output (the mathematically calculated second number in the pairs). Some use cases for linear interpolation could be using a table of distances give by a limelight to the real distance. +The linear interpolation class takes a list of integer pairs and will interpolate between the input (the first number in the pair) to the calculated output (the mathematically calculated second number in the pairs). Some use cases for linear interpolation may involve using a table of distances give by a limelight to the real distance. ### Example @@ -32,15 +32,32 @@ The linear interpolation class takes a list of integer pairs and will interpolat double real_distance = table.interp(123); // Outputs 128 inches ``` +## Telemetry + +The purpose of the Telemetery class is to serve as a replacement for SmartDashboard. Over time, the use of smart dashboard can lead to a cluttered dashboard and can make tuning difficult during competitions. The Telemetry class allows tuning data to be stored in its own tab and organized by parent class. + +### Example + +```java + Telemetry.logData("Motor Output", motor.getPower(), JoystickDrive.class); + Telemetry.logData("x", x, JoystickDrive.class); +``` + +The code above generates this list which stores all the values being logged for this specific class. Just to clear up some things, how the logger creates list names it starts with the name of the parent class first. After the two colons, `::` it appends what class its extending to the end of the name. The purpose of this makes distinguishing `subsystems` from `commands` easier. + +_NOTE: Sometimes the list isn't added to Shuffleboard and may need to be added manually._ + +![telemetry example](docs/telemetry-example1.png) + ## Spherical Coordinates -The spherical coordinates class makes using the spherical coordinate system easier with some builtin utilites. Just as a quick refresher instead of using x, y, and z for units spherical coordinates use projection (r), azimuth (θ), and elevation (Φ). If your not familar with spherical coordinates theres a great article [here](https://mathinsight.org/spherical_coordinates) to help you out. +The spherical coordinates class makes using the spherical coordinate system easier with some built-in utilites. As a quick refresher, instead of using x, y, and z for units, spherical coordinates use projection (r), azimuth (θ), and elevation (Φ). If you're not familar with spherical coordinates theres a great article [here](https://mathinsight.org/spherical_coordinates) to help you out. ### Example ```java // Creating coordinates with known constants. - double x= 0; + double x = 0; double y = 0; double z = 0; diff --git a/ThePinkAlliance.json b/ThePinkAlliance.json index 476d49b..7ab3b6e 100644 --- a/ThePinkAlliance.json +++ b/ThePinkAlliance.json @@ -1,7 +1,7 @@ { "fileName": "ThePinkAlliance.json", "name": "ThePinkAlliance", - "version": "2.3.17", + "version": "2.3.3", "uuid": "9619F7EA-7F96-4236-9D94-02338DFED572", "mavenUrls": [ "https://jitpack.io", @@ -13,7 +13,7 @@ { "groupId": "com.github.ThePinkAlliance", "artifactId": "core", - "version": "2.3.17" + "version": "2.3.3" } ], "jniDependencies": [], diff --git a/build.gradle b/build.gradle index a666ba2..d26fb13 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'java-library' apply plugin: 'maven-publish' group = 'com.ThePinkAlliance.core' -version = '2.3.17' +version = '2.3.3' sourceCompatibility = JavaVersion.VERSION_11 // java 11 targetCompatibility = JavaVersion.VERSION_11 diff --git a/docs/telemetry-example1.png b/docs/telemetry-example1.png new file mode 100644 index 0000000..d118b92 Binary files /dev/null and b/docs/telemetry-example1.png differ diff --git a/src/main/java/com/ThePinkAlliance/core/logging/Telemetry.java b/src/main/java/com/ThePinkAlliance/core/logging/Telemetry.java new file mode 100644 index 0000000..3655eab --- /dev/null +++ b/src/main/java/com/ThePinkAlliance/core/logging/Telemetry.java @@ -0,0 +1,76 @@ +package com.ThePinkAlliance.core.logging; + +import java.util.HashMap; + +import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; +import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardContainer; +import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; +import edu.wpi.first.wpilibj.shuffleboard.SimpleWidget; + +public class Telemetry { + private static ShuffleboardContainer tab = Shuffleboard.getTab("debug"); + private static HashMap layouts = new HashMap<>(); + private static HashMap widgets = new HashMap<>(); + + public Telemetry() { + } + + /** + * Logs data to the debug tab on Shuffleboard stored in a list with the name of + * the parent class. + * + * @param title Name of the data being logged. + * @param data The data object being logged. Permitted types: Strings, + * Doubles, + * Integers, and Longs. + * @param parent The parent class object. + */ + public static void logData(String title, Object data, Class parent) { + Class superClass = parent.getSuperclass(); + String className = parent.getSimpleName(); + String superClassName = superClass != null ? superClass.getSimpleName() : "Unknown"; + int id = (className + superClassName).hashCode(); + ShuffleboardLayout layout = layouts.get(id); + SimpleWidget currentWidget = widgets.get(title); + + if (layout == null) { + layout = tab.getLayout(className + " :: " + superClassName, "List"); + } + + if (currentWidget == null) { + currentWidget = layout.add(title, serializeDataType(data)); + } + + if (data instanceof Integer) { + currentWidget.getEntry().setInteger((long) data); + } else if (data instanceof String) { + currentWidget.getEntry().setString((String) data); + } else if (data instanceof Double) { + currentWidget.getEntry().setDouble((double) data); + } else { + currentWidget.getEntry().setString(data.toString()); + } + + if (layout == null) { + layouts.put(id, layout); + } + + widgets.put(title, currentWidget); + } + + /** + * Serialize the data type. And convert it into string if it's not a permitted + * data + * type (String, Long, Integer, Double). + */ + private static Object serializeDataType(Object data) { + boolean validType = data instanceof Integer || data instanceof String || data instanceof Double + || data instanceof Long; + + if (!validType) { + return data.toString(); + } else { + return data; + } + } +} diff --git a/src/test/java/LinearInterpolationTest.java b/src/test/java/LinearInterpolationTest.java index 6404983..d3e468b 100644 --- a/src/test/java/LinearInterpolationTest.java +++ b/src/test/java/LinearInterpolationTest.java @@ -2,8 +2,8 @@ import java.util.List; +import com.ThePinkAlliance.core.logging.Telemetry; import com.ThePinkAlliance.core.math.LinearInterpolationTable; -import com.ThePinkAlliance.core.math.Vector2d; import edu.wpi.first.math.Pair; import org.junit.Test;