GRIP and NetworkTables settings for use with a co-processor

My team has successfully written an algorithm to consistently find this year’s targets in GRIP. However, for whatever reason we are unable to transmit contour information to our program on the roboRIO. I essentially copied our code line for line from the Java examples on ScreenstepsLive and the GRIP github page, with minor tweaks in order to access the variables we care about. Our GRIP related code is as follows:
In constructor:
table = NetworkTable.getTable(“GRIP/myContoursReport”);
In operatorControl:
targetWidth = table.getNumber(“width”, 0);
When we run our program, the default value of zero is always returned. We run GRIP on a separate laptop(we eventually hope to use a Kangaroo on our robot, but it has not arrived yet). In GRIP I have set the NetworkTables server address as roborio-4541-frc.local, and we can view all of the contour information on our main laptop using OutlineViewer in client mode with the server at the same address. I tried running our code as a client as well, but recieved an error stating that there was already an instance of NetworkTables running. This is our first year using NetworkTables, so I do not have the required knowledge to troubleshoot this problem any further on my own(I’ve already spent a good 2-3 meetings working on this). Any help or advice anyone could give would be much appreciated.

The robot is always the NetworkTables server. Do you see “client connected” messages on the robot? Are you sure you have the table name / value name correct? A screenshot of what OutlineViewer is showing you would be helpful in debugging.

I cannot get to our laptop to take a screenshot at the moment, but I remember that OutlineViewer showed all of the contour information as well as the values being sent to the SmartDashboard. I am positive we have typed in all of the paths correctly. Where might we see this “client connected” message? In the riolog?

Correct, in riolog (or the driver station console if you turn on prints), you should see “NT: server: client CONNECTED: <ip> port <port>” printed for each NT client that has connected.

I just tried it, the correct message displayed in the riolog.

Ok, there’s no reason you shouldn’t be able to read the table then. Can you post or PM me a more complete snippet of your code?

This is our entire Robot.java class. NetworkTables related code is bolded.

package org.usfirst.frc.team4541.robot;

import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.SPI;

import com.kauailabs.navx.frc.AHRS;

import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.I2C.Port;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

public class Robot extends SampleRobot {
Joystick stick;
TankDrive drive;
CANTalon t1, t2, t3, t4, t5, t6, t7, t8, t9;
MotorManip m1, m2, m3, m4, m5;
Shooter shooter;
Intake intake;
Climber climber;

LIDAR lidar;
final String defaultAuto = "Default";
final String customAuto = "My Auto";
SendableChooser chooser;
AHRS gyro;

** NetworkTable table;**
CameraServer server;
**double targetWidthPx;
double targetDistanceIn;
double desiredX;
double targetOffsetIn;
double targetOffsetDegrees;
**// Port port = I2C.Port.kOnboard;

public Robot() {
   stick = new Joystick(0);
   t1 = new CANTalon(0);
   t2 = new CANTalon(1);
   t3 = new CANTalon(2);
   t4 = new CANTalon(3);
   t5 = new CANTalon(4);
   t6 = new CANTalon(5);
   t7 = new CANTalon(6);
   t8 = new CANTalon(7);
   t9 = new CANTalon(8);
   m1 = new MotorManip(t5);
   m2 = new MotorManip(t6);
   m3 = new MotorManip(t7);
   m4 = new MotorManip(t8);
   climber = new Climber(t9);
   drive = new TankDrive(t1,t2,t3,t4);
   shooter = new Shooter(m1, m2);
   intake = new Intake(m3, m4);

// lidar = new LIDAR(port);
gyro = new AHRS(SPI.Port.kMXP);
server = CameraServer.getInstance();
server.setQuality(50);
server.startAutomaticCapture(“cam0”);
}

public void robotInit() {
    chooser = new SendableChooser();
    chooser.addDefault("Default Auto", defaultAuto);
    chooser.addObject("My Auto", customAuto);
    SmartDashboard.putData("Auto modes", chooser);
   ** table = NetworkTable.getTable("GRIP/myContoursReport");**
}

public void autonomous() {

// String autoSelected = (String) chooser.getSelected();
// String autoSelected = SmartDashboard.getString(“Auto Selector”, defaultAuto);
// System.out.println("Auto selected: " + autoSelected);
//
// switch(autoSelected) {
// case customAuto:
// break;
// case defaultAuto:
// default:
// break;
// }
}

public void operatorControl() {
	gyro.reset();
	while (isOperatorControl() && isEnabled()) {

// lidar.begin(100, 0xff);
// lidar.start(100);
// SmartDashboard.putNumber(“Distance”, lidar.getDistance());
targetWidthPx = table.getNumber(“width”, 0);
targetDistanceIn = 3200/(2 * targetWidthPx * Math.tan(25));
desiredX = 0;
targetOffsetIn = (desiredX -table.getNumber(“centerX”, 0)) * 20/targetWidthPx;
targetOffsetDegrees = Math.tan(targetOffsetIn/targetDistanceIn);

SmartDashboard.putNumber(“angle”, gyro.getAngle());
SmartDashboard.putNumber(“output”, Math.abs(.0035*(90-gyro.getAngle())));
SmartDashboard.putNumber(“target width”, targetWidthPx);
SmartDashboard.putNumber(“target distance”, targetDistanceIn);
drive.arcadeDrive(drive.modStickIn(stick,1),drive.modStickIn(stick, 4));
if(stick.getRawButton(1)){
drive.rotateToAngle(90, gyro);
}
else if(stick.getRawButton(5)){
drive.speedUp();
}
else if(stick.getRawButton(6)){
drive.slowDown();
}
// else if(stick.getRawButton(2)){
// drive.rotateToAngle(targetOffsetDegrees, gyro);
// shooter.shoot(1,1);
// }
// else if(stick.getRawButton(4)){
// intake.pickUp(1);
// }
//
// else if(stick.getRawButton(5)){
// climber.extend(.5);
// }
//
// else if(stick.getRawButton(6)){
// climber.retract(.5);
// }

	}
}


public void test() {
}

}

Since you’re running it now, could you post a screenshot of what OutlineViewer is showing?

My guess is that the data type being put by GRIP is an array rather than a single number?

Edit: yes, looks like it is. See http://wpilib.screenstepslive.com/s/4485/m/50711/l/479908-reading-array-values-published-by-networktables

I had tried changing it to an array, but I can give it another shot. Here is the screenshot from OutlineViewer

outlineviewer.PNG


outlineviewer.PNG

Yep, those are definitely arrays (albeit 1-element ones).

So you should use getNumberArray() instead, check the size of the result, and get the 0th element.

I just tried it again using getNumberArray(); and it still only returns the default value.
Edit: Actually, it turns out that I forgot to recompile. I am getting the data now, thank you so much for all of your help.

This may be a long shot, but the “myContoursReport” name is entered into GRIP manually, correct? Any chance there’s a leading or trailing space in there by accident? (it wouldn’t show up in outline viewer since it’s whitespace)

You could also try adding a subtable listener on the “GRIP” table and/or a table listener on the “GRIP/myContoursReport” table and printing what it’s called with (see NetworkTable.addSubTableListener() and addTableListener() ).

Edit: nevermind, you got it… but this is another debug step for anyone else who might be having this issue.

I am having a similar problem, but I’m not even able to view the values in OutlineViewer. First of all, I’m not sure if I am supposed to use the server button or the client button (I tried it both ways without success). For the host address, I used the server address used in the GRIP settings, roborio-5102-frc.local. Is that the address that I’m supposed to use? or is there something I need to change in the GRIP settings? (I’m running GRIP on the driver station laptop)

The robot is always the server. The “server” mode of OutlineViewer is only for testing purposes when you don’t have robot code running, otherwise you should use the client mode.

Things to check:

  • Do you have robot code running? (e.g. the Driver Station is not showing “no robot code”)
  • Can you ping roborio-5102-frc.local from the command line?
  • Do you see a CONNECTED message in the console / riolog from your robot code?
  • Is GRIP reporting any NetworkTable errors in its console window?
  • Try running OutlineViewer.jar from the command prompt (it’s in C:\Users&lt;user>\wpilib ools). This will provide a place where error messages are reported.

Yes, it has robot code running, and the robot is connected. I will try the other things next time I have access to the robot. And what GRIP console window? Is that just if you run it from the command prompt? Do I have to run the GRIP program somehow, or does it just work in real time as you edit the filters? Do I need to somehow “deploy” the project to the laptop, or is that just if you are running it on the robot?

Ok, so I just tried it on my personal laptop, and it is working with the OutlineViewer in server mode, and the host set as localhost on both the server and GRIP. I don’t see how this is any different from how I was testing it on the robot, with the addresses both set at roborio-5102-frc.local, and OutlineViewer in client mode…

Correct, just run it from the command prompt. No need to deploy, you’re basically running the same executable you run when you click the GRIP icon when running GRIP normally, just from a command prompt instead.

That’s right, it shouldn’t be any different. Thus the questions about pinging, running from console window to see error messages, etc.

Ok, I’ll try these troubleshooting steps next time I am at robotics, and post the results.

I just tried it, and I’m not able to ping roborio-5102-frc.local from either the DS laptop or my personal laptop. The DS laptop has the firewall disabled, and the IP and DNS both set to auto. I even tried reprogramming the radio, but it still won’t work. Bonjour is running in the background too, so it shouldn’t be a problem with resolving the address. Are there any other troubleshooting steps that I can try for getting the mDNS to work?

What command would we run in the command promt to open grip and the project file that we want. Currently, when we set the .grip file to open as grip executable, the save does not open into the grip window and it is like it just opens grip.