Class Field
The JSON format contains the top-level objects "name", "season", "game", "field-dimensions", and "program", and can optionally contain "field-image" and "field-tags". The "field-dimensions" object stores "length" and "width" in meters. The "field-image" object stores the image path and the field boundaries in image pixels. The "field-tags" object stores all field tags contained within a layout.
Pose3ds in the JSON are measured using the normal FRC coordinate system, NWU with the origin
at the bottom-right corner of the blue alliance wall. setOrigin(OriginPosition) can be
used to change the poses returned from getTagPose(int) to be from the perspective
of a specific alliance.
Tag poses represent the center of the tag, with a zero rotation representing a tag that is upright and facing away from the (blue) alliance wall (that is, towards the opposing alliance).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumCommon origin positions for the field tag coordinate system. -
Field Summary
FieldsModifier and TypeFieldDescriptionField image metadata, or null if this field has no image.Game name.doubleField length in meters.Human-readable field name.FIRST program.JSON resource path for this field, or null if this field was loaded from a file.Field season.Field tag metadata, or null if this field has no tag layout.doubleField width in meters. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleandoubleReturns the field length in meters.doubleReturns the field width in meters.Gets an input stream for the field image described by this field.Gets the resource path of the field image described by this field.Gets the URL of the field image described by this field.getJson()Returns the original JSON contents for this field.getName()Returns the human-readable field name.Returns the origin used for tag pose transformation.getTagPose(int ID) Gets a tag pose by its ID.getTags()Returns a List of theFieldTagsused by this field.inthashCode()booleanhasImage()Returns true if this field has field image metadata.booleanhasTags()Returns true if this field has tag metadata.static FieldLoads a predefined field.static FieldloadFromFile(Path file) Loads a field from a file on disk.static FieldloadFromResource(String resourcePath) Loads a field from a resource file located inside the program's jar file.voidSerializes a field to a JSON file.voidSerializes a field to a JSON file.voidsetOrigin(Field.OriginPosition origin) Sets the origin based on a predefined enumeration of coordinate frame origins.voidSets the origin for tag pose transformation.
-
Field Details
-
name
Human-readable field name. -
season
Field season. -
game
Game name. -
fieldImage
Field image metadata, or null if this field has no image. -
length
public double lengthField length in meters. -
width
public double widthField width in meters. -
program
FIRST program. -
tags
-
resourceFile
JSON resource path for this field, or null if this field was loaded from a file.
-
-
Constructor Details
-
Field
public Field()Constructs an empty field object for JSON deserialization. -
Field
public Field(String name, String season, String game, FieldImage fieldImage, double fieldLength, double fieldWidth, String program, List<FieldTag> tags) Constructs a field object.- Parameters:
name- Human-readable field name.season- Field season.game- Game name.fieldImage- Field image metadata, or null if this field has no image.fieldLength- Field length in meters.fieldWidth- Field width in meters.program- FIRST program.tags- Field tag metadata, or null if this field has no tag layout.
-
-
Method Details
-
getName
Returns the human-readable field name.- Returns:
- The human-readable field name.
-
hasImage
public boolean hasImage()Returns true if this field has field image metadata.- Returns:
- True if this field has field image metadata.
-
getImageResource
Gets the resource path of the field image described by this field.- Returns:
- The image resource path, or null if this field has no image.
-
getImageUrl
Gets the URL of the field image described by this field.This returns null unless this field has an image and the separate field image resources artifact is present on the runtime classpath.
- Returns:
- The image URL, or null if the image resource is not available.
-
getImageAsStream
Gets an input stream for the field image described by this field.This returns null unless this field has an image and the separate field image resources artifact is present on the runtime classpath.
- Returns:
- The image input stream, or null if the image resource is not available.
-
getJson
Returns the original JSON contents for this field.- Returns:
- The original JSON contents for this field, or null if none were retained.
-
hasTags
public boolean hasTags()Returns true if this field has tag metadata.- Returns:
- True if this field has tag metadata.
-
getTags
-
getFieldLength
public double getFieldLength()Returns the field length in meters.- Returns:
- The field length in meters.
-
getFieldWidth
public double getFieldWidth()Returns the field width in meters.- Returns:
- The field width in meters.
-
setOrigin
Sets the origin based on a predefined enumeration of coordinate frame origins. The origins are calculated from the field dimensions.This transforms the Pose3d objects returned by
getTagPose(int)to return the correct pose relative to a predefined coordinate frame.- Parameters:
origin- The predefined origin.
-
setOrigin
Sets the origin for tag pose transformation.This transforms the Pose3d objects returned by
getTagPose(int)to return the correct pose relative to the provided origin.- Parameters:
origin- The new origin for tag transformations.
-
getOrigin
-
getTagPose
-
serialize
Serializes a field to a JSON file.- Parameters:
path- The path to write to.- Throws:
IOException- If writing to the file fails.
-
serialize
Serializes a field to a JSON file.- Parameters:
path- The path to write to.- Throws:
IOException- If writing to the file fails.
-
loadField
-
loadFromFile
Loads a field from a file on disk.- Parameters:
file- The JSON file to load.- Returns:
- The field.
- Throws:
IOException- Throws if the file could not be loaded.
-
loadFromResource
Loads a field from a resource file located inside the program's jar file.- Parameters:
resourcePath- The path to the resource file.- Returns:
- The field.
- Throws:
IOException- Throws if the resource could not be loaded.
-
equals
-
hashCode
-