SmartDashboard Variable Not Updating...Sometimes

I have a LabVIEW dashboard running sending data to Java robot code. Most of the time it works, but sometimes the variable being read in the Java robot code as shown below stops updating and continues outputting the last value. If there is an exception, it should return -1, not the last value, so I’m not sure what’s happening.

/** 
* Polls the target dimensions from the dashboard.
* If they are not present, it returns {-1, -1}.
*  
* @return an array of the {x center of mass, y center of mass}
* */
public double] getTargetCenterOfMass(){
	double x = -1;
	double y = -1;
		
	try{
		x = SmartDashboard.getNumber("vision_target_x_cm");
		y = SmartDashboard.getNumber("vision_target_y_cm");
	}catch(Exception e){
		e.printStackTrace();
	}
	
	double data] = {x, y};
	
	return data;
}

I attached a screenshot of the console where I was debugging our targeting when this started happening (and it has happened many times before, but only this season since we just started using Java this year).

I can see through the Network Variables tab on the LabVIEW dashboard that the values are indeed being updated, yet the Java SmartDashbord.getNumber() is not reflecting the changes. Sometimes disconnecting, waiting, and reconnecting to the robot fixes it. Other times I have to reboot the robot.

Does anyone know why this would happen?
Thanks in advance.





I have seen something similar to this, with a LabVIEW dashboard sending to a java robot. However, it only occurs after a long time (10s of minutes) and only affects variables being written frequently. We changed our dashboard to only write if the new value is different then the previous value, and the problem has effectively gone away.

I haven’t been able to duplicate in a clean environment, yet (eg minimal code with a good connection), I’ve only seen it over wireless with full robot code and dashboard.

As to avoid

Here’s the answer:

To ensure that the SmartDashboard and TableViewer are showing exactly the same values, it is necessary to restart all of them at the same time. That way, old values that one is holding won’t get replicated to the others.

If you restart robot code and not the dashboard, you will need to restart the dashboard too if this happens.

https://wpilib.screenstepslive.com/s/3120/m/7932/l/91065-stale-data-and-smartdashboard