Class LoggedMechanism2d

java.lang.Object
org.littletonrobotics.junction.mechanism.LoggedMechanism2d
All Implemented Interfaces:
NTSendable, Sendable, AutoCloseable

public final class LoggedMechanism2d extends Object implements NTSendable, AutoCloseable
Visual 2D representation of arms, elevators, and general mechanisms through a node-based API.

A Mechanism2d object is published and contains at least one root node. A root is the anchor point of other nodes (such as ligaments). Other nodes are recursively appended based on other nodes.

See Also:
  • Constructor Details

    • LoggedMechanism2d

      public LoggedMechanism2d(double width, double height)
      Create a new Mechanism2d with the given dimensions and default color (dark blue).

      The dimensions represent the canvas that all the nodes are drawn on.

      Parameters:
      width - the width in meters
      height - the height in meters
    • LoggedMechanism2d

      public LoggedMechanism2d(Distance width, Distance height)
      Create a new Mechanism2d with the given dimensions and default color (dark blue).

      The dimensions represent the canvas that all the nodes are drawn on.

      Parameters:
      width - the width
      height - the height
    • LoggedMechanism2d

      public LoggedMechanism2d(double width, double height, Color8Bit backgroundColor)
      Create a new Mechanism2d with the given dimensions.

      The dimensions represent the canvas that all the nodes are drawn on.

      Parameters:
      width - the width in meters
      height - the height in meters
      backgroundColor - the background color. Defaults to dark blue.
    • LoggedMechanism2d

      public LoggedMechanism2d(Distance width, Distance height, Color8Bit backgroundColor)
      Create a new Mechanism2d with the given dimensions.

      The dimensions represent the canvas that all the nodes are drawn on.

      Parameters:
      width - the width
      height - the height
      backgroundColor - the background color. Defaults to dark blue.
  • Method Details

    • close

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

      public LoggedMechanismRoot2d getRoot(String name, double x, double y)
      Get or create a root in this Mechanism2d with the given name and position.

      If a root with the given name already exists, the given x and y coordinates are not used.

      Parameters:
      name - the root name
      x - the root x coordinate
      y - the root y coordinate
      Returns:
      a new root joint object, or the existing one with the given name.
    • setBackgroundColor

      public void setBackgroundColor(Color8Bit color)
      Set the Mechanism2d background color.
      Parameters:
      color - the new color
    • initSendable

      public void initSendable(NTSendableBuilder builder)
      Specified by:
      initSendable in interface NTSendable
    • logOutput

      public void logOutput(LogTable table)
      Record the current value to the log. This function should never be called by user code.
      Parameters:
      table - The table to which data should be written.
    • generate3dMechanism

      public ArrayList<Pose3d> generate3dMechanism()
      Converts a forward facing Mechanism2d into a series of Pose3d objects. Poses are generated with standard coordinate frame (+x forward, +y left, +z up) and each pivot point is assumed to be at the origin of the model.

      The order of the poses returned is based on the order of insertion. The first root inserted into the Mechanism2d goes first, and processed in a depth-first manner.

      Returns:
      Pose3d[] representing each mechanism component