UGBasicHighGoalPipeline
Để sử dụng pipeline, bạn chỉ cần gọi constructor và cho camera chạy pipeline đó.
Hãy đảm bảo rằng bạn vẫn có thể truy cập được object pipeline mà bạn đã truyền vào camera.
Tham khảo tài liệu của Easy OpenCV về cách sử dụng pipeline với thiết bị camera của bạn, cho dù đó là camera điện thoại hay webcam ngoài.
Ví dụ, việc tạo pipeline có thể được thực hiện như sau:
UGBasicHighGoalPipeline pipeline = new UGBasicHighGoalPipeline();
camera.setPipeline(pipeline);
Sau khi pipeline đã được thiết lập, trong chương trình của bạn, bạn có thể bắt đầu gọi các phương thức trong pipeline.
Một cách sử dụng pipeline rất đơn giản trong chương trình của bạn được minh họa bên dưới:
if (pipeline.isRedVisible()) {
Rect redRect = pipeline.getRedRect();
Point centerOfRedGoal = pipeline.getCenterofRect(redRect);
telemetry.addData("Red goal position",
centerOfRedGoal.toString());
}
if (pipeline.isBlueVisible()) {
Rect blueRect = pipeline.getBlueRect();
Point centerOfBlueGoal = pipeline.getCenterofRect(blueRect);
telemetry.addData("Blue goal position",
centerOfBlueGoal.toString());
}
if (pipeline.isRedVisible()) {
Rect redRect = pipeline.getRedRect();
Point centerOfRedGoal = pipeline.getCenterofRect(redRect);
telemetry.addData("Red goal position",
centerOfRedGoal.toString());
}
if (pipeline.isBlueVisible()) {
Rect blueRect = pipeline.getBlueRect();
Point centerOfBlueGoal = pipeline.getCenterofRect(blueRect);
telemetry.addData("Blue goal position",
centerOfBlueGoal.toString());
}Sử dụng các phương thức được cung cấp này, bạn có thể dùng điểm (Point) để căn chỉnh robot thẳng hàng với goal, như trong ví dụ sau:
double xDist = Math.abs(centerOfCamera.x - centerOfBlueGoal.x);
double yDist = Math.abs(centerOfCamera.y - centerOfBlueGoal.y);
double dist = Math.hypot(xDist, yDist);
while (true) {
if (centerOfCamera.x < centerOfBlueGoal.x - TOLERANCE) {
turn(dist);
} else if (centerOfCamera.x > centerOfBlueGoal.x + TOLERANCE) {
turn(-dist);
} else {
turn(0);
break;
}
}
double xDist = Math.abs(centerOfCamera.x - centerOfBlueGoal.x);
double yDist = Math.abs(centerOfCamera.y - centerOfBlueGoal.y);
double dist = Math.hypot(xDist, yDist);
while (true) {
if (centerOfCamera.x < centerOfBlueGoal.x - TOLERANCE) {
turn(dist);
} else if (centerOfCamera.x > centerOfBlueGoal.x + TOLERANCE) {
turn(-dist);
} else {
turn(0);
break;
}
}Đây là một cách rất cơ bản và thô sơ để tận dụng pipeline.
UGAngleHighGoalPipeline
Tiếp theo là một pipeline nâng cao hơn, đó là angle pipeline.
Công dụng của nó giống với pipeline cơ bản đã nói ở trên. Tuy nhiên, pipeline này còn cho phép bạn tính toán yaw và pitch của goal so với camera.
Dưới đây là một ví dụ rất đơn giản về cách sử dụng pipeline này:
while (!angleController.atSetPoint()) {
double angle = pipeline.calculateYaw(Target.RED);
double output = angleController.calculate(-angle, 0);
turn(output);
}
turn(0);turn(0)
while (!angleController.atSetPoint()) {
double angle = pipeline.calculateYaw(Target.RED);
double output = angleController.calculate(-angle, 0);
turn(output);
}
turn(0);turn(0)