WPILibC++ 2024.3.2
frc::Mechanism2d Class Reference

Visual 2D representation of arms, elevators, and general mechanisms through a node-based API. More...

#include <frc/smartdashboard/Mechanism2d.h>

Inheritance diagram for frc::Mechanism2d:
nt::NTSendable wpi::SendableHelper< Mechanism2d > wpi::Sendable

Public Member Functions

 Mechanism2d (double width, double height, const Color8Bit &backgroundColor={0, 0, 32})
 Create a new Mechanism2d with the given dimensions and background color. More...
 
MechanismRoot2dGetRoot (std::string_view name, double x, double y)
 Get or create a root in this Mechanism2d with the given name and position. More...
 
void SetBackgroundColor (const Color8Bit &color)
 Set the Mechanism2d background color. More...
 
void InitSendable (nt::NTSendableBuilder &builder) override
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from nt::NTSendable
virtual void InitSendable (NTSendableBuilder &builder)=0
 Initializes this Sendable object. More...
 
void InitSendable (wpi::SendableBuilder &builder) override
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from wpi::Sendable
virtual ~Sendable ()=default
 
virtual void InitSendable (SendableBuilder &builder)=0
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from wpi::SendableHelper< Mechanism2d >
 SendableHelper (const SendableHelper &rhs)=default
 
 SendableHelper (SendableHelper &&rhs)
 
SendableHelperoperator= (const SendableHelper &rhs)=default
 
SendableHelperoperator= (SendableHelper &&rhs)
 

Additional Inherited Members

- Protected Member Functions inherited from wpi::SendableHelper< Mechanism2d >
 SendableHelper ()=default
 
 ~SendableHelper ()
 

Detailed Description

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 also
MechanismObject2d
MechanismLigament2d
MechanismRoot2d

Constructor & Destructor Documentation

◆ Mechanism2d()

frc::Mechanism2d::Mechanism2d ( double  width,
double  height,
const Color8Bit backgroundColor = {0, 0, 32} 
)

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.

Parameters
widththe width
heightthe height
backgroundColorthe background color

Member Function Documentation

◆ GetRoot()

MechanismRoot2d * frc::Mechanism2d::GetRoot ( std::string_view  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
namethe root name
xthe root x coordinate
ythe root y coordinate
Returns
a new root object, or the existing one with the given name.

◆ InitSendable()

void frc::Mechanism2d::InitSendable ( nt::NTSendableBuilder builder)
overridevirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements nt::NTSendable.

◆ SetBackgroundColor()

void frc::Mechanism2d::SetBackgroundColor ( const Color8Bit color)

Set the Mechanism2d background color.

Parameters
colorthe new background color

The documentation for this class was generated from the following file: