|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Vision With GRIP
We have this code, but can't figure out why it doesn't work.
import wpilib import networktables from networktables import NetworkTable class Vision(): def __init__(self): # NetworkTable.setIPAddress("10.26.5.73") # NetworkTable.setServerMode() self.table = NetworkTable.getTable('GRIP/myContoursReport') def printCenter(self): self.centerX = networktables.NumberArray() self.center = self.table.retrieveValue("centerX", self.centerX) print("Center: " + str(self.center)) Please help. ![]() |
|
#2
|
||||
|
||||
|
Re: Vision With GRIP
Quote:
Code:
NetworkTable.getTable("/GRIP/myContoursReport")
|
|
#3
|
||||
|
||||
|
Re: Vision With GRIP
Quote:
Code:
retrieveValue
raise KeyError(name)
KeyError: '/GRIP/myContoursReport/centerX'
Locals at innermost frame:
{ 'entry': None,
'externalData': [],
'name': '/GRIP/myContoursReport/centerX',
'self': <networktables2.server.NetworkTableServer object at 0x1027b6c18>}
|
|
#4
|
||||
|
||||
|
Re: Vision With GRIP
The first thing that I would recommend is using table viewer to ensure that the value is actually available. And, even if it's not available, the retrieveValue API doesn't have functionality to set a default value, so you should do one of two things:
Finally, I tested the functionality, and you can use pynetworktables to retrieve a NumberArray. However, the retrieveValue function returns None, not an array. Therefore, the code you have above won't work -- but remove the assignment, and it should be fine: Code:
table = NetworkTable.getTable('/GRIP/myContoursReport')
na = NumberArray()
...
try:
table.retrieveValue('centerX', na)
except KeyError:
# do something else here...
else:
print(na)
|
|
#5
|
||||
|
||||
|
Re: Vision With GRIP
Oh, I didn't see that quirk in the code (kids- always format your code in code blocks)
retrieveValue works like alot of C functions where it requests a pointer to put data into rather than returning the data itself (for reasons). The first argument is the name of the key (similar to how youd use getNumber(key,default)). The second argument isnt the argument but rather the variable that the return value will be placed into. |
|
#6
|
||||
|
||||
|
Re: Vision With GRIP
I now have the problem of connecting to GRIP. GRIP seems to be the server and in order to access the variables, you need to use the ClientMode. The problem with that is you need the IP of the server. GRIP is going to be running on our Driver Station and the IP will not stay the same.
How am I supposed to connect to GRIP? Here is the working code(Just using GRIP locally by setting both to 127.0.0.1): Code:
import sys
import time
from networktables import NetworkTable
import networktables
ip = "127.0.0.1"
NetworkTable.setIPAddress(ip)
NetworkTable.setClientMode()
NetworkTable.initialize()
table = NetworkTable.getTable('/GRIP/myContoursReport')
default = networktables.NumberArray()
while True:
try:
table.retrieveValue('centerX', default)
except KeyError:
pass
else:
print default
time.sleep(1)
|
|
#7
|
||||
|
||||
|
Re: Vision With GRIP
GRIP is a client. The server should be your roboRIO.
|
|
#8
|
||||
|
||||
|
Re: Vision With GRIP
When I use Network Table Viewer to see the values, I need to click "Client" in order for it to work. "Server" never finds the table.
|
|
#9
|
|||
|
|||
|
Re: Vision With GRIP
Correct, because the roboRio is the server. Clicking "Server" makes the Viewer its own server.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|