View Full Version : Can't put data or get data from network table using pynetworktables
Hello,
This season we used RoboRealm for vision and used their network tables to talk to our RoboRio which is running Java and didn't have a problem. We decided to switch to opencv (python), but have not had any luck with pynetworktables even though we're following the examples online. We're using pynetwortables version 2015.3.4 and python 2.7.11 through Anaconda 4.0.0 on a Windows machine. The code relating to the network tables that we have is:
from networktables import NetworkTable
import logging
logging.basicConfig(level=logging.DEBUG)
NetworkTable.setIPAddress('10.5.1.11')
NetworkTable.setClientMode()
NetworkTable.initialize()
sd = NetworkTable.getTable("SmartDashboard")
sd.putNumber('Distance', distance)
(Note: in the regular code distance is a defined variable and SmartDashboard is the correct name of our dashboard)
When we run this we don't get an error, but our table doesn't get updated with the variable and its value. When we try getting numbers from the table with sd.getNumber('variable') then we get a keyError.
Additionally, if I run the code,stop it, and then run it again I get an error saying the table has already been initialized. However if I exit spyder (the IDLE) I'm using in between each time I run the code I don't get the error.
Does anyone have any idea why these things are happening and how to fix them?
Thanks in advance!
virtuald
19-05-2016, 09:18
Hello,
This season we used RoboRealm for vision and used their network tables to talk to our RoboRio which is running Java and didn't have a problem. We decided to switch to opencv (python), but have not had any luck with pynetworktables even though we're following the examples online. We're using pynetwortables version 2015.3.4 and python 2.7.11 through Anaconda 4.0.0 on a Windows machine. The code relating to the network tables that we have is:
from networktables import NetworkTable
import logging
logging.basicConfig(level=logging.DEBUG)
NetworkTable.setIPAddress('10.5.1.11')
NetworkTable.setClientMode()
NetworkTable.initialize()
sd = NetworkTable.getTable("SmartDashboard")
sd.putNumber('Distance', distance)
(Note: in the regular code distance is a defined variable and SmartDashboard is the correct name of our dashboard)
When we run this we don't get an error, but our table doesn't get updated with the variable and its value. When we try getting numbers from the table with sd.getNumber('variable') then we get a keyError.
Additionally, if I run the code,stop it, and then run it again I get an error saying the table has already been initialized. However if I exit spyder (the IDLE) I'm using in between each time I run the code I don't get the error.
Does anyone have any idea why these things are happening and how to fix them?
Thanks in advance!
I refer you to the troubleshooting section of the documentation:
http://pynetworktables.readthedocs.io/en/latest/troubleshooting.html
Why are you telling it to connect to x.x.x.11? Is that the Robot IP? It will only work if there's a NT server to connect to (eg, a robot).
Yes, that is the robot ip address that we are trying to connect to. We have also tried roborio-501.local with no success. Our code looks identical to the trouble shooting guide and we have been using WPI's TableViewer, and it appears that nothing is being transmitted.
I'm not sure if a connection is being made. I enabled logging, but when I run the program in spyder there are no logging messages appearing in the IPython console. Is there somewhere else I'm supposed to be looking for logging messages? If not, the docs say that if this happens there's still a problem. What should I do next?
Thanks!
virtuald
19-05-2016, 11:28
Yes, that is the robot ip address that we are trying to connect to. We have also tried roborio-501.local with no success. Our code looks identical to the trouble shooting guide and we have been using WPI's TableViewer, and it appears that nothing is being transmitted.
I'm not sure if a connection is being made. I enabled logging, but when I run the program in spyder there are no logging messages appearing in the IPython console. Is there somewhere else I'm supposed to be looking for logging messages? If not, the docs say that if this happens there's still a problem. What should I do next?
Thanks!
Does the table viewer connect successfully? (eg, it can see changes in NT on the robot?). If not, there's probably a networking issue of some kind.
The log messages should show up in the console. If they don't show up, then it's not connecting. One experiment you can do is you can tell tableviewer to be a server, and tell pynetworktables to connect to localhost... that should work, and you'll see the appropriate log messages.
10.xx.xx.11 is a strange IP for the roborio.
Yes, that is the robot ip address that we are trying to connect to. We have also tried roborio-501.local with no success. Our code looks identical to the trouble shooting guide and we have been using WPI's TableViewer, and it appears that nothing is being transmitted.
I'm not sure if a connection is being made. I enabled logging, but when I run the program in spyder there are no logging messages appearing in the IPython console. Is there somewhere else I'm supposed to be looking for logging messages? If not, the docs say that if this happens there's still a problem. What should I do next?
Thanks!
.11 is the camera
Your mDNS is also incorrect, should be roborio-501-frc.local
If the top isn't true you messed up your networking settings
If the bottom isn't true than your RIO is not updated
The connection was the problem because you were right about me putting the wrong ip address! It's all set now; thank you very much!
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.