Class Field2d

java.lang.Object
org.wpilib.smartdashboard.Field2d
All Implemented Interfaces:
AutoCloseable, TelemetryLoggable, ComplexTunable

public class Field2d extends Object implements TelemetryLoggable, ComplexTunable, AutoCloseable
2D representation of game field for dashboards.

An object's pose is the location shown on the dashboard view. Note that for the robot, this may or may not match the internal odometry. For example, the robot is shown at a particular starting location, the pose in this class would represent the actual location on the field, but the robot's internal state might have a 0,0,0 pose (unless it's initialized to something different).

As the user is able to edit the pose, code performing updates should get the robot pose, transform it as appropriate (e.g. based on wheel odometry), and set the new pose.

This class provides methods to set the robot pose, but other objects can also be shown by using the getObject() function. Other objects can also have multiple poses (which will show the object at multiple locations).

  • Constructor Details

    • Field2d

      public Field2d()
      Constructor.
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • setRobotPose

      public void setRobotPose(Pose2d pose)
      Set the robot pose from a Pose object.
      Parameters:
      pose - 2D pose
    • setRobotPose

      public void setRobotPose(double x, double y, Rotation2d rotation)
      Set the robot pose from x, y, and rotation.
      Parameters:
      x - X location, in meters
      y - Y location, in meters
      rotation - rotation
    • setRobotPose

      public void setRobotPose(Distance x, Distance y, Rotation2d rotation)
      Set the robot pose from x, y, and rotation.
      Parameters:
      x - X location
      y - Y location
      rotation - rotation
    • getRobotPose

      public Pose2d getRobotPose()
      Get the robot pose.
      Returns:
      2D pose
    • getObject

      public FieldObject2d getObject(String name)
      Get or create a field object.
      Parameters:
      name - The field object's name.
      Returns:
      Field object
    • getRobotObject

      public FieldObject2d getRobotObject()
      Get the robot object.
      Returns:
      Field object for robot
    • logTo

      public void logTo(TelemetryTable table)
      Description copied from interface: TelemetryLoggable
      Logs the object to a TelemetryTable.
      Specified by:
      logTo in interface TelemetryLoggable
      Parameters:
      table - telemetry table
    • getTelemetryType

      public String getTelemetryType()
      Description copied from interface: TelemetryLoggable
      Gets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.
      Specified by:
      getTelemetryType in interface TelemetryLoggable
      Returns:
      Table type
    • getTunableType

      public String getTunableType()
      Gets the tunable type.
      Specified by:
      getTunableType in interface ComplexTunable
      Returns:
      Field2d type.
    • publishTunable

      public void publishTunable(TunableTable table)
      Publishes field objects to a tunable table.
      Specified by:
      publishTunable in interface ComplexTunable
      Parameters:
      table - Tunable table.