Log in

View Full Version : looking for sample - simple smartdashboard plugin which writes to networktable


charr
29-01-2014, 22:41
This is really a unit test. I want to create a plugin which, when the smartdashboard starts, will start writing values to the network tables - perhaps a continuous sine wave.

byteit101
05-02-2014, 13:10
There is now a tutorial here: http://wpilib.screenstepslive.com/s/3120/m/7932/l/172935-creating-a-custom-control-using-java

charr
05-02-2014, 13:23
Thanks, that is helpful. But actually I was looking for an example for the old smartdashboard.

There is now a tutorial here: http://wpilib.screenstepslive.com/s/3120/m/7932/l/172935-creating-a-custom-control-using-java

fovea1959
09-02-2014, 10:48
there was an example **buried** in last year's documentation... <rummage rummage>

I went through this over the summer: it worked well for the 2013 swing based dashboard, hope to see the same in 2014?

http://firstforge.wpi.edu/sf/wiki/do/viewPage/projects.smartdashboard/wiki/CreateExtension

fovea1959
09-02-2014, 16:11
If it's not essential that the sine-wave generator is part of the dashboard (where does that requirement come from?), then you can just write and run a separate program to stuff the data into the network tables (this is what robo realm does). Integration with the dashboard is not necessary to access the network tables.

The PC desktop version of the network tables library in in sunspotfrcsdk\desktop-lib, along with Javadocs.

charr
09-02-2014, 16:38
As I had said in my original posting, this is about unit testing and not about any "requirement". Or to say another way, the requirement is for the following unit test: a smartdashboard which sends data to the network tables. I've still not found such an example.
Thanks,
Chris
If it's not essential that the sine-wave generator is part of the dashboard (where does that requirement come from?), then you can just write and run a separate program to stuff the data into the network tables (this is what robo realm does). Integration with the dashboard is not necessary to access the network tables.

The PC desktop version of the network tables library in in sunspotfrcsdk\desktop-lib, along with Javadocs.

fovea1959
09-02-2014, 20:38
again, does it need to specifically be a smartdashboard, or just a Java program (it sounds like the latter)? In that case, the shorter route may be a standalone program to stuff the network tables.


package org.usfirst.frc3620.desktop.networktables;

import edu.wpi.first.wpilibj.networktables2.client.Networ kTableClient;
import edu.wpi.first.wpilibj.networktables2.stream.IOStre amFactory;
import edu.wpi.first.wpilibj.networktables2.stream.Socket Streams;
import java.io.IOException;

public class TableStuffer {

public static void main(String args[]) {
Throwable boom = null;
try {
String host = "10.36.20.2";
if (args.length > 0) {
host = args[0];
}
int port = 1735;
TableStuffer tableStuffer = new TableStuffer(host, port);
tableStuffer.go();
} catch (IOException ex) {
boom = ex;
} catch (RuntimeException ex) {
boom = ex;
}
if (boom != null) {
boom.printStackTrace();
}
}

NetworkTableClient client = null;

TableStuffer(String h, int p) throws IOException {
IOStreamFactory streamFactory = SocketStreams.newStreamFactory(h, p);
client = new NetworkTableClient(streamFactory);
}

void go() {
double degrees = 0;

while (true) {
if (!client.isConnected()) {
client.reconnect();
// fresh connection, restart the since wave
degrees = 0;
} else {
double s = Math.sin(degrees * Math.PI / 180.0);
System.out.println (degrees + " -> " + s);
client.putDouble("degrees", degrees);
client.putDouble("sin", s);
degrees ++;
}
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
}
}
}

}