FRC1076 / Vision2019

Target detection (python2 with opencv 3)
0 stars 2 forks source link

Add connection notification callback with wait loop for robust connection #1

Open mcolinj opened 5 years ago

mcolinj commented 5 years ago

If the pi powers up before the robot does, then it will need some wait time to connect to the SmartDashboard so it can publish the ntproperty for target detection.

Try to be robust about that.

mcolinj commented 5 years ago

See the example of the listener callback in ContinuingEducation:

Here's some notion (maybe wrong) about how to do it. Note that you need to research what the notification reports in info and connection, and need to know what it indicates (is it safe to get a table, a value, or what?)

NetworkTables.initialize(server=ip)
connected = False

def connectionListener(connected, info):
       #  test for info and connected for SmartDashboard?
       connected = True

NetworkTables.addConnectionListener(connectionListener, immediateNotify=True)

while not connected:
    #  do nothing, maybe sleep for a second

# Now you should be able to use the NetworkTables