Can't seem to retrieve SmartDashboard data for PyNetworkTables?

Hi,

Today’s problem of the day is the SmartDashboard. I am using this [summarized] code on the robot:


def robotInit(self):
     self.sensor = wpilib.AnalogInput(3)
     wpilib.SmartDashboard.putNumber("Clicky1", self.sensor.getValue())
def teleopPeriodic(self):
     wpilib.SmartDashboard.putNumber("Clicky1", self.sensor.getValue())

and this code on our driver station computer:


from networktables import NetworkTable

NetworkTable.setIPAddress("roborio-4480-frc.local")
NetworkTable.setClientMode()
NetworkTable.initialize()
sd - NetworkTable.getTable("SmartDashboard")
while True:
    try:
        print('distance:', sd.getNumber('Clicky1'))
    except KeyError:
        print('distance: N/A')

So I get a KeyError for when it tries to pull “Clicky1”. Am I supposed to put more code on the robot to define the Clicky1 name? Or is there a way to make sure I am connected for sure to the robot? Sorry for all the questions.

That looks correct. There should be a log message that prints out when you actually connect to the robot. You need to enable logging to see it:


# To see messages from networktables, you must setup logging
import logging
logging.basicConfig(level=logging.DEBUG)

You probably want to add a sleep in that while loop.

I assume you’ve already looked through the samples?

So is that logging in the robot code or the driver station code? Thanks!

The DS code. The robot already has logging enabled by default.

Is there a way to print out all the available keys? I still get the KeyError right away. Maybe it is not waiting to connect?

Check out the global listener sample.

It’s also broken for me.
it gives an error about incompatible version or whatever, so I think it rejects Network Tables 3.0.

Is there a way to get this to work with NT 3.0, or should I give up on PyNetworkTables?

If you’re using LabVIEW then it will not work until we upgrade the implementation to NetworkTables 3.0 (tracked at this github issue). However, it should work correctly with Java/C++ NetworkTables client/servers, despite the warning about incompatible revisions.

The global listener sample is great for figuring out if the other side has placed anything in NetworkTables.

Yes, I’m using LabVIEW. Is the upgrade anticipated to be before the end of the build season?

Peter has been working on a full migration to NT 3.0, but it’s a lot of effort and not done yet. I talked to Peter last night and he said he was going to look at putting together something quick this week that would allow us to be compatible with LabVIEW, as the question has come up a few times.

It’s been a couple weeks; any update on this?

Peter said he’s been busy, but has been working on it. He promised to post whatever he’s got by Wednesday.

Peter pushed a branch, can you try it out and let us know if it works for you? https://github.com/robotpy/pynetworktables/tree/nt3-barebones

He hasn’t tried it with LabVIEW, but says it works with the OutlineViewer + NT3.

I gave it a shot, and it seems to work nicely.
Was able to upload values and they appeared on the LabVIEW dashboard.

Thanks.

Cool. I’ve pushed an alpha release of this (2016.0.0alpha1) to pypi in case someone else needs it – you’ll need to specify the --pre argument to pip in order to install it.