Hello all,
I’ve tried to use vision multiple times before, but to no avail. What I’m trying to do is make our robot adjust itself so that it is in line with retro reflective tape using java and Grip. I have already created the GRIP file to identify the retro reflective tape as a contour and added the GRIP file to my java project in VSCode.
Here is what I have already.
m_robotContainer = new RobotContainer();
leftFront = new VictorSP(0);
leftBack = new VictorSP(2);
rightFront = new VictorSP(1);
rightBack = new VictorSP(3);
leftGroup = new SpeedControllerGroup(leftFront, leftBack);
rightGroup = new SpeedControllerGroup(rightFront, rightBack);
drive = new DifferentialDrive(leftGroup, rightGroup);
UsbCamera camera = CameraServer.getInstance().startAutomaticCapture();
camera.setResolution(IMG_WIDTH, IMG_HEIGHT);
thread = 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);
// System.out.println(r.width);
}
}
});
thread.start();
Then, in autonomous I have:
double centerX;
synchronized (imgLock) {
centerX = this.centerX;
}
double turn = centerX - (IMG_WIDTH / 2);
drive.arcadeDrive(.2, turn * 0.005);
Help?