From dc8b6fd8bc3a759dba85ff697972e7075fabee8d Mon Sep 17 00:00:00 2001 From: Mason-Lam <97353903+Mason-Lam@users.noreply.github.com> Date: Tue, 28 Nov 2023 01:11:41 -0800 Subject: [PATCH] Minor Cleanup --- 3128-Common.json | 4 +- 3128-common.json | 4 +- .../common/core/controllers/Controller.java | 16 +++++ .../core/subsystems/NAR_PIDSubsystem.java | 6 +- .../narwhaldashboard/NarwhalDashboard.java | 9 +++ .../shuffleboard/NAR_Shuffleboard.java | 66 +++++++++---------- 6 files changed, 65 insertions(+), 40 deletions(-) diff --git a/3128-Common.json b/3128-Common.json index 6f86554..5bbd4dc 100644 --- a/3128-Common.json +++ b/3128-Common.json @@ -1,6 +1,6 @@ { "name": "3128-common", - "version": "0.0.6", + "version": "0.0.7", "uuid": "ae3fa5a2-78d9-47e8-921a-dba45b889445", "mavenUrls": [ "https://jitpack.io" @@ -11,7 +11,7 @@ { "groupId": "com.github.Team3128", "artifactId": "3128-common", - "version": "0.0.6" + "version": "0.0.7" } ], "jniDependencies": [], diff --git a/3128-common.json b/3128-common.json index 6f86554..5bbd4dc 100644 --- a/3128-common.json +++ b/3128-common.json @@ -1,6 +1,6 @@ { "name": "3128-common", - "version": "0.0.6", + "version": "0.0.7", "uuid": "ae3fa5a2-78d9-47e8-921a-dba45b889445", "mavenUrls": [ "https://jitpack.io" @@ -11,7 +11,7 @@ { "groupId": "com.github.Team3128", "artifactId": "3128-common", - "version": "0.0.6" + "version": "0.0.7" } ], "jniDependencies": [], diff --git a/src/main/java/common/core/controllers/Controller.java b/src/main/java/common/core/controllers/Controller.java index fb97ea6..327acc5 100644 --- a/src/main/java/common/core/controllers/Controller.java +++ b/src/main/java/common/core/controllers/Controller.java @@ -55,6 +55,22 @@ public Controller(double kP, double kI, double kD, double kS, double kV, double this.type = type; } + /** + * Create a new object to control PID + FF logic for a subsystem. + *

Sets kP, kI, kD, kS, kV, kG values. + * + * @param kP The proportional coefficient. + * @param kI The integral coefficient. + * @param kD The derivative coefficient. + * @param kS The static gain. + * @param kV The velocity gain. + * @param kG The gravity gain. + * @param type The type of setpoint used by the controller + */ + public Controller(double kP, double kI, double kD, double kS, double kV, double kG, Type type) { + this(kP, kI, kD, kS, kV, kG, type, 0.02); + } + /** * Create a new object to control PID logic for a subsystem. *

Sets kP, kI, kD, period values. diff --git a/src/main/java/common/core/subsystems/NAR_PIDSubsystem.java b/src/main/java/common/core/subsystems/NAR_PIDSubsystem.java index d0c1b3c..7222a89 100644 --- a/src/main/java/common/core/subsystems/NAR_PIDSubsystem.java +++ b/src/main/java/common/core/subsystems/NAR_PIDSubsystem.java @@ -32,7 +32,7 @@ public abstract class NAR_PIDSubsystem extends SubsystemBase { public NAR_PIDSubsystem(Controller controller) { m_controller = controller; controller.setMeasurementSource(()-> getMeasurement()); - controller.addOutput(this::useOutput); + controller.addOutput(output -> useOutput(output, getSetpoint())); min = Double.NEGATIVE_INFINITY; max = Double.POSITIVE_INFINITY; safetyThresh = 5; @@ -166,7 +166,7 @@ public boolean atSetpoint() { * * @param output the output of the PIDController */ - protected abstract void useOutput(double output); + protected abstract void useOutput(double output, double setpoint); /** * Returns the measurement of the process variable used by the PIDController. @@ -185,7 +185,7 @@ public void enable() { /** Disables the PID control. Sets output to zero. */ public void disable() { m_enabled = false; - useOutput(0); + useOutput(0, 0); } /** diff --git a/src/main/java/common/utility/narwhaldashboard/NarwhalDashboard.java b/src/main/java/common/utility/narwhaldashboard/NarwhalDashboard.java index b4496ad..2b92475 100644 --- a/src/main/java/common/utility/narwhaldashboard/NarwhalDashboard.java +++ b/src/main/java/common/utility/narwhaldashboard/NarwhalDashboard.java @@ -81,6 +81,14 @@ private NarwhalDashboard(int port) throws UnknownHostException { super(new InetSocketAddress(port)); } + /** + * Returns the selectedAuto on the web server + * @return A string containing an auto + */ + public String getSelectedAuto() { + return selectedAuto; + } + /** * Initializes NarwhalDashboard autos and buttons */ @@ -203,6 +211,7 @@ public void addButton(String key, BooleanConsumer button) { @Override public void onMessage(WebSocket conn, String message) { Log.info("NarwhalDashboard", message); + //Message format category + key + value or category + value, example auto:"exampleAuto" final String[] parts = message.split(":"); if (!actionMap.containsKey(parts[0])) return; diff --git a/src/main/java/common/utility/shuffleboard/NAR_Shuffleboard.java b/src/main/java/common/utility/shuffleboard/NAR_Shuffleboard.java index 55241c1..ee71637 100644 --- a/src/main/java/common/utility/shuffleboard/NAR_Shuffleboard.java +++ b/src/main/java/common/utility/shuffleboard/NAR_Shuffleboard.java @@ -51,24 +51,24 @@ public void update() { private static HashMap> tabs = new HashMap>();; /** - * Creates a new tab entry - * - * @param tabName the title of the new tab - */ + * Creates a new tab entry + * + * @param tabName the title of the new tab + */ private static void create_tab(String tabName) { tabs.put(tabName, new HashMap()); } /** - * Displays a value in Shuffleboard - * - * @param tabName the title of the tab to select - * @param name the name of the entry - * @param data value to display - * @param x -coord of the entry starting from 0 - * @param y -coord of the entry starting from 0 - * @return simple widget that can be modified - */ + * Displays a value in Shuffleboard + * + * @param tabName the title of the tab to select + * @param name the name of the entry + * @param data value to display + * @param x -coord of the entry starting from 0 + * @param y -coord of the entry starting from 0 + * @return simple widget that can be modified + */ public static SimpleWidget addData(String tabName, String name, Object data, int x, int y) { return addData(tabName, name, data, x, y, 1, 1); } @@ -111,27 +111,27 @@ public static SimpleWidget addData(String tabName, String name, Supplier } /** - * Displays a value in Shuffleboard - * - * @param tabName the title of the tab to select - * @param name the name of the entry - * @param data value to display - * @param x -coord of the entry starting from 0 - * @param y -coord of the entry starting from 0 - * @param width -of the entry - * @param height -of the entry - * @return simple widget that can be modified - */ - public static SimpleWidget addData(String tabName, String name, Object data, int x, int y, int width, int height) { - if(!tabs.containsKey(tabName)) create_tab(tabName); - if (tabs.get(tabName).containsKey(name)) { - tabs.get(tabName).get(name).m_data.setValue(data); - return tabs.get(tabName).get(name).m_entry; + * Displays a value in Shuffleboard + * + * @param tabName the title of the tab to select + * @param name the name of the entry + * @param data value to display + * @param x -coord of the entry starting from 0 + * @param y -coord of the entry starting from 0 + * @param width -of the entry + * @param height -of the entry + * @return simple widget that can be modified + */ + public static SimpleWidget addData(String tabName, String name, Object data, int x, int y, int width, int height) { + if(!tabs.containsKey(tabName)) create_tab(tabName); + if (tabs.get(tabName).containsKey(name)) { + tabs.get(tabName).get(name).m_data.setValue(data); + return tabs.get(tabName).get(name).m_entry; + } + SimpleWidget entry = Shuffleboard.getTab(tabName).add(name,data).withPosition(x, y).withSize(width,height); + tabs.get(tabName).put(name, new entryInfo(entry,null)); + return entry; } - SimpleWidget entry = Shuffleboard.getTab(tabName).add(name,data).withPosition(x, y).withSize(width,height); - tabs.get(tabName).put(name, new entryInfo(entry,null)); - return entry; -} /** * Displays complex values, like subsystems and command, works on all classes that extend sendable