Using GRIP's generated code for vision tracking

I’ve been following these screen steps for using GRIP for vision tracking and have come across a problem which I’m not too sure how to fix. When I go to type,

visionThread = new VisionThread(camera, new MyGripPipeline(), pipeline -> {
    if (!pipeline.filterContoursOutput().isEmpty()) {
        Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
        synchronized (imgLock) {
            centerX = r.x + (r.width / 2);
        }
    }
});
visionThread.start();
    
drive = new RobotDrive(1, 2);

This portion,

new VisionThread(camera, new MyGripPipeline(), pipeline → {
if (!pipeline.filterContoursOutput().isEmpty()) {
Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
synchronized (imgLock) {
centerX = r.x + (r.width / 2);
}
}
});

becomes underlined and tells me that the constructor VisionThread is undefined.
I’m not sure what I’m doing wrong.

Any help is much appreciated,
Alex

1 Like

We are having the exact same issue and would really appreciate some help from anyone who can offer some.

Could it possibly be you have an older version of Java installed? Lambda expressions came in Java 8 so anything before that won’t support them.

If that’s not the issue, double check the parameters from the VisionThread constructor and make sure you’re at least passing the correct types (Don’t believe this should throw an undefined error but always good to check).

Lastly, you may need to import vision libraries. I haven’t used GRIP but I believe it should add the required imports to the top of the code export. If not, read up as to what libraries GRIP makes use of and import the appropriate ones.

Currently I have Java 11 installed.

The code is copied almost directly from wpilib, so I should be using the correct parameters for the constructor as far as I can tell, and I believe I have all the required vision libraries. Here is my code:

package frc.robot;

import frc.robot.GripPipeline;

import org.opencv.core.Rect;
import org.opencv.imgproc.Imgproc;

import edu.wpi.cscore.AxisCamera;
import edu.wpi.cscore.UsbCamera;
import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.vision.VisionRunner;
import edu.wpi.first.vision.VisionThread;

public class Robot extends TimedRobot {

private static final int IMG_WIDTH = 320;
private static final int IMG_HEIGHT = 240;

private VisionThread visionThread;
private double centerX = 0.0;

private final Object imgLock = new Object();

@Override
public void robotInit() {
AxisCamera camera = CameraServer.getInstance().addAxisCamera(“AxisCamera0”, “10.29.96.11”);
camera.setResolution(IMG_WIDTH, IMG_HEIGHT);

  visionThread = new VisionThread(camera, new GripPipeline(), pipeline -> {
      if (!pipeline.filterContoursOutput().isEmpty()) {
          Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
          synchronized (imgLock) {
              centerX = r.x + (r.width / 2);
          }
      }
  });
  visionThread.start();

}

@Override
public void autonomousPeriodic() {
}
}

So I solved it, the GripPipeline class needs to implement VisionPipline

Blockquote
public class GripPipeline implements VisionPipeline{

The Class header for the auto-generated GripPipline class, add implements VisionPipline

Or check the “implement WPILib vision pipeline” checkbox when generating code

I did not see that box, thanks for the suggestion

What is the pipeline variable in the new VisionThread?