WPILibC++ 2024.3.2
|
Class for representing a layout of AprilTags on a field and reading them from a JSON format. More...
#include <frc/apriltag/AprilTagFieldLayout.h>
Public Types | |
enum class | OriginPosition { kBlueAllianceWallRightSide , kRedAllianceWallRightSide } |
Common origin positions for the AprilTag coordinate system. More... | |
Public Member Functions | |
AprilTagFieldLayout ()=default | |
AprilTagFieldLayout (std::string_view path) | |
Construct a new AprilTagFieldLayout with values imported from a JSON file. More... | |
AprilTagFieldLayout (std::vector< AprilTag > apriltags, units::meter_t fieldLength, units::meter_t fieldWidth) | |
Construct a new AprilTagFieldLayout from a vector of AprilTag objects. More... | |
units::meter_t | GetFieldLength () const |
Returns the length of the field the layout is representing. More... | |
units::meter_t | GetFieldWidth () const |
Returns the length of the field the layout is representing. More... | |
std::vector< AprilTag > | GetTags () const |
Returns a vector of all the april tags used in this layout. More... | |
void | SetOrigin (OriginPosition origin) |
Sets the origin based on a predefined enumeration of coordinate frame origins. More... | |
void | SetOrigin (const Pose3d &origin) |
Sets the origin for tag pose transformation. More... | |
Pose3d | GetOrigin () const |
Returns the origin used for tag pose transformation. More... | |
std::optional< Pose3d > | GetTagPose (int ID) const |
Gets an AprilTag pose by its ID. More... | |
void | Serialize (std::string_view path) |
Serializes an AprilTagFieldLayout to a JSON file. More... | |
bool | operator== (const AprilTagFieldLayout &) const =default |
Static Public Member Functions | |
static AprilTagFieldLayout | LoadField (AprilTagField field) |
Loads an AprilTagFieldLayout from a predefined field. More... | |
Friends | |
WPILIB_DLLEXPORT void | to_json (wpi::json &json, const AprilTagFieldLayout &layout) |
WPILIB_DLLEXPORT void | from_json (const wpi::json &json, AprilTagFieldLayout &layout) |
Class for representing a layout of AprilTags on a field and reading them from a JSON format.
The JSON format contains two top-level objects, "tags" and "field". The "tags" object is a list of all AprilTags contained within a layout. Each AprilTag serializes to a JSON object containing an ID and a Pose3d. The "field" object is a descriptor of the size of the field in meters with "width" and "length" values. This is to account for arbitrary field sizes when transforming the poses.
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).
|
strong |
Common origin positions for the AprilTag coordinate system.
Enumerator | |
---|---|
kBlueAllianceWallRightSide | Blue alliance wall, right side. |
kRedAllianceWallRightSide | Red alliance wall, right side. |
|
default |
|
explicit |
Construct a new AprilTagFieldLayout with values imported from a JSON file.
path | Path of the JSON file to import from. |
frc::AprilTagFieldLayout::AprilTagFieldLayout | ( | std::vector< AprilTag > | apriltags, |
units::meter_t | fieldLength, | ||
units::meter_t | fieldWidth | ||
) |
Construct a new AprilTagFieldLayout from a vector of AprilTag objects.
apriltags | Vector of AprilTags. |
fieldLength | Length of field the layout is representing. |
fieldWidth | Width of field the layout is representing. |
units::meter_t frc::AprilTagFieldLayout::GetFieldLength | ( | ) | const |
Returns the length of the field the layout is representing.
units::meter_t frc::AprilTagFieldLayout::GetFieldWidth | ( | ) | const |
Returns the length of the field the layout is representing.
Pose3d frc::AprilTagFieldLayout::GetOrigin | ( | ) | const |
Returns the origin used for tag pose transformation.
std::optional< Pose3d > frc::AprilTagFieldLayout::GetTagPose | ( | int | ID | ) | const |
Gets an AprilTag pose by its ID.
ID | The ID of the tag. |
std::vector< AprilTag > frc::AprilTagFieldLayout::GetTags | ( | ) | const |
Returns a vector of all the april tags used in this layout.
|
static |
Loads an AprilTagFieldLayout from a predefined field.
field | The predefined field |
|
default |
void frc::AprilTagFieldLayout::Serialize | ( | std::string_view | path | ) |
Serializes an AprilTagFieldLayout to a JSON file.
path | The path to write the JSON file to. |
void frc::AprilTagFieldLayout::SetOrigin | ( | const Pose3d & | origin | ) |
Sets the origin for tag pose transformation.
This transforms the Pose3ds returned by GetTagPose(int) to return the correct pose relative to the provided origin.
origin | The new origin for tag transformations |
void frc::AprilTagFieldLayout::SetOrigin | ( | OriginPosition | origin | ) |
Sets the origin based on a predefined enumeration of coordinate frame origins.
The origins are calculated from the field dimensions.
This transforms the Pose3ds returned by GetTagPose(int) to return the correct pose relative to a predefined coordinate frame.
origin | The predefined origin |
|
friend |
|
friend |