Skip to content

Commit

Permalink
Convert RobotPy API URLs to sphinx references (#2584)
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald committed Feb 23, 2024
1 parent b74ce41 commit ed3fb4b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ DifferentialDrive is a method provided for the control of "skid-steer" or "West
Multi-Motor DifferentialDrive
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Many FRC\ |reg| drivetrains have more than 1 motor on each side. Classes derived from ``PWMMotorController`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/motorcontrol/PWMMotorController.html>`__ / `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_p_w_m_motor_controller.html>`__ / `Python <https://robotpy.readthedocs.io/projects/robotpy/en/stable/wpilib/PWMMotorController.html>`__) have an ``addFollower`` method so that multiple follower motor controllers can be updated when the leader motor controller is commanded. CAN motor controllers have similar features, review the vendor's documention to see how to use them. The examples below show a 4 motor (2 per side) drivetrain. To extend to more motors, simply create the additional controllers and use additional ``addFollower`` calls.
Many FRC\ |reg| drivetrains have more than 1 motor on each side. Classes derived from ``PWMMotorController`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/motorcontrol/PWMMotorController.html>`__ / `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_p_w_m_motor_controller.html>`__ / :external:py:class:`Python <wpilib.PWMMotorController>`) have an ``addFollower`` method so that multiple follower motor controllers can be updated when the leader motor controller is commanded. CAN motor controllers have similar features, review the vendor's documention to see how to use them. The examples below show a 4 motor (2 per side) drivetrain. To extend to more motors, simply create the additional controllers and use additional ``addFollower`` calls.

.. tab-set::

Expand Down
2 changes: 1 addition & 1 deletion source/docs/software/networktables/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NetworkTables

This section outlines the details of using the NetworkTables (v4) API to communicate information across the robot network.

.. important:: The code examples in this section are not intended for the user to copy-paste. Ensure that the following documentation is thoroughly read and the API (`Java <https://github.wpilib.org/allwpilib/docs/release/java/index.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/index.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/api.html>`__) is consulted when necessary.
.. important:: The code examples in this section are not intended for the user to copy-paste. Ensure that the following documentation is thoroughly read and the API (`Java <https://github.wpilib.org/allwpilib/docs/release/java/index.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/index.html>`__, :ref:`Python <robotpy:ntcore_api>`) is consulted when necessary.

.. toctree::
:maxdepth: 1
Expand Down
2 changes: 1 addition & 1 deletion source/docs/software/networktables/multiple-instances.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ For most general usage, you should use the "default" instance, as all current da

However, if you wanted to do unit testing of your robot program's NetworkTables communications, you could set up your unit tests such that they create a separate client instance (still within the same program) and have it connect to the server instance that the main robot code is running.

The ``NetworkTableInstance`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/NetworkTableInstance.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_network_table_instance.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/ntcore/NetworkTableInstance.html>`__) class provides the API abstraction for instances. The number of instances that can be simultaneously created is limited to 16 (including the default instance), so when using multiple instances in cases such as unit testing code, it's important to destroy instances that are no longer needed.
The ``NetworkTableInstance`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/NetworkTableInstance.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_network_table_instance.html>`__, :external:py:class:`Python <ntcore.NetworkTableInstance>`) class provides the API abstraction for instances. The number of instances that can be simultaneously created is limited to 16 (including the default instance), so when using multiple instances in cases such as unit testing code, it's important to destroy instances that are no longer needed.

Destroying a NetworkTableInstance frees all resources related to the instance. All classes or handles that reference the instance (e.g. Topics, Publishers, and Subscribers) are invalidated and may result in unexpected behavior if used after the instance is destroyed--in particular, instance handles are reused so it's possible for a handle "left over" from a previously destroyed instance to refer to an unexpected resource in a newly created instance.

Expand Down
2 changes: 1 addition & 1 deletion source/docs/software/networktables/networktables-intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Because of this, two timestamps are visible through the API: a server timestamp
NetworkTables Organization
--------------------------

Data is organized in NetworkTables in a hierarchy much like a filesystem's folders and files. There can be multiple subtables (folders) and topics (files) that may be nested in whatever way fits the data organization desired. At the top level (``NetworkTableInstance``: `Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/NetworkTableInstance.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_network_table_instance.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/ntcore/NetworkTableInstance.html#ntcore.NetworkTableInstance>`__), topic names are handled similar to absolute paths in a filesystem: subtables are represented as a long topic name with slashes ("/") separating the nested subtable and value names. A ``NetworkTable`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/NetworkTable.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_network_table.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/ntcore/NetworkTable.html#ntcore.NetworkTable>`__) object represents a single subtable (folder), so topic names are relative to the NetworkTable's base path: e.g. for a root table called "SmartDashboard" with a topic named "xValue", the same topic can be accessed via ``NetworkTableInstance`` as a topic named "/SmartDashboard/xValue". However, unlike a filesystem, subtables don't really exist in the same way folders do, as there is no way to represent an empty subtable on the network--a subtable "appears" only as long as there are topics published within it.
Data is organized in NetworkTables in a hierarchy much like a filesystem's folders and files. There can be multiple subtables (folders) and topics (files) that may be nested in whatever way fits the data organization desired. At the top level (``NetworkTableInstance``: `Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/NetworkTableInstance.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_network_table_instance.html>`__, :external:py:class:`Python <ntcore.NetworkTableInstance>`), topic names are handled similar to absolute paths in a filesystem: subtables are represented as a long topic name with slashes ("/") separating the nested subtable and value names. A ``NetworkTable`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/NetworkTable.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_network_table.html>`__, :external:py:class:`Python <ntcore.NetworkTable>`) object represents a single subtable (folder), so topic names are relative to the NetworkTable's base path: e.g. for a root table called "SmartDashboard" with a topic named "xValue", the same topic can be accessed via ``NetworkTableInstance`` as a topic named "/SmartDashboard/xValue". However, unlike a filesystem, subtables don't really exist in the same way folders do, as there is no way to represent an empty subtable on the network--a subtable "appears" only as long as there are topics published within it.

:ref:`docs/software/wpilib-tools/outlineviewer/index:outlineviewer` is a utility for exploring the values stored in NetworkTables, and can show either a flat view (topics with absolute paths) or a nested view (subtables and topics).

Expand Down
10 changes: 5 additions & 5 deletions source/docs/software/networktables/publish-and-subscribe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Publishing to a Topic

In order to create a :term:`topic` and publish values to it, it's necessary to create a :term:`publisher`.

NetworkTable publishers are represented as type-specific Publisher objects (e.g. ``BooleanPublisher``: `Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/BooleanPublisher.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_boolean_publisher.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/ntcore/BooleanPublisher.html>`__). Publishers are only active as long as the Publisher object exists. Typically you want to keep publishing longer than the local scope of a function, so it's necessary to store the Publisher object somewhere longer term, e.g. in an instance variable. In Java, the ``close()`` method needs be called to stop publishing; in C++ this is handled by the destructor. C++ publishers are moveable and non-copyable. In Python the ``close()`` method should be called to stop publishing, but it will also be closed when the object is garbage collected.
NetworkTable publishers are represented as type-specific Publisher objects (e.g. ``BooleanPublisher``: `Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/BooleanPublisher.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_boolean_publisher.html>`__, :external:py:class:`Python <ntcore.BooleanPublisher>`). Publishers are only active as long as the Publisher object exists. Typically you want to keep publishing longer than the local scope of a function, so it's necessary to store the Publisher object somewhere longer term, e.g. in an instance variable. In Java, the ``close()`` method needs be called to stop publishing; in C++ this is handled by the destructor. C++ publishers are moveable and non-copyable. In Python the ``close()`` method should be called to stop publishing, but it will also be closed when the object is garbage collected.

In the handle-based APIs, there is only the non-type-specific ``NT_Publisher`` handle; the user is responsible for keeping track of the type of the publisher and using the correct type-specific set methods.

Expand Down Expand Up @@ -236,7 +236,7 @@ Publishing values is done via a ``set()`` operation. By default, this operation
Subscribing to a Topic
----------------------

A :term:`subscriber` receives value updates made to a topic. Similar to publishers, NetworkTable subscribers are represented as type-specific Subscriber classes (e.g. ``BooleanSubscriber``: `Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/BooleanSubscriber.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_boolean_subscriber.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/ntcore/BooleanSubscriber.html>`__) that must be stored somewhere to continue subscribing.
A :term:`subscriber` receives value updates made to a topic. Similar to publishers, NetworkTable subscribers are represented as type-specific Subscriber classes (e.g. ``BooleanSubscriber``: `Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/BooleanSubscriber.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_boolean_subscriber.html>`__, :external:py:class:`Python <ntcore.BooleanSubscriber>`) that must be stored somewhere to continue subscribing.

Subscribers have a range of different ways to read received values. It's possible to just read the most recent value using ``get()``, read the most recent value, along with its timestamp, using ``getAtomic()``, or get an array of all value changes since the last call using ``readQueue()`` or ``readQueueValues()``.

Expand Down Expand Up @@ -470,7 +470,7 @@ Subscribers have a range of different ways to read received values. It's possibl
Using Entry to Both Subscribe and Publish
-----------------------------------------

An :term:`entry` is a combined publisher and subscriber. The subscriber is always active, but the publisher is not created until a publish operation is performed (e.g. a value is "set", aka published, on the entry). This may be more convenient than maintaining a separate publisher and subscriber. Similar to publishers and subscribers, NetworkTable entries are represented as type-specific Entry classes (e.g. ``BooleanEntry``: `Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/BooleanEntry.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_boolean_entry.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/ntcore/BooleanEntry.html>`__) that must be retained to continue subscribing (and publishing).
An :term:`entry` is a combined publisher and subscriber. The subscriber is always active, but the publisher is not created until a publish operation is performed (e.g. a value is "set", aka published, on the entry). This may be more convenient than maintaining a separate publisher and subscriber. Similar to publishers and subscribers, NetworkTable entries are represented as type-specific Entry classes (e.g. ``BooleanEntry``: `Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/BooleanEntry.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_boolean_entry.html>`__, :external:py:class:`Python <ntcore.BooleanEntry>`) that must be retained to continue subscribing (and publishing).

.. tab-set::

Expand Down Expand Up @@ -730,7 +730,7 @@ An :term:`entry` is a combined publisher and subscriber. The subscriber is alway
Using GenericEntry, GenericPublisher, and GenericSubscriber
-----------------------------------------------------------

For the most robust code, using the type-specific Publisher, Subscriber, and Entry classes is recommended, but in some cases it may be easier to write code that uses type-specific get and set function calls instead of having the NetworkTables type be exposed via the class (object) type. The ``GenericPublisher`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/GenericPublisher.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_generic_publisher.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/ntcore/GenericPublisher.html>`__), ``GenericSubscriber`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/GenericSubscriber.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_generic_subscriber.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/ntcore/GenericSubscriber.html>`__), and ``GenericEntry`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/GenericEntry.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_generic_entry.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/ntcore/GenericEntry.html>`__) classes enable this approach.
For the most robust code, using the type-specific Publisher, Subscriber, and Entry classes is recommended, but in some cases it may be easier to write code that uses type-specific get and set function calls instead of having the NetworkTables type be exposed via the class (object) type. The ``GenericPublisher`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/GenericPublisher.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_generic_publisher.html>`__, :external:py:class:`Python <ntcore.GenericPublisher>`), ``GenericSubscriber`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/GenericSubscriber.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_generic_subscriber.html>`__, :external:py:class:`Python <ntcore.GenericSubscriber>`), and ``GenericEntry`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/GenericEntry.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_generic_entry.html>`__, :external:py:class:`Python <ntcore.GenericEntry>`) classes enable this approach.

.. tab-set::

Expand Down Expand Up @@ -1201,6 +1201,6 @@ Entry options:
NetworkTableEntry
-----------------

``NetworkTableEntry`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/NetworkTableEntry.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_network_table_entry.html>`__, `Python <https://robotpy.readthedocs.io/projects/pyntcore/en/stable/ntcore/NetworkTableEntry.html>`__) is a class that exists for backwards compatibility. New code should prefer using type-specific Publisher and Subscriber classes, or GenericEntry if non-type-specific access is needed.
``NetworkTableEntry`` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/networktables/NetworkTableEntry.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classnt_1_1_network_table_entry.html>`__, :external:py:class:`Python <ntcore.NetworkTableEntry>`) is a class that exists for backwards compatibility. New code should prefer using type-specific Publisher and Subscriber classes, or GenericEntry if non-type-specific access is needed.

It is similar to ``GenericEntry`` in that it supports both publishing and subscribing in a single object. However, unlike ``GenericEntry``, ``NetworkTableEntry`` is not released (e.g. unsubscribes/unpublishes) if ``close()`` is called (in Java) or the object is destroyed (in C++); instead, it operates similar to ``Topic``, in that only a single ``NetworkTableEntry`` exists for each topic and it lasts for the lifetime of the instance.

0 comments on commit ed3fb4b

Please sign in to comment.