|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need NetworkTables to update??(Grip)
How do I get the NetworkTables to update when the camera is plugged into the roboRio? (Grip related issue)
When the camera USB is plugged into the computer our networkTables update fine, and the GripPipeline code that Grip generated works fine, but we cannot get grip to publish networkTables that update when the camera is connected to the robot. |
|
#2
|
||||
|
||||
|
Re: Need NetworkTables to update??(Grip)
GRIP only generates the vision processing code. You have to write the NetworkTables part.
If you take a look at this screensteps page, you can publish to NetworkTables inside the callback in the second code block. Something like Code:
visionThread = new VisionThread(camera, new Pipeline(), pipeline -> {
...
centerX = ...
centerY = ...
NetworkTables.getTable("vision").putNumber("centerX", centerX);
NetworkTables.getTable("vision").putNumber("centerY", centerY);
});
|
|
#3
|
|||
|
|||
|
Re: Need NetworkTables to update??(Grip)
yes i have code similar to i, but it still won't work ._.
visionThread = new VisionThread(camera, new GripPipeline(), pipeline -> { if (!pipeline.filterContoursOutput().isEmpty()) { System.out.println(pipeline.filterContoursOutput() .get(0)); //SmartDashboard.putNumber("opencv",pipeline.filterC ontoursOutput().get(0)); table = NetworkTable.getTable("GRIP/marly"); double[] def = new double[0]; double[] areas = table.getNumberArray("width", def); System.out.println(areas[0]); } }); visionThread.start(); |
|
#4
|
||||
|
||||
|
Re: Need NetworkTables to update??(Grip)
You're doing vision processing, but not using the results. You need to be putting values into the table.
|
|
#5
|
|||
|
|||
|
Re: Need NetworkTables to update??(Grip)
Quote:
if (!pipeline.filterContoursOutput().isEmpty()) { Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput ().get(0)); SmartDashboard.putString("opencv", "at (" + r.x + ',' + r.y + ')' ); |
|
#6
|
|||
|
|||
|
Re: Need NetworkTables to update??(Grip)
Quote:
We have been able to get the Rect values to display on the SmartDashboard, but they don't seem to be updating. We noticed that the process() method in the pipeline is what actually updates the values, but the example code doesn't seem to use it. (We are able to see new values each time we restart the SmartDashboard!, but not updating). We tried calling the process() method inside of the while loop of our init method. We attempted to grab a picture and pass in as the Mat parameter, but there were no rectangles being seen (even though we have been consistently seeing rectangles in the Grip software). I'm stuck again on trying to figure out how to get the rectangles to update in real time. Any help would be greatly appreciated! This is our camInit() method: Code:
public void camInit() {
// NetworkTable.setIPAddress("10.16.60.63");
// table = NetworkTable.getTable("marly");
/* Creates UsbCamera and MjpegServer [1] and connects them */
UsbCamera camera = CameraServer.getInstance().startAutomaticCapture();
/* Creates the CvSource and MjpegServer [2] and connects them */
CvSource outputStream = CameraServer.getInstance().putVideo("steamVideo", 640, 480);
/* Creates the CvSink and connects it to the UsbCamera */
CvSink cvSink = CameraServer.getInstance().getVideo();
Mat mat = new Mat();
Mat outputMat = new Mat();
// camera.
VisionThread visionThread = new VisionThread(camera, new GripPipeline(), pipeline -> {
while (camRunning) {
ArrayList<MatOfPoint> amat = pipeline.filterContoursOutput();
int tempNumRectangles = amat.size();
Rect tempR0 = r0; //keep old value if you don't see it?
System.out.println(" tempNumRectangles "+ tempNumRectangles);
if (tempNumRectangles > 0){ //!pipeline.filterContoursOutput().isEmpty()) {
tempR0 = Imgproc.boundingRect(amat.get(0));
Rect tempR1 = r1; //keep old value if you don't see it?
if (tempNumRectangles > 1) {
tempR1 = Imgproc.boundingRect(amat.get(1));
}
synchronized(camLock){
System.out.println(" here");
r0 = tempR0;
r1 = tempR1;
numRectangles = tempNumRectangles;
}
}
// System.out.print ("r0.x: " +r0.x + " r0.y: " +r0.y+ " r0.height: " + r0.height + " r0.width: "+r0.width);
SmartDashboard.putNumber("rect0.x", r0.x);
SmartDashboard.putNumber("rect0.y", r0.y);
SmartDashboard.putNumber("rect0.height", r0.height);
SmartDashboard.putNumber("rect0.width", r0.width);
// System.out.print ("r1.x: " +r1.x + " r1.y: " +r1.y+ " r1.height: " + r1.height + " r1.width: "+r1.width);
SmartDashboard.putNumber("rect1.x", r1.x);
SmartDashboard.putNumber("rect1.y", r1.y);
SmartDashboard.putNumber("rect1.height", r1.height);
SmartDashboard.putNumber("rect1.width", r1.width);
// System.out.println("\t rect count = " + numRectangles);
SmartDashboard.putNumber("rect count", tempNumRectangles);
try {
Thread.sleep(100);
} catch(InterruptedException e){
camRunning = false;
System.out.println("Thread sleep exception");
}
if (cvSink.grabFrame(mat) == 0)
{
System.out.println("not working****");
outputStream.notifyError(cvSink.getError());
continue;
}
//System.out.println("working!!");
pipeline.process(mat);
//cvSink.grabFrame(mat);
//Imgproc.cvtColor(mat, outputMat, Imgproc.COLOR_BGR2GRAY);
//outputStream.putFrame(outputMat);
//System.out.println(mat.toString());
}
});
visionThread.start();
}
|
|
#7
|
||||
|
||||
|
Re: Need NetworkTables to update??(Grip)
Code:
while (camRunning) {
So why did you decide to add a loop? I'd like to improve the documentation so that it's clearer that this is not the right way to do this. The Javadoc for VisionRunner.Listener, which is what that lambda is |
|
#8
|
||||
|
||||
|
Re: Need NetworkTables to update??(Grip)
Sam,
I think what has been throwing us for a loop hasn't really been so much a GRIP problem (generating java code from GRIP has made this part very elegant), but a steep learning curve for more advanced Java syntax.There is a fundamental need for the vision code to loop, and really understanding how this is done can feel like hiking through a jungle:
The while loop that we, and perhaps others, needed was really in the runForever() method of the VisionRunner class, but that's not a simple find unless you are already familiar with the previous concepts. Throw on top of that:
Our school recently began offering APCS A for students, which has been very helpful for robotics team students who program our robot, but a lot of these topics are not in the scope of the AP exam and are things we'll need to figure out how to integrate into our learning pipeline. The GRIP/vision screensteps have been much improved this year, and very helpful, and we are especially appreciative of the time you have put into ChiefDelphi forums to help us and others out with GRIP-related questions. I, personally, am very excited about how GRIP and the openCV-based libraries can help make vision-processing a reality for a larger number of FRC teams going forward. Perhaps in the future, there is an opportunity to add some additional screensteps (or point to good tutorial resources) that address some of the topics I mentioned above. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|