Skip to content

Commit

Permalink
AprilTagFieldLayout: Add accessors for origin and field dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Nov 4, 2023
1 parent 049732a commit b6b7783
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ public List<AprilTag> getTags() {
return new ArrayList<>(m_apriltags.values());
}

/**
* Returns the length of the field the layout is representing in meters.
*
* @return length, in meters
*/
@JsonIgnore
public double getFieldLength() {
return m_fieldDimensions.fieldLength;
}

/**
* Returns the length of the field the layout is representing in meters.
*
* @return width, in meters
*/
@JsonIgnore
public double getFieldWidth() {
return m_fieldDimensions.fieldWidth;
}

/**
* Sets the origin based on a predefined enumeration of coordinate frame origins. The origins are
* calculated from the field dimensions.
Expand Down Expand Up @@ -152,6 +172,16 @@ public void setOrigin(Pose3d origin) {
m_origin = origin;
}

/**
* Returns the origin used for tag pose transformation.
*
* @return the origin
*/
@JsonIgnore
public Pose3d getOrigin() {
return m_origin;
}

/**
* Gets an AprilTag pose by its ID.
*
Expand Down
12 changes: 12 additions & 0 deletions apriltag/src/main/native/cpp/AprilTagFieldLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ AprilTagFieldLayout::AprilTagFieldLayout(std::vector<AprilTag> apriltags,
}
}

units::meter_t AprilTagFieldLayout::GetFieldLength() const {
return m_fieldLength;
}

units::meter_t AprilTagFieldLayout::GetFieldWidth() const {
return m_fieldWidth;
}

void AprilTagFieldLayout::SetOrigin(OriginPosition origin) {
switch (origin) {
case OriginPosition::kBlueAllianceWallRightSide:
Expand All @@ -59,6 +67,10 @@ void AprilTagFieldLayout::SetOrigin(const Pose3d& origin) {
m_origin = origin;
}

Pose3d AprilTagFieldLayout::GetOrigin() const {
return m_origin;
}

std::optional<frc::Pose3d> AprilTagFieldLayout::GetTagPose(int ID) const {
const auto& it = m_apriltags.find(ID);
if (it == m_apriltags.end()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ class WPILIB_DLLEXPORT AprilTagFieldLayout {
AprilTagFieldLayout(std::vector<AprilTag> apriltags,
units::meter_t fieldLength, units::meter_t fieldWidth);

/**
* Returns the length of the field the layout is representing.
* @return length
*/
units::meter_t GetFieldLength() const;

/**
* Returns the length of the field the layout is representing.
* @return width
*/
units::meter_t GetFieldWidth() const;

/**
* Sets the origin based on a predefined enumeration of coordinate frame
* origins. The origins are calculated from the field dimensions.
Expand All @@ -83,6 +95,12 @@ class WPILIB_DLLEXPORT AprilTagFieldLayout {
*/
void SetOrigin(const Pose3d& origin);

/**
* Returns the origin used for tag pose transformation.
* @return the origin
*/
Pose3d GetOrigin() const;

/**
* Gets an AprilTag pose by its ID.
*
Expand Down

0 comments on commit b6b7783

Please sign in to comment.