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 if (obj instanceof AprilTag) { 043 var other = (AprilTag) obj; 044 return ID == other.ID && pose.equals(other.pose); 045 } 046 return false; 047 } 048 049 @Override 050 public int hashCode() { 051 return Objects.hash(ID, pose); 052 } 053 054 @Override 055 public String toString() { 056 return "AprilTag(ID: " + ID + ", pose: " + pose + ")"; 057 } 058 059 /** 060 * Generates a RawFrame containing the apriltag with the id with family 16h5 passed in. 061 * 062 * @param id id 063 * @return A RawFrame containing the AprilTag image 064 */ 065 public static RawFrame generate16h5AprilTagImage(int id) { 066 RawFrame frame = new RawFrame(); 067 AprilTagJNI.generate16h5AprilTagImage(frame, frame.getNativeObj(), id); 068 return frame; 069 } 070 071 /** 072 * Generates a RawFrame containing the apriltag with the id with family 36h11 passed in. 073 * 074 * @param id id 075 * @return A RawFrame containing the AprilTag image 076 */ 077 public static RawFrame generate36h11AprilTagImage(int id) { 078 RawFrame frame = new RawFrame(); 079 AprilTagJNI.generate36h11AprilTagImage(frame, frame.getNativeObj(), id); 080 return frame; 081 } 082}