Phát hin High Goal

Phát hin High Goal

Cách nhận diện high goal để hỗ trợ robot bắn chính xác hơn.

Cách nhận diện high goal để hỗ trợ robot bắn chính xác hơn.

Level

Advanced

Source

Source

Author

Author

FTC Lib

FTC Lib

Translator

Translator

FTC26749 aDudu

FTC26749 aDudu

Date Published

Date Published

Jan 18, 2026

Jan 18, 2026

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:

// Red Goal
if (pipeline.isRedVisible()) {
    Rect redRect = pipeline.getRedRect();
    Point centerOfRedGoal = pipeline.getCenterofRect(redRect);
    
    telemetry.addData("Red goal position",
                        centerOfRedGoal.toString());
}
// Blue Goal
if (pipeline.isBlueVisible()) {
    Rect blueRect = pipeline.getBlueRect();
    Point centerOfBlueGoal = pipeline.getCenterofRect(blueRect);
    
    telemetry.addData("Blue goal position",
                        centerOfBlueGoal.toString());
}
// Red Goal
if (pipeline.isRedVisible()) {
    Rect redRect = pipeline.getRedRect();
    Point centerOfRedGoal = pipeline.getCenterofRect(redRect);
    
    telemetry.addData("Red goal position",
                        centerOfRedGoal.toString());
}
// Blue Goal
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:

// say we have a point called 'centerOfCamera'
double xDist = Math.abs(centerOfCamera.x - centerOfBlueGoal.x);
double yDist = Math.abs(centerOfCamera.y - centerOfBlueGoal.y);
double dist = Math.hypot(xDist, yDist);
// assume we have a method that turns the robot at some speed,
// but clamps it to [-1, 1]
while (true) {
    if (centerOfCamera.x < centerOfBlueGoal.x - TOLERANCE) {
        turn(dist);    // turning right is positive input
    } else if (centerOfCamera.x > centerOfBlueGoal.x + TOLERANCE) {
        turn(-dist);
    } else {
        turn(0);
        break;
    }
}
// say we have a point called 'centerOfCamera'
double xDist = Math.abs(centerOfCamera.x - centerOfBlueGoal.x);
double yDist = Math.abs(centerOfCamera.y - centerOfBlueGoal.y);
double dist = Math.hypot(xDist, yDist);
// assume we have a method that turns the robot at some speed,
// but clamps it to [-1, 1]
while (true) {
    if (centerOfCamera.x < centerOfBlueGoal.x - TOLERANCE) {
        turn(dist);    // turning right is positive input
    } 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:

// assume we have a PID controller called 'angleController'
while (!angleController.atSetPoint()) {
    double angle = pipeline.calculateYaw(Target.RED);
    double output = angleController.calculate(-angle, 0);
    
    turn(output);
}
turn(0);turn(0)
// assume we have a PID controller called 'angleController'
while (!angleController.atSetPoint()) {
    double angle = pipeline.calculateYaw(Target.RED);
    double output = angleController.calculate(-angle, 0);
    
    turn(output);
}
turn(0);turn(0)

ADUDU

A proud team of passionate Robotics Enthusiasts competing in nation-wide Technology competitions in Vietnam, the FIRST Tech Challenge and the FIRST Robotics Competition.

Copyright ©

, all rights reserved

Made by aDudu's Programming Department

made by aDudu

made by aDudu

Phát hiện High Goal