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

Update SmartDashboard to use WPILib-2023.4.3 NetworkTable APIs #173

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c541691
basic changes to remove ITables and replace with NetworkTables; doesn…
chauser Apr 30, 2023
2db45bc
Convert NetworkTableValues to contained Object in appropriate places
chauser May 1, 2023
bdb59de
Bug fix -- looking in the parent table instead of the new table for '…
chauser May 1, 2023
6b3b936
Fixed Connection Indicator bug; fixed bug asking for DataType of Netw…
chauser May 1, 2023
ba1045e
Figured out why the Scheduler widget wasn't being registered for the …
chauser May 1, 2023
5162b23
Change to using NT interfaces from WPILib 4.1.3
chauser May 4, 2023
1d3acde
docstring cleanup; scheduler cancellation fixes (cancelling a command…
chauser May 5, 2023
5fc1fba
Apply Thad House's patch to get the build environment right
chauser May 5, 2023
1fde1ca
fix checkStyle failures
chauser May 5, 2023
0485a51
Add Help|About menu displaying version and build date from .jar file …
chauser May 5, 2023
a5031b0
Switch to NT4 client; fixes problems with deleting from the robot pre…
chauser May 6, 2023
1178153
Merge remote-tracking branch 'origin/main' into ModernWPILib; fix con…
chauser Jul 27, 2023
bddc899
start the NT server in fakerobot
chauser Jul 28, 2023
4163175
fix mode cast to (int) in CANSpeedController and change label of Spee…
chauser Jul 29, 2023
a161c95
Incorporate upstream changes that fix the widget for a PID Subsystem
chauser Aug 22, 2023
eab92a0
Speed Controller -> Motor Controller changes
chauser Aug 24, 2023
c8992e3
Fix FakeRobot test case for DigitalInput to use boolean instead of st…
chauser Aug 24, 2023
d1c29be
Fix LiveWindowFakeRobot test for DigitalInput to use boolean rather t…
chauser Aug 24, 2023
5b9afd6
Register SchedulerType so Scheduler instances in network tables don't…
chauser Aug 26, 2023
ea85b01
fix Chooser element so that NT keys seen before the .options key do n…
chauser Aug 26, 2023
dc7e122
Suppress attempts to create widgets for DataTypes that don't exist
chauser Aug 26, 2023
3dbac59
Disable NT driverstation client so SmartDashboard doesn't connect to …
chauser Sep 5, 2023
f4c9fc4
Fix formatting mistakes
chauser Sep 5, 2023
6068a32
Disable DSClient to fix 'Disappearing Chooser problem
chauser Sep 5, 2023
440d63f
Remove DSClient disable -- moved to separate branch
chauser Sep 5, 2023
33469b7
Enable DSClient after loading save.xml
chauser Sep 5, 2023
3bb28ee
Fix formatting errors
chauser Sep 5, 2023
3f372d5
Arrange that NetworkTables acquired in Robot.java are unique
chauser Sep 6, 2023
7b87ad7
Start DSClient before anything else and see what happens
chauser Sep 6, 2023
c0755a8
tweaking dsclient startup
chauser Sep 8, 2023
9009cd8
Merge branch 'UniqueTables' into DisableDSClient
chauser Sep 9, 2023
409bc81
Improve unique tables implementation
chauser Sep 9, 2023
0823260
add livewindow widgets to parent widgets when loaded from save file. …
chauser Sep 9, 2023
961b54f
Merge branch 'DisableDSClient' into FixSchedulerInLiveWindow; the branch
chauser Sep 9, 2023
90745f9
Merge branch 'FakeRobotDigitalInputFix' into FixSchedulerInLiveWindow
chauser Sep 9, 2023
9286be2
Merge branch 'main' into FixSchedulerInLiveWindow
chauser Sep 10, 2023
c19e72b
Fix UnsupportedOperationException when pressing scheduler Cancel buttons
chauser Sep 10, 2023
999d9ca
Fix compilation error
chauser Sep 10, 2023
f0a6667
Acquire fixes from the NT3 SD version
chauser Sep 11, 2023
d3c181f
merge fixes from NT3 version
chauser Sep 11, 2023
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id "com.jfrog.artifactory" version "4.16.0"
id "com.jfrog.artifactory" version "4.25.2"
id "com.diffplug.spotless" version "6.19.0"
id "com.github.spotbugs" version "5.0.14"
id 'maven-publish'
Expand All @@ -20,7 +20,7 @@ plugins {
id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '4.1.0'
id 'edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin' version '2020.2'
id 'checkstyle'
id 'edu.wpi.first.WpilibTools' version '0.9.1'
id 'edu.wpi.first.WpilibTools' version '1.0.0'
}

wpilibVersioning.buildServerMode = project.hasProperty('buildServer')
Expand Down
4 changes: 3 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ def nativeTasks = wpilibTools.createExtractionTasks {

nativeTasks.addToSourceSetResources(sourceSets.main)

wpilibTools.deps.wpilibVersion = "2021.3.1"
wpilibTools.deps.wpilibVersion = "2023.+"

nativeConfig.dependencies.add wpilibTools.deps.wpilib("ntcore")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil")

dependencies {
implementation wpilibTools.deps.wpilibJava("ntcore")
implementation wpilibTools.deps.wpilibJava("wpinet")
implementation wpilibTools.deps.wpilibJava("wpiutil")

implementation 'jfree:jcommon:1.0.16'
Expand Down
4 changes: 3 additions & 1 deletion fakeRobot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ def nativeTasks = wpilibTools.createExtractionTasks {

nativeTasks.addToSourceSetResources(sourceSets.main)

wpilibTools.deps.wpilibVersion = "2021.+"
wpilibTools.deps.wpilibVersion = "2023.+"

nativeConfig.dependencies.add wpilibTools.deps.wpilib("ntcore")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil")

dependencies {
implementation wpilibTools.deps.wpilibJava("ntcore")
implementation wpilibTools.deps.wpilibJava("wpinet")
implementation wpilibTools.deps.wpilibJava("wpiutil")

implementation "com.fasterxml.jackson.core:jackson-annotations:2.10.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package edu.wpi.livewindowfakerobot;

import edu.wpi.first.networktables.NetworkTablesJNI;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.tables.ITable;
import edu.wpi.first.wpiutil.CombinedRuntimeLoader;
import edu.wpi.first.wpiutil.WPIUtilJNI;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.util.CombinedRuntimeLoader;
import edu.wpi.first.util.WPIUtilJNI;

import java.io.IOException;
import java.util.Timer;
Expand All @@ -15,10 +15,9 @@
* @author Sam
*/
public class LiveWindowFakeRobot {

private static NetworkTable liveWindow;

private static ITable STATUS, wrist, wPotentiometer, wVictor, elevator, ePotentiometer,
private static NetworkTable STATUS, wrist, wPotentiometer, wVictor, elevator, ePotentiometer,
eVictor, testSys, tComp, tGearTooth, tVictor, tPotentiometer, tRelay, tDigitalOutput,
tGyro, tSolenoid, tServo, tAccel, tEncoder1, tUltra, tCompass, tSwitch, canSystem,
canJag, canTalon, ePID;
Expand All @@ -27,11 +26,16 @@ public static void main(String[] args) throws IOException {
WPIUtilJNI.Helper.setExtractOnStaticLoad(false);
NetworkTablesJNI.Helper.setExtractOnStaticLoad(false);
CombinedRuntimeLoader.loadLibraries(LiveWindowFakeRobot.class, "wpiutiljni", "ntcorejni");

liveWindow = NetworkTable.getTable("LiveWindow");
NetworkTableInstance.getDefault().startServer();

liveWindow = NetworkTableInstance.getDefault().getTable("LiveWindow");

STATUS = createTable(liveWindow, ".status", "LW Status");

wrist = createTable(liveWindow, "Wrist", "LW Subsystem");
wPotentiometer = createTable(wrist, "Potentiometer", "Analog Input");
wVictor = createTable(wrist, "Victor", "Motor Controller");

wrist = createTable(liveWindow, "Wrist", "LW Subsystem");
wPotentiometer = createTable(wrist, "Potentiometer", "Analog Input");
wVictor = createTable(wrist, "Victor", "Motor Controller");
Expand Down Expand Up @@ -62,48 +66,49 @@ public static void main(String[] args) throws IOException {
canTalon = createTable(canSystem, "CAN Talon", "CANSpeedController");

System.out.println();

STATUS.getEntry("LW Enabled").setBoolean(true);
STATUS.getEntry("Robot").setString("Testing");
wPotentiometer.getEntry("Value").setDouble(2.6);
ePotentiometer.getEntry("Value").setDouble(-11.6872);
tSwitch.getEntry("Value").setBoolean(false);

STATUS.putBoolean("LW Enabled", true);
STATUS.putString("Robot", "Testing");
wPotentiometer.putNumber("Value", 2.6);
ePotentiometer.putNumber("Value", -11.6872);
tSwitch.putBoolean("Value", false);

ePID.putNumber("p", 0.5);
ePID.putNumber("i", 0.5);
ePID.putNumber("d", 0.5);
ePID.putNumber("setpoint", 0.5);
ePID.getEntry("p").setDouble(0.5);
ePID.getEntry("i").setDouble(0.5);
ePID.getEntry("d").setDouble(0.5);
ePID.getEntry("setpoint").setDouble(0.5);

canJag.putString("Type", "CANJaguar");
canTalon.putString("Type", "CANTalon");
canJag.getEntry("Type").setString("CANJaguar");
canTalon.getEntry("Type").setString("CANTalon");


(new Timer()).schedule(
new TimerTask(){
@Override
public void run() {
wPotentiometer.putNumber("Value", (Math.random()-.5) * 24);
ePotentiometer.putNumber("Value", (Math.random()-.5) * 24);
tPotentiometer.putNumber("Value", (Math.random()-.5) * 24);
tGyro.putNumber("Value", Math.random() * 360);
tAccel.putNumber("Value", (Math.random()-.5)*8);
tSwitch.putBoolean("Value", Math.random() < 0.5 ? true : false);
tEncoder1.putNumber("Speed", Math.random() * 20);
tEncoder1.putNumber("Distance", Math.random() * 10);
tEncoder1.putNumber("Distance per Tick", Math.random());
tCompass.putNumber("Value", Math.random());
tUltra.putNumber("Value", (Math.random()-.5) * 200);
tGearTooth.putNumber("Value", (int)(Math.random() * 100));
wPotentiometer.getEntry("Value").setDouble((Math.random()-.5) * 24);
ePotentiometer.getEntry("Value").setDouble((Math.random()-.5) * 24);
tPotentiometer.getEntry("Value").setDouble((Math.random()-.5) * 24);
tGyro.getEntry("Value").setDouble(Math.random() * 360);
tAccel.getEntry("Value").setDouble((Math.random()-.5)*8);
tSwitch.getEntry("Value").setBoolean(Math.random() < 0.5 ? true : false);
tEncoder1.getEntry("Speed").setDouble(Math.random() * 20);
tEncoder1.getEntry("Distance").setDouble(Math.random() * 10);
tEncoder1.getEntry("Distance per Tick").setDouble(Math.random());
tCompass.getEntry("Value").setDouble(Math.random());
tUltra.getEntry("Value").setDouble((Math.random()-.5) * 200);
tGearTooth.getEntry("Value").setDouble((int)(Math.random() * 100));
}},
0, 500);

}

private static ITable createTable(ITable parent, String name, String type) {
ITable table = parent.getSubTable(name);
private static NetworkTable createTable(NetworkTable parent, String name, String type) {
NetworkTable table = parent.getSubTable(name);
System.out.println(table);
table.putString(".type", type);
table.putString(".name", name);
table.getEntry(".type").setValue(type);
table.getEntry(".name").setValue(name);
return table;
}
}
27 changes: 17 additions & 10 deletions src/main/java/edu/wpi/first/smartdashboard/LogToCSV.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package edu.wpi.first.smartdashboard;

import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEvent;
import edu.wpi.first.networktables.NetworkTable.TableEventListener;
import edu.wpi.first.smartdashboard.gui.DashboardFrame;
import edu.wpi.first.smartdashboard.robot.Robot;
import edu.wpi.first.wpilibj.tables.ITable;
import edu.wpi.first.wpilibj.tables.ITableListener;
import java.io.FileWriter;
import java.io.IOException;
import java.util.EnumSet;

import javax.swing.JOptionPane;

/**
* Logs all information received to a CSV file.
*
* @author pmalmsten
*/
public class LogToCSV implements ITableListener {
public class LogToCSV implements TableEventListener {

private static final String s_lineSeparator = System.getProperty("line.separator");
private long m_startTime;
private FileWriter m_fw;
private final DashboardFrame frame;
private int listenerHandle;

public LogToCSV(DashboardFrame frame) {
this.frame = frame;
Expand All @@ -38,9 +42,10 @@ public void start(String path) {
m_fw = new FileWriter(path);
m_fw.write("Time (ms),Name,Value" + s_lineSeparator);
m_fw.flush();
Robot.getTable().addTableListenerEx(this,
ITable.NOTIFY_IMMEDIATE | ITable.NOTIFY_LOCAL | ITable.NOTIFY_NEW
| ITable.NOTIFY_UPDATE);
listenerHandle = Robot.getTable().addListener(
EnumSet.of(NetworkTableEvent.Kind.kImmediate, NetworkTableEvent.Kind.kValueAll,
NetworkTableEvent.Kind.kPublish),
this);
} catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null,
Expand All @@ -66,16 +71,18 @@ public void stop() {
} catch (IOException ex) {
ex.printStackTrace();
}
Robot.getTable().removeTableListener(this);
Robot.getTable().removeListener(listenerHandle);
m_fw = null;
}

@Override
public void valueChanged(ITable source, String key, Object value, boolean isNew) {
if (!(value instanceof ITable) && m_fw != null) {
public void accept(NetworkTable source, String key,
NetworkTableEvent event) {
if (m_fw != null) {
try {
long timeStamp = System.currentTimeMillis() - m_startTime;
m_fw.write(timeStamp + "," + "\"" + key + "\"," + "\"" + value + "\"" + s_lineSeparator);
m_fw.write(timeStamp + "," + "\"" + key + "\"," + "\"" + event.valueData
.value.getValue() + "\"" + s_lineSeparator);
m_fw.flush();
} catch (IOException ex) {
ex.printStackTrace();
Expand Down
80 changes: 47 additions & 33 deletions src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package edu.wpi.first.smartdashboard;

import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.networktables.NetworkTablesJNI;
import edu.wpi.first.smartdashboard.extensions.FileSniffer;
import edu.wpi.first.smartdashboard.gui.DashboardFrame;
import edu.wpi.first.smartdashboard.properties.IntegerProperty;
import edu.wpi.first.smartdashboard.properties.StringProperty;
import edu.wpi.first.smartdashboard.robot.Robot;
import edu.wpi.first.wpiutil.CombinedRuntimeLoader;
import edu.wpi.first.wpiutil.WPIUtilJNI;
import edu.wpi.first.util.CombinedRuntimeLoader;
import edu.wpi.first.util.WPIUtilJNI;
import edu.wpi.first.smartdashboard.robot.Robot;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -59,8 +60,9 @@ public static void main(final String[] args) throws IOException {
NetworkTablesJNI.Helper.setExtractOnStaticLoad(false);
CombinedRuntimeLoader.loadLibraries(SmartDashboard.class, "wpiutiljni", "ntcorejni");


NetworkTablesJNI.getDefaultInstance();
// NetworkTablesJNI.getDefaultInstance();
var instance = NetworkTableInstance.getDefault();
instance.stopDSClient();

try {
SwingUtilities.invokeAndWait(new Runnable() {
Expand Down Expand Up @@ -101,32 +103,6 @@ public void run() {
System.exit(2);
}

if (argParser.hasValue("ip")) {
monitor.setProgress(650);
monitor.setNote("Connecting to robot at: " + argParser.getValue("ip"));
Robot.setHost(argParser.getValue("ip"));
System.out.println("IP: " + argParser.getValue("ip"));
} else {
monitor.setProgress(600);
monitor.setNote("Getting Team Number");
StringProperty teamProp = frame.getPrefs().team;
String teamNumber = teamProp.getValue();

teamNumberLoop:
while (teamNumber.equals("0")) {
String input = JOptionPane.showInputDialog("Input Team Number\\Host");
if (input == null) {
break teamNumberLoop;
}
teamNumber = input;
}

monitor.setProgress(650);
monitor.setNote("Connecting to robot: " + teamNumber);
Robot.setHost(teamNumber);
teamProp.setValue(teamNumber);
}

try {
SwingUtilities.invokeAndWait(new Runnable() {

Expand All @@ -135,7 +111,7 @@ public void run() {
frame.pack();
frame.setVisible(true);

monitor.setProgress(750);
monitor.setProgress(500);
monitor.setNote("Loading From Save");

// Load
Expand All @@ -144,7 +120,7 @@ public void run() {
frame.load(file.getPath());
}

monitor.setProgress(1000);
monitor.setProgress(750);

} catch (Exception e) {
e.printStackTrace();
Expand All @@ -157,5 +133,43 @@ public void run() {
ex.printStackTrace();
System.exit(2);
}
// Delay starting DSClient until save.xml is processed.
// If NT connection happens before save.xml is processed
// some widgets will not be rendered.
Robot.startDSClient();
try {
// Give time for DS client to supply server address
// before trying locally configured team number/address
Thread.sleep(500);
} catch (InterruptedException e) {
// ignore; no harm if sleep is interrupted
}
if (argParser.hasValue("ip")) {
monitor.setProgress(800);
monitor.setNote("Connecting to robot at: " + argParser.getValue("ip"));
Robot.setHost(argParser.getValue("ip"));
System.out.println("IP: " + argParser.getValue("ip"));
} else {
monitor.setProgress(850);
monitor.setNote("Getting Team Number");
StringProperty teamProp = frame.getPrefs().team;
String teamNumber = teamProp.getValue();

teamNumberLoop:
while (teamNumber.equals("0")) {
String input = JOptionPane.showInputDialog("Input Team Number\\Host");
if (input == null) {
break teamNumberLoop;
}
teamNumber = input;
}


monitor.setProgress(900);
monitor.setNote("Connecting to robot: " + teamNumber);
Robot.setHost(teamNumber);
teamProp.setValue(teamNumber);
monitor.setProgress(1000);
}
}
}
Loading