WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
Mechanism2d.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <memory>
8#include <string>
9
11#include "wpi/nt/NTSendable.hpp"
17#include "wpi/util/mutex.hpp"
19
20namespace wpi {
21
22/**
23 * Visual 2D representation of arms, elevators, and general mechanisms through
24 * a node-based API.
25 *
26 * A Mechanism2d object is published and contains at least one root node. A root
27 * is the anchor point of other nodes (such as ligaments). Other nodes are
28 * recursively appended based on other nodes.
29 *
30 * Except for the Mechanism2d container object, none of the objects should be
31 * passed or interacted with by value! Obtain pointers from factory methods such
32 * as Mechanism2d.GetRoot() and MechanismObject2d.Append<>(). The Mechanism2d
33 * container object owns the root nodes, and each node internally owns the nodes
34 * based on it. Beware not to let the Mechanism2d object out of scope - all
35 * nodes will be recursively destructed!
36 *
37 * @see MechanismObject2d
38 * @see MechanismLigament2d
39 * @see MechanismRoot2d
40 */
42 public wpi::util::SendableHelper<Mechanism2d> {
43 public:
44 /**
45 * Create a new Mechanism2d with the given dimensions and background color.
46 *
47 * The dimensions represent the canvas that all the nodes are drawn on. The
48 * default color is dark blue.
49 *
50 * @param width the width
51 * @param height the height
52 * @param backgroundColor the background color
53 */
54 Mechanism2d(double width, double height,
55 const wpi::util::Color8Bit& backgroundColor = {0, 0, 32});
56
57 /**
58 * Get or create a root in this Mechanism2d with the given name and
59 * position.
60 *
61 * <p>If a root with the given name already exists, the given x and y
62 * coordinates are not used.
63 *
64 * @param name the root name
65 * @param x the root x coordinate
66 * @param y the root y coordinate
67 * @return a new root object, or the existing one with the given name.
68 */
69 MechanismRoot2d* GetRoot(std::string_view name, double x, double y);
70
71 /**
72 * Set the Mechanism2d background color.
73 *
74 * @param color the new background color
75 */
77
79
80 private:
81 double m_width;
82 double m_height;
83 std::string m_color;
84 mutable wpi::util::mutex m_mutex;
85 std::shared_ptr<wpi::nt::NetworkTable> m_table;
88 wpi::nt::StringPublisher m_colorPub;
89};
90} // namespace wpi
@ name
Definition base.h:690
void SetBackgroundColor(const wpi::util::Color8Bit &color)
Set the Mechanism2d background color.
Mechanism2d(double width, double height, const wpi::util::Color8Bit &backgroundColor={0, 0, 32})
Create a new Mechanism2d with the given dimensions and background color.
MechanismRoot2d * GetRoot(std::string_view name, double x, double y)
Get or create a root in this Mechanism2d with the given name and position.
void InitSendable(wpi::nt::NTSendableBuilder &builder) override
Initializes this Sendable object.
Root Mechanism2d node.
Definition MechanismRoot2d.hpp:25
NetworkTables DoubleArray publisher.
Definition DoubleArrayTopic.hpp:182
Helper class for building Sendable dashboard representations for NetworkTables.
Definition NTSendableBuilder.hpp:21
Interface for NetworkTable Sendable objects.
Definition NTSendable.hpp:16
NetworkTables String publisher.
Definition StringTopic.hpp:184
Represents colors that can be used with Addressable LEDs.
Definition Color8Bit.hpp:23
A helper class for use with objects that add themselves to SendableRegistry.
Definition SendableHelper.hpp:21
StringMap is a sorted associative container that contains key-value pairs with unique string keys.
Definition StringMap.hpp:26
color
Definition color.h:16
::std::mutex mutex
Definition mutex.hpp:17
Definition CvSource.hpp:15