001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.apriltag; 006 007import com.fasterxml.jackson.annotation.JsonCreator; 008import com.fasterxml.jackson.annotation.JsonProperty; 009import edu.wpi.first.apriltag.jni.AprilTagJNI; 010import edu.wpi.first.math.geometry.Pose3d; 011import edu.wpi.first.util.RawFrame; 012import java.util.Objects; 013 014/** Represents an AprilTag's metadata. */ 015@SuppressWarnings("MemberName") 016public class AprilTag { 017 /** The tag's ID. */ 018 @JsonProperty(value = "ID") 019 public int ID; 020 021 /** The tag's pose. */ 022 @JsonProperty(value = "pose") 023 public Pose3d pose; 024 025 /** 026 * Constructs an AprilTag. 027 * 028 * @param ID The tag's ID. 029 * @param pose The tag's pose. 030 */ 031 @SuppressWarnings("ParameterName") 032 @JsonCreator 033 public AprilTag( 034 @JsonProperty(required = true, value = "ID") int ID, 035 @JsonProperty(required = true, value = "pose") Pose3d pose) { 036 this.ID = ID; 037 this.pose = pose; 038 } 039 040 @Override 041 public boolean equals(Object obj) { 042 return obj instanceof AprilTag tag && ID == tag.ID && pose.equals(tag.pose); 043 } 044 045 @Override 046 public int hashCode() { 047 return Objects.hash(ID, pose); 048 } 049 050 @Override 051 public String toString() { 052 return "AprilTag(ID: " + ID + ", pose: " + pose + ")"; 053 } 054 055 /** 056 * Generates a RawFrame containing the apriltag with the id with family 16h5 passed in. 057 * 058 * @param id id 059 * @return A RawFrame containing the AprilTag image 060 */ 061 public static RawFrame generate16h5AprilTagImage(int id) { 062 RawFrame frame = new RawFrame(); 063 AprilTagJNI.generate16h5AprilTagImage(frame, frame.getNativeObj(), id); 064 return frame; 065 } 066 067 /** 068 * Generates a RawFrame containing the apriltag with the id with family 36h11 passed in. 069 * 070 * @param id id 071 * @return A RawFrame containing the AprilTag image 072 */ 073 public static RawFrame generate36h11AprilTagImage(int id) { 074 RawFrame frame = new RawFrame(); 075 AprilTagJNI.generate36h11AprilTagImage(frame, frame.getNativeObj(), id); 076 return frame; 077 } 078}