Skip to content

Commit 2a04e12

Browse files
authored
[apriltag] AprilTagFieldLayout: Add accessors for origin and field dimensions (#5869)
1 parent 33e0089 commit 2a04e12

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ public List<AprilTag> getTags() {
113113
return new ArrayList<>(m_apriltags.values());
114114
}
115115

116+
/**
117+
* Returns the length of the field the layout is representing in meters.
118+
*
119+
* @return length, in meters
120+
*/
121+
@JsonIgnore
122+
public double getFieldLength() {
123+
return m_fieldDimensions.fieldLength;
124+
}
125+
126+
/**
127+
* Returns the length of the field the layout is representing in meters.
128+
*
129+
* @return width, in meters
130+
*/
131+
@JsonIgnore
132+
public double getFieldWidth() {
133+
return m_fieldDimensions.fieldWidth;
134+
}
135+
116136
/**
117137
* Sets the origin based on a predefined enumeration of coordinate frame origins. The origins are
118138
* calculated from the field dimensions.
@@ -152,6 +172,16 @@ public void setOrigin(Pose3d origin) {
152172
m_origin = origin;
153173
}
154174

175+
/**
176+
* Returns the origin used for tag pose transformation.
177+
*
178+
* @return the origin
179+
*/
180+
@JsonIgnore
181+
public Pose3d getOrigin() {
182+
return m_origin;
183+
}
184+
155185
/**
156186
* Gets an AprilTag pose by its ID.
157187
*

apriltag/src/main/native/cpp/AprilTagFieldLayout.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ AprilTagFieldLayout::AprilTagFieldLayout(std::vector<AprilTag> apriltags,
4141
}
4242
}
4343

44+
units::meter_t AprilTagFieldLayout::GetFieldLength() const {
45+
return m_fieldLength;
46+
}
47+
48+
units::meter_t AprilTagFieldLayout::GetFieldWidth() const {
49+
return m_fieldWidth;
50+
}
51+
4452
void AprilTagFieldLayout::SetOrigin(OriginPosition origin) {
4553
switch (origin) {
4654
case OriginPosition::kBlueAllianceWallRightSide:
@@ -59,6 +67,10 @@ void AprilTagFieldLayout::SetOrigin(const Pose3d& origin) {
5967
m_origin = origin;
6068
}
6169

70+
Pose3d AprilTagFieldLayout::GetOrigin() const {
71+
return m_origin;
72+
}
73+
6274
std::optional<frc::Pose3d> AprilTagFieldLayout::GetTagPose(int ID) const {
6375
const auto& it = m_apriltags.find(ID);
6476
if (it == m_apriltags.end()) {

apriltag/src/main/native/include/frc/apriltag/AprilTagFieldLayout.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ class WPILIB_DLLEXPORT AprilTagFieldLayout {
6262
AprilTagFieldLayout(std::vector<AprilTag> apriltags,
6363
units::meter_t fieldLength, units::meter_t fieldWidth);
6464

65+
/**
66+
* Returns the length of the field the layout is representing.
67+
* @return length
68+
*/
69+
units::meter_t GetFieldLength() const;
70+
71+
/**
72+
* Returns the length of the field the layout is representing.
73+
* @return width
74+
*/
75+
units::meter_t GetFieldWidth() const;
76+
6577
/**
6678
* Sets the origin based on a predefined enumeration of coordinate frame
6779
* origins. The origins are calculated from the field dimensions.
@@ -83,6 +95,12 @@ class WPILIB_DLLEXPORT AprilTagFieldLayout {
8395
*/
8496
void SetOrigin(const Pose3d& origin);
8597

98+
/**
99+
* Returns the origin used for tag pose transformation.
100+
* @return the origin
101+
*/
102+
Pose3d GetOrigin() const;
103+
86104
/**
87105
* Gets an AprilTag pose by its ID.
88106
*

0 commit comments

Comments
 (0)