class wpilib.Mechanism2d(width: float, height: float, backgroundColor: wpilib._wpilib.Color8Bit = Color8Bit(red=0, green=0, blue=32))

Bases: _pyntcore._ntcore.NTSendable

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.

Except for the Mechanism2d container object, none of the objects should be passed or interacted with by value! Obtain pointers from factory methods such as Mechanism2d.GetRoot() and MechanismObject2d.Append<>(). The Mechanism2d container object owns the root nodes, and each node internally owns the nodes based on it. Beware not to let the Mechanism2d object out of scope - all nodes will be recursively destructed!

@see MechanismObject2d @see MechanismLigament2d @see MechanismRoot2d

Create a new Mechanism2d with the given dimensions and background color.

The dimensions represent the canvas that all the nodes are drawn on. The default color is dark blue.

  • width – the width

  • height – the height

  • backgroundColor – the background color

getRoot(name: str, x: float, y: float) wpilib._wpilib.MechanismRoot2d

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.

  • name – the root name

  • x – the root x coordinate

  • y – the root y coordinate


a new root object, or the existing one with the given name.

initSendable(builder: _pyntcore._ntcore.NTSendableBuilder) None
setBackgroundColor(color: wpilib._wpilib.Color8Bit) None

Set the Mechanism2d background color.


color – the new background color