![]() |
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. |
Re: GRIP and NetworkTables settings for use with a co-processor
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.
|
Re: GRIP and NetworkTables settings for use with a co-processor
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?
|
Re: GRIP and NetworkTables settings for use with a co-processor
Quote:
|
Re: GRIP and NetworkTables settings for use with a co-processor
I just tried it, the correct message displayed in the riolog.
|
Re: GRIP and NetworkTables settings for use with a co-processor
Quote:
|
Re: GRIP and NetworkTables settings for use with a co-processor
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.SendableChoos er; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboar d; 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() { } } |
Re: GRIP and NetworkTables settings for use with a co-processor
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/...-networktables |
Re: GRIP and NetworkTables settings for use with a co-processor
1 Attachment(s)
I had tried changing it to an array, but I can give it another shot. Here is the screenshot from OutlineViewer
|
Re: GRIP and NetworkTables settings for use with a co-processor
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. |
Re: GRIP and NetworkTables settings for use with a co-processor
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. |
Re: GRIP and NetworkTables settings for use with a co-processor
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. |
Re: GRIP and NetworkTables settings for use with a co-processor
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)
|
Re: GRIP and NetworkTables settings for use with a co-processor
Quote:
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\<user>\wpilib\tools). This will provide a place where error messages are reported. |
Re: GRIP and NetworkTables settings for use with a co-processor
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?
|
| All times are GMT -5. The time now is 06:54. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi