Repository navigation
Expand file tree
/
Copy pathFieldConstants.java
More file actions
219 lines (188 loc) · 7.92 KB
/
Copy pathFieldConstants.java
File metadata and controls
219 lines (188 loc) · 7.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package frc.robot.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.wpi.first.apriltag.AprilTagFieldLayout;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.geometry.Translation3d;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.Filesystem;
import java.io.IOException;
import java.nio.file.Path;
// Copyright (c) 2025-2026 Littleton Robotics
// http://github.com/Mechanical-Advantage
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file at
// the root directory of this project.
/**
* Contains information for location of field element and other useful reference points.
*
* <p>NOTE: All constants are defined relative to the field coordinate system, and from the
* perspective of the blue alliance station
*/
public class FieldConstants {
public static final AprilTagFieldLayout APRIL_TAG_LAYOUT =
AprilTagLayoutType.OFFICIAL.getLayout();
public static final FieldType fieldType = FieldType.WELDED;
// AprilTag related constants
public static final int aprilTagCount = AprilTagLayoutType.OFFICIAL.getLayout().getTags().size();
public static final double aprilTagWidth = Units.inchesToMeters(6.5);
public static final AprilTagLayoutType defaultAprilTagType = AprilTagLayoutType.OFFICIAL;
// Field dimensions
public static final double fieldLength = 16.541;
public static final double fieldWidth = 8.069;
/**
* Officially defined and relevant vertical lines found on the field (defined by X-axis offset)
*/
public static class LinesVertical {
public static final double center = fieldLength / 2.0;
}
/**
* Officially defined and relevant horizontal lines found on the field (defined by Y-axis offset)
*
* <p>NOTE: The field element start and end are always left to right from the perspective of the
* alliance station
*/
public static class LinesHorizontal {
public static final double center = fieldWidth / 2.0;
}
public static class Bump {
public static final double LEFT_BUMP_CENTER = fieldWidth - 2.518918;
public static final double RIGHT_BUMP_CENTER = 2.518918;
public static final double FRONT_BUMP_EDGE = 5.729224;
public static final double BUMP_CENTER_X = 4.612;
}
/** Hub related constants */
public static class Hub {
// Dimensions
public static final double width = Units.inchesToMeters(47.0);
public static final double height =
Units.inchesToMeters(72.0); // includes the catcher at the top
public static final double innerWidth = Units.inchesToMeters(41.7);
public static final double innerHeight = Units.inchesToMeters(56.5);
// Relevant reference points on alliance side
public static final Translation3d topCenterPoint =
new Translation3d(4.0218614 + width / 2.0, 8.069 / 2.0, height);
// public static final Translation3d innerCenterPoint =
// new Translation3d(
// AprilTagLayoutType.OFFICIAL.getLayout().getTagPose(26).get().getX() + width / 2.0,
// fieldWidth / 2.0,
// innerHeight);
}
/** Tower related constants */
public static class Tower {
// Dimensions
public static final double width = Units.inchesToMeters(49.25);
public static final double depth = Units.inchesToMeters(45.0);
public static final double height = Units.inchesToMeters(78.25);
public static final double innerOpeningWidth = Units.inchesToMeters(32.250);
public static final double frontFaceX = Units.inchesToMeters(43.51);
public static final double uprightHeight = Units.inchesToMeters(72.1);
// Rung heights from the floor
public static final double lowRungHeight = Units.inchesToMeters(27.0);
public static final double midRungHeight = Units.inchesToMeters(45.0);
public static final double highRungHeight = Units.inchesToMeters(63.0);
// Relevant reference points on alliance side
public static final Translation2d centerPoint =
new Translation2d(
frontFaceX, AprilTagLayoutType.OFFICIAL.getLayout().getTagPose(31).get().getY());
public static final Translation2d leftUpright =
new Translation2d(
frontFaceX,
(AprilTagLayoutType.OFFICIAL.getLayout().getTagPose(31).get().getY())
+ innerOpeningWidth / 2
+ Units.inchesToMeters(0.75));
public static final Translation2d rightUpright =
new Translation2d(
frontFaceX,
(AprilTagLayoutType.OFFICIAL.getLayout().getTagPose(31).get().getY())
- innerOpeningWidth / 2
- Units.inchesToMeters(0.75));
// Relevant reference points on opposing side
public static final Translation2d oppCenterPoint =
new Translation2d(
fieldLength - frontFaceX,
AprilTagLayoutType.OFFICIAL.getLayout().getTagPose(15).get().getY());
public static final Translation2d oppLeftUpright =
new Translation2d(
fieldLength - frontFaceX,
(AprilTagLayoutType.OFFICIAL.getLayout().getTagPose(15).get().getY())
+ innerOpeningWidth / 2
+ Units.inchesToMeters(0.75));
public static final Translation2d oppRightUpright =
new Translation2d(
fieldLength - frontFaceX,
(AprilTagLayoutType.OFFICIAL.getLayout().getTagPose(15).get().getY())
- innerOpeningWidth / 2
- Units.inchesToMeters(0.75));
}
public static class Depot {
// Dimensions
public static final double width = Units.inchesToMeters(42.0);
public static final double depth = Units.inchesToMeters(27.0);
public static final double height = Units.inchesToMeters(1.125);
public static final double distanceFromCenterY = Units.inchesToMeters(75.93);
// Relevant reference points on alliance side
public static final Translation3d depotCenter =
new Translation3d(depth, (fieldWidth / 2) + distanceFromCenterY, height);
public static final Translation3d leftCorner =
new Translation3d(depth, (fieldWidth / 2) + distanceFromCenterY + (width / 2), height);
public static final Translation3d rightCorner =
new Translation3d(depth, (fieldWidth / 2) + distanceFromCenterY - (width / 2), height);
}
public static class Outpost {
// Dimensions
public static final double width = Units.inchesToMeters(31.8);
public static final double openingDistanceFromFloor = Units.inchesToMeters(28.1);
public static final double height = Units.inchesToMeters(7.0);
// Relevant reference points on alliance side
public static final Translation2d centerPoint =
new Translation2d(0, AprilTagLayoutType.OFFICIAL.getLayout().getTagPose(29).get().getY());
}
public enum FieldType {
WELDED("welded");
FieldType(String string) {
jsonFolder = string;
}
public String getJsonFolder() {
return jsonFolder;
}
private final String jsonFolder;
}
public enum AprilTagLayoutType {
OFFICIAL("2026-official"),
NONE("2026-none");
private final String name;
private volatile AprilTagFieldLayout layout;
private volatile String layoutString;
AprilTagLayoutType(String name) {
this.name = name;
}
public AprilTagFieldLayout getLayout() {
if (layout == null) {
synchronized (this) {
if (layout == null) {
try {
Path p =
Path.of(
Filesystem.getDeployDirectory().getPath(),
"apriltags",
"welded",
name + ".json");
layout = new AprilTagFieldLayout(p);
layoutString = new ObjectMapper().writeValueAsString(layout);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
return layout;
}
public String getLayoutString() {
if (layoutString == null) {
getLayout();
}
return layoutString;
}
}
}