Using Shuffleboard/NetworkTables in non-robot code

Hello. I’m currently making a simulation program and want to be able to use shuffleboard just like running simulateJava on an official robot project would work. I’m trying to avoid importing the GradleRIO plugin because the simulation might run on Android and I discovered that the Android build doesn’t like that plugin. Plus I’d rather just import the things that I want instead of getting everything.

If someone has an easy way to interface with Shuffleboard without importing wpiLib stuff, that would be nice, but I figured I’d have to go that route.

My first attempt is trying to import necessary things in my build.gradle and then using either NetworkTableInstance.getDefault() or NetworkTableInstance.create(). Both produced this error:

java.io.IOException: ntcorejni could not be loaded from path or an embedded resource.
attempted to load for platform /linux/x86-64/

at edu.wpi.first.wpiutil.RuntimeLoader.loadLibrary(RuntimeLoader.java:79)
at edu.wpi.first.networktables.NetworkTablesJNI.<clinit>(NetworkTablesJNI.java:23)
at edu.wpi.first.networktables.NetworkTableInstance.getDefault(NetworkTableInstance.java:97)
at com.first1444.sim.gdx.desktop_test.MyRobotCreator$create$robotCreator$1.invoke(MyRobotCreator.kt:109)

My build.gradle dependencies:

implementation "edu.wpi.first.ntcore:ntcore-java:$wpiLibVersion"
implementation "edu.wpi.first.ntcore:ntcore-jni:$wpiLibVersion"
implementation "edu.wpi.first.shuffleboard:api:$wpiLibVersion"
implementation "edu.wpi.first.shuffleboard:shuffleboard:$wpiLibVersion"

implementation "edu.wpi.first.hal:hal-java:$wpiLibVersion"
implementation "edu.wpi.first.hal:hal-jni:$wpiLibVersion"

implementation "edu.wpi.first.wpilibj:wpilibj-java:$wpiLibVersion"
implementation "edu.wpi.first.wpiutil:wpiutil-java:$wpiLibVersion"

I’m running Ubuntu 19.04.

My final goal is to be able to do stuff like Shuffleboard.getTab("my_tab").add(stuff) in my code just like on a real robot.

I’m unsure if importing the GradleRIO plugin would make this “just work,” but I’d like to avoid importing that anyway.

I’ve gotten NetworkTables to work on a Windows desktop client using the following build.gradle dependency:

repositories {
    maven {
        url 'http://first.wpi.edu/FRC/roborio/maven/release'
    }
}

dependencies {
    compile group: 'edu.wpi.first.ntcore', name: 'ntcore-java', version: '2019.4.1'
}

The only other thing I can think of is that it is not pulling the Linux JNI properly? I’d try checking if the gradle script pulled the libraries properly and that they are included in your project libraries.

As for implementing function calls for Shuffleboard, I have an example using just a modified version of the SmartDashboard class, which wouldn’t need the Shuffleboard libraries. (I did it this way because the examples for Shuffleboard given in the WPILib Docs seemed more complex than they really needed to be and it’s easier for people who are used to the Smartdashboard function calls to get used)

All the -jni dependencies need to look like the following.

-jni:$wpilibVersion:linuxx86-64 in order to work correctly.

In addition, they all use native libraries, so even if you got this working, those libraries would fail to work on Android. We don’t build Android, and have no plans to do so.

This works great. Thanks!

In order to use all of Shuffleboard’s features, these are the dependencies I used:

implementation "edu.wpi.first.ntcore:ntcore-java:$wpiLibVersion"
implementation "edu.wpi.first.ntcore:ntcore-jni:$wpiLibVersion"
implementation "edu.wpi.first.ntcore:ntcore-jni:$wpiLibVersion:linuxx86-64"
implementation "edu.wpi.first.wpilibj:wpilibj-java:$wpiLibVersion"
implementation "edu.wpi.first.wpiutil:wpiutil-java:$wpiLibVersion"
implementation "edu.wpi.first.cscore:cscore-java:$wpiLibVersion"
implementation "edu.wpi.first.hal:hal-java:$wpiLibVersion"
implementation "edu.wpi.first.hal:hal-jni:$wpiLibVersion"
implementation "edu.wpi.first.hal:hal-jni:$wpiLibVersion:linuxx86-64"

The reason cscore is included is so that when some class in shuffleboard is loaded it finds VideoSource.

I also had this before all of my code

NetworkTableInstance.getDefault().startServer()

You also have to call Shuffleboard.update() to get it to update.

Thanks for that example. I might end up creating something similar so I don’t have to have the cscore or wpilibj dependencies.

I might end up not using Shuffleboard on Android and having wrappers for using Shuffleboard stuff. More dependency injection for me. Yay.

I’m guessing implementing NetworkTables in pure Java doesn’t make sense for something as big as NetworkTables.

It’s not worth the maintainence burden, no. RobotPy reimplemented it in Python but they’re looking at switching back to wrapping the C++ implementation for performance reasons.

Note the cmake build in the wpilib repository can be used to build ntcore for other platforms. It’s a bit more work than just using the Gradle artifacts but it is fundamentally portable code.

1 Like