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@SuppressWarnings("MemberName")
015public class AprilTag {
016  @JsonProperty(value = "ID")
017  public int ID;
018
019  @JsonProperty(value = "pose")
020  public Pose3d pose;
021
022  @SuppressWarnings("ParameterName")
023  @JsonCreator
024  public AprilTag(
025      @JsonProperty(required = true, value = "ID") int ID,
026      @JsonProperty(required = true, value = "pose") Pose3d pose) {
027    this.ID = ID;
028    this.pose = pose;
029  }
030
031  @Override
032  public boolean equals(Object obj) {
033    if (obj instanceof AprilTag) {
034      var other = (AprilTag) obj;
035      return ID == other.ID && pose.equals(other.pose);
036    }
037    return false;
038  }
039
040  @Override
041  public int hashCode() {
042    return Objects.hash(ID, pose);
043  }
044
045  @Override
046  public String toString() {
047    return "AprilTag(ID: " + ID + ", pose: " + pose + ")";
048  }
049
050  /**
051   * Generates a RawFrame containing the apriltag with the id with family 16h5 passed in.
052   *
053   * @param id id
054   * @return A RawFrame containing the AprilTag image
055   */
056  public static RawFrame generate16h5AprilTagImage(int id) {
057    RawFrame generatedImage = new RawFrame();
058    AprilTagJNI.generate16h5AprilTagImage(id, generatedImage.getDataPtr());
059    return generatedImage;
060  }
061
062  /**
063   * Generates a RawFrame containing the apriltag with the id with family 36h11 passed in.
064   *
065   * @param id id
066   * @return A RawFrame containing the AprilTag image
067   */
068  public static RawFrame generate36h11AprilTagImage(int id) {
069    RawFrame generatedImage = new RawFrame();
070    AprilTagJNI.generate36h11AprilTagImage(id, generatedImage.getDataPtr());
071    return generatedImage;
072  }
073}