OCCRA
Go to Post 71, sponsored by Beatty, was breaking the box apart--not just thinking outside it. - Kevin Ray [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 05-14-2018, 05:43 PM
0x54796C6572's Avatar
0x54796C6572 0x54796C6572 is offline
Registered User
AKA: Tyler Tian
FRC #6135 (Arctos)
Team Role: Programmer
 
Join Date: Apr 2018
Rookie Year: 2017
Location: Toronto, Ontario, Canada
Posts: 12
0x54796C6572 is an unknown quantity at this point
NetworkTables not updating

I'm trying to use a standalone Java program to send values over NetworkTables, which the robot will constantly read and respond to.

Here's the code for the separate Java program:
Code:
static NetworkTableInstance tableInstance;
static NetworkTable table;
	
static NetworkTableEntry state;

//...

tableInstance = NetworkTableInstance.getDefault();
table = tableInstance.getTable("control");
		
state = table.getEntry("state");
tableInstance.startClientTeam(6135);
tableInstance.startDSClient();

state.setNumber(0x0001);
try {
	Thread.sleep(3000);
}
catch(Exception e) {
	e.printStackTrace();
}
System.out.println("Setting to 0");
state.setNumber(0x0000);
And here's the robot code:
Code:
public static NetworkTableInstance tableInstance;
public static NetworkTable table;
public static NetworkTableEntry stateEntry;

//...

tableInstance = NetworkTableInstance.getDefault();
table = tableInstance.getTable("control");
stateEntry = table.getEntry("state");

//teleopPeriodic()
System.out.println(stateEntry.getNumber(ACT_REST).intValue());
However, when I run this code, only the first call to setNumber() actually updates the value of the table entry read from the robot. All the subsequent calls only sets the value of the entry for the Java program side, and the value read by the robot stays the same. Can someone point out the issue for me?
Reply With Quote
  #2   Spotlight this post!  
Unread 05-14-2018, 07:54 PM
Peter Johnson Peter Johnson is offline
Volunteer WPILib Developer, CSA
no team (WPILib)
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Redondo Beach, CA
Posts: 532
Peter Johnson has a reputation beyond reputePeter Johnson has a reputation beyond reputePeter Johnson has a reputation beyond reputePeter Johnson has a reputation beyond reputePeter Johnson has a reputation beyond reputePeter Johnson has a reputation beyond reputePeter Johnson has a reputation beyond reputePeter Johnson has a reputation beyond reputePeter Johnson has a reputation beyond reputePeter Johnson has a reputation beyond reputePeter Johnson has a reputation beyond repute
Re: NetworkTables not updating

What does the full program look like for the separate Java program? It's unclear from the snippet you sent whether that code is running in a loop, or whether the program exits after the last setNumber() call. If the latter, that's the issue--NetworkTables calls are completely asynchronous, so setNumber() returns before the number is actually sent over the network. If your program exits immediately afterwards, NetworkTables has no time to get the value over to the robot (normally this is done every 100 ms, although you can set it to a faster rate or use flush() to semi-synchronize).
__________________
WPILib Developer, 2014-Present:
  • Author of cscore - WPILib CameraServer for 2017+
  • Author of ntcore - WPILib NetworkTables for 2016+
Creator of RobotPy - Python for FRC
Mentor, Team 294, 2008-2018 (World Champions FRC 2010 & FTC 2008)
Reply With Quote
  #3   Spotlight this post!  
Unread 05-14-2018, 08:00 PM
0x54796C6572's Avatar
0x54796C6572 0x54796C6572 is offline
Registered User
AKA: Tyler Tian
FRC #6135 (Arctos)
Team Role: Programmer
 
Join Date: Apr 2018
Rookie Year: 2017
Location: Toronto, Ontario, Canada
Posts: 12
0x54796C6572 is an unknown quantity at this point
Re: NetworkTables not updating

Ah, that's probably the problem! The program does indeed exit exit right after the last setNumber() call. I'll try it out once I get access to the robot again. Thank you so much!
Reply With Quote
  #4   Spotlight this post!  
Unread 05-14-2018, 08:18 PM
0x54796C6572's Avatar
0x54796C6572 0x54796C6572 is offline
Registered User
AKA: Tyler Tian
FRC #6135 (Arctos)
Team Role: Programmer
 
Join Date: Apr 2018
Rookie Year: 2017
Location: Toronto, Ontario, Canada
Posts: 12
0x54796C6572 is an unknown quantity at this point
Re: NetworkTables not updating

By the way, the entire program is as follows:

Code:
package myobot.bridge;

import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;

public class Main {
	
	static NetworkTableInstance tableInstance;
	static NetworkTable table;
	
	static NetworkTableEntry state;
	
	public static final int PORT = 6135;

	public static void main(String[] args) {
		tableInstance = NetworkTableInstance.getDefault();
		table = tableInstance.getTable("control");
		
		state = table.getEntry("state");
		tableInstance.startClientTeam(6135);
		tableInstance.startDSClient();
		
		state.setDouble(0x0004);
		try {
			Thread.sleep(3000);
			state.setNumber(0x0001);
		}
		catch(Exception e) {
			e.printStackTrace();
		}
		System.out.println("Setting to 0");
		state.setNumber(0x0001);
		
	}

}
The program was supposed to receive data over a socket and update NetworkTables values accordingly, but for testing I commented out all the networking stuff so this is all there is for the program.
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 04:33 PM.

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


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