You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.. note:: The ``MyCommand`` instance can also be sent using a lower-level NetworkTables API or using the :ref:`Shuffleboard API <docs/software/dashboards/shuffleboard/getting-started/shuffleboard-displaying-data:Displaying data from your robot>`. In this case, the ``SmartDashboard`` API was used, meaning that the :guilabel:`Command Selector` widget will appear under the ``SmartDashboard`` table name.
Copy file name to clipboardExpand all lines: source/docs/software/dashboards/glass/field2d-widget.rst
+24-20Lines changed: 24 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,17 +13,11 @@ To send your robot's position (usually obtained by :ref:`odometry <docs/software
13
13
14
14
privatefinalField2d m_field =newField2d();
15
15
16
-
public Drivetrain() {
17
-
...
18
-
SmartDashboard.putData("Field", m_field);
19
-
}
16
+
// Do this in either robot or subsystem init
17
+
SmartDashboard.putData("Field", m_field);
20
18
21
-
...
22
-
23
-
publicvoid periodic() {
24
-
...
25
-
m_field.setRobotPose(m_odometry.getPoseMeters());
26
-
}
19
+
// Do this in either robot periodic or subsystem periodic
20
+
m_field.setRobotPose(m_odometry.getPoseMeters());
27
21
28
22
.. code-block:: c++
29
23
@@ -32,17 +26,23 @@ To send your robot's position (usually obtained by :ref:`odometry <docs/software
32
26
33
27
frc::Field2d m_field;
34
28
35
-
Drivetrain() {
36
-
...
37
-
frc::SmartDashboard::PutData("Field", &m_field);
38
-
}
29
+
// Do this in either robot or subsystem init
30
+
frc::SmartDashboard::PutData("Field", &m_field);
31
+
32
+
// Do this in either robot periodic or subsystem periodic
33
+
m_field.SetRobotPose(m_odometry.GetPose());
34
+
35
+
.. code-block:: python
39
36
40
-
...
37
+
from wpilib import SmartDashboard, Field2d
41
38
42
-
void Periodic() {
43
-
...
44
-
m_field.SetRobotPose(m_odometry.GetPose());
45
-
}
39
+
self.field = Field2d()
40
+
41
+
# Do this in either robot or subsystem init
42
+
SmartDashboard.putData("Field", self.field)
43
+
44
+
# Do this in either robot periodic or subsystem periodic
45
+
self.field.setRobotPose(self.odometry.getPose())
46
46
47
47
.. note:: The ``Field2d`` instance can also be sent using a lower-level NetworkTables API or using the :ref:`Shuffleboard API <docs/software/dashboards/shuffleboard/getting-started/shuffleboard-displaying-data:Displaying data from your robot>`. In this case, the ``SmartDashboard`` API was used, meaning that the :guilabel:`Field2d` widget will appear under the ``SmartDashboard`` table name.
48
48
@@ -65,6 +65,10 @@ Visualizing your trajectory is a great debugging step for verifying that your tr
@@ -73,7 +77,7 @@ The sent trajectory can be viewed with :ref:`Glass <docs/software/dashboards/gla
73
77
.. image:: images/sent-trajectory.png
74
78
:alt:Picture containing Field2d and the generated trajectory
75
79
76
-
.. note:: The above example which uses the `RamseteController (Java) <https://github.com/wpilibsuite/allwpilib/blob/a610379965680a8f9214d5f0db3a8e1bc20d4712/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Robot.java>`__/`RamseteController (C++) <https://github.com/wpilibsuite/allwpilib/blob/a610379965680a8f9214d5f0db3a8e1bc20d4712/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp>`__ will not show the sent trajectory until autonomous is enabled at least once.
80
+
.. note:: The above example which uses the RamseteController (`Java <https://github.com/wpilibsuite/allwpilib/blob/a610379965680a8f9214d5f0db3a8e1bc20d4712/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Robot.java>`__ / `C++ <https://github.com/wpilibsuite/allwpilib/blob/a610379965680a8f9214d5f0db3a8e1bc20d4712/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp>`__ / `Python <https://github.com/robotpy/examples/tree/2024.0.0b4/RamseteController>`__) will not show the sent trajectory until autonomous is enabled at least once.
Each ``MechanismLigament2d`` object represents a stage of the mechanism. It has a three required parameters, a name, an initial length to draw (relative to the size of the ``Mechanism2d`` object), and an initial angle to draw the ligament in degrees. Ligament angles are relative to the parent ligament, and follow math notation - the same as :ref:`Rotation2d <docs/software/advanced-controls/geometry/pose:Rotation>` (counterclockwise-positive). A ligament based on the root with an angle of zero will point right. Two optional parameters let you change the width (also relative to the size of the Mechanism2d object) and the color. Call ``append()``/``Append()`` on a root node or ligament node to add another node to the figure. In Java, pass a constructed ``MechanismLigament2d`` object to add it. In C++, pass the construction parameters in order to construct and add a ligament.
29
35
@@ -42,6 +48,12 @@ Each ``MechanismLigament2d`` object represents a stage of the mechanism. It has
.. note:: The ``Mechanism2d`` instance can also be sent using a lower-level NetworkTables API or using the :ref:`Shuffleboard API <docs/software/dashboards/shuffleboard/getting-started/shuffleboard-displaying-data:Displaying data from your robot>`. In this case, the ``SmartDashboard`` API was used, meaning that the :guilabel:`Mechanism2d` widget will appear under the ``SmartDashboard`` table name.
62
80
63
81
To manipulate a ligament angle or length, call ``setLength()`` or ``setAngle()`` on the ``MechanismLigament2d`` object. When manipulating ligament length based off of sensor measurements, make sure to add the minimum length to prevent 0-length (and therefore invisible) ligaments.
@@ -76,6 +94,12 @@ To manipulate a ligament angle or length, call ``setLength()`` or ``setAngle()``
@@ -99,4 +123,4 @@ Viewing the Mechanism2d in AdvantageScope
99
123
Next Steps
100
124
----------
101
125
102
-
As mentioned above, the Mechanism2d visualization can be combined with :doc:`Physics Simulation </docs/software/wpilib-tools/robot-simulation/physics-sim>` to help you program mechanisms before your robot is built. The ArmSimulation (`Java <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armsimulation/Robot.java>`__ / `C++ <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp>`__) and ElevatorSimulation (`Java <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorsimulation/Robot.java>`__ / `C++ <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp>`__) examples combine physics simulation and Mechanism2d visualization so that you can practice programming a single jointed arm and elevator without a robot.
126
+
As mentioned above, the Mechanism2d visualization can be combined with :doc:`Physics Simulation </docs/software/wpilib-tools/robot-simulation/physics-sim>` to help you program mechanisms before your robot is built. The ArmSimulation (`Java <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armsimulation/Robot.java>`__ / `C++ <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp>`__ / `Python <https://github.com/robotpy/examples/blob/2024.0.0b4/ArmSimulation/robot.py>`__) and ElevatorSimulation (`Java <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorsimulation/Robot.java>`__ / `C++ <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp>`__ / `Python <https://github.com/robotpy/examples/blob/2024.0.0b4/ElevatorSimulation/robot.py>`__) examples combine physics simulation and Mechanism2d visualization so that you can practice programming a single jointed arm and elevator without a robot.
.. note:: For more information on creating a ``SendableChooser``, please see :ref:`this document <docs/software/dashboards/smartdashboard/choosing-an-autonomous-program-from-smartdashboard:Setting up SendableChooser>`.
44
50
45
51
The :guilabel:`Sendable Chooser` widget will appear in the :guilabel:`NetworkTables` menu and underneath the main table name that the instance was sent over. From the example above, the main table name would be :guilabel:`SmartDashboard`.
@@ -60,6 +66,12 @@ The :guilabel:`PID Controller` widget allows you to quickly tune PID values for
0 commit comments