Go to Post Can't we also care about and celebrate the processes, the professionalism, the experience of healing? - Taylor [more]
Home
Go Back   Chief Delphi > Technical > Programming > Python
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-02-2016, 01:12
kingnyancatjack's Avatar
kingnyancatjack kingnyancatjack is offline
Registered User
AKA: Tommy Zhu
FRC #2605 (Seamonster Robotics)
Team Role: Engineer
 
Join Date: Feb 2015
Rookie Year: 2013
Location: Sehome High School
Posts: 1
kingnyancatjack is an unknown quantity at this point
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 21-02-2016, 13:21
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Vision With GRIP

Quote:
Originally Posted by kingnyancatjack View Post
self.table = NetworkTable.getTable('GRIP/myContoursReport')
->
Code:
NetworkTable.getTable("/GRIP/myContoursReport")
also, next time, use [code][/code] tags
__________________
FRC Team 1684 - Head Programmer (2013-2016)
FRC Team 5460 - Programming Mentor (2015-2016)

FIRST in Michigan - Technical Crew (2015-continuing)
Reply With Quote
  #3   Spotlight this post!  
Unread 22-02-2016, 21:24
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 214
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: Vision With GRIP

Quote:
Originally Posted by Arhowk View Post
->
Code:
NetworkTable.getTable("/GRIP/myContoursReport")
also, next time, use [code][/code] tags
We are suffering from the same problem with the exact same code. Here is a more verbose description of what is happening:

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>}
Thanks!
Reply With Quote
  #4   Spotlight this post!  
Unread 23-02-2016, 00:39
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,032
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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:
  • Set a default value when your program starts up
  • Surround the retrieveValue() call with a try...except block

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)
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #5   Spotlight this post!  
Unread 23-02-2016, 23:19
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
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.
__________________
FRC Team 1684 - Head Programmer (2013-2016)
FRC Team 5460 - Programming Mentor (2015-2016)

FIRST in Michigan - Technical Crew (2015-continuing)
Reply With Quote
  #6   Spotlight this post!  
Unread 01-03-2016, 22:25
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 214
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
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)
Thanks!
Reply With Quote
  #7   Spotlight this post!  
Unread 01-03-2016, 22:27
ThomasClark's Avatar
ThomasClark ThomasClark is offline
Registered User
FRC #0237
 
Join Date: Dec 2012
Location: Watertown, CT
Posts: 146
ThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud of
Re: Vision With GRIP

GRIP is a client. The server should be your roboRIO.
__________________
GRIP (Graphically Represented Image Processing) - rapidly develop computer vision algorithms for FRC
Reply With Quote
  #8   Spotlight this post!  
Unread 01-03-2016, 22:29
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 214
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: Vision With GRIP

Quote:
Originally Posted by ThomasClark View Post
GRIP is a client. The server should be your roboRIO.
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.
Reply With Quote
  #9   Spotlight this post!  
Unread 02-03-2016, 00:15
Peter Johnson Peter Johnson is offline
WPILib Developer
FRC #0294 (Beach Cities Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Redondo Beach, CA
Posts: 243
Peter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud of
Re: Vision With GRIP

Quote:
Originally Posted by team-4480 View Post
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.
Correct, because the roboRio is the server. Clicking "Server" makes the Viewer its own server.
__________________
Author of ntcore - WPILib NetworkTables for 2016+
Creator of RobotPy - Python for FRC

2010 FRC World Champions (294, 67, 177)
2007 FTC World Champions (30, 74, 23)
2001 FRC National Champions (71, 294, 125, 365, 279)
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 21:39.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi