AlphaBit OpenML
2026
Documentation
AprilTag Implementation - Code Samples
Implementation Template
Use this page while coding. It shows the exact order most teams should follow: build camera class, connect autonomous pattern logic, then add pose correction safely.
Step 1
Create a Dedicated Vision Class
Keep camera logic isolated so OpModes stay readable:
public class AprilTagIdentification {
    AprilTagProcessor aprilTagProcessor;
    VisionPortal visionPortal;
    public int detectionId = 0;
    public double robotPose_x = 0.0;
    public double robotPose_y = 0.0;
    public double bearingAngle = 0.0;
    public boolean locTagFound = false;

    public void init(HardwareMap hwdmap, MultipleTelemetry telemetrys) {
        // build processor and portal here
    }
}
Step 2
Wire Pattern IDs Into Autonomous Init
Use tags in init to decide your route before match starts:
if (!nearBasket) {
    currentId = artifactControl.getCurrentTag();
    if (currentId != 0) {
        switch (currentId) {
            case 21: currentPattern = ObeliskPattern.GPP; break;
            case 22: currentPattern = ObeliskPattern.PGP; break;
            case 23: currentPattern = ObeliskPattern.PPG; break;
        }
        patternFound = true;
    }
}
Step 3
Add Pose Refresh Gate in Control Layer
In ArtifactControl, read tag pose only in trusted windows:
if (aprilTagIdentification.locTagFound) {
    calculatedRobotPose_X = aprilTagIdentification.robotPose_x;
    calculatedRobotPose_Y = aprilTagIdentification.robotPose_y;
    robotAngleAprilTag = aprilTagIdentification.bearingAngle;

    gyroscope.resetHeading();
    gyroscope.setAngleOffset(36.5 - robotAngleAprilTag);
    drive.setPose(new Pose(
        calculatedRobotPose_X,
        calculatedRobotPose_Y,
        Math.toRadians(126.5 - robotAngleAprilTag)
    ));
}
Add your own stationary and area checks around this block before using it in matches.
Step 4
Add Validation Telemetry
Always expose tag and pose information while tuning:
telemetrys.addData("[Artifact] AprilTag Robot Pose X", artifactControl.calculatedRobotPose_X);
telemetrys.addData("[Artifact] AprilTag Robot Pose Y", artifactControl.calculatedRobotPose_Y);
telemetrys.addData("[Artifact] AprilTag Robot Angle", artifactControl.robotAngleAprilTag);
telemetrys.addData("[->] Pattern", artifactControl.artifactPattern);
Checklist
  • Tag IDs split correctly (pattern vs localization).
  • Telemetry confirms stable X/Y/bearing when parked.
  • No pose hard-reset during rapid acceleration.
  • Next
    Continue to Autonomous Control - Getting Started to connect this vision layer with route execution.
    Setup
    AprilTag Detection

    AprilTag Implementation

    Autonomous Control
    Auto Aiming Turret
    Need help with OpenML? Ask the AlphaBit assistant

    AlphaBit AI Assistant

    Hi! I can help with model setup, training data, and robotics ML workflow questions.