Skip to content

Commit

Permalink
Update python cscore/cameraserver documentation to be clearer about i…
Browse files Browse the repository at this point in the history
…nstall (#2625)

- Fixes #2624
  • Loading branch information
virtuald authored May 3, 2024
1 parent d5db5cb commit 30d8b1d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ If you're interested in just switching what the driver sees, and are using Smart
.. tab-item:: PYTHON
:sync: tabcode-python

.. note:: Python requires you to place your image processing code in a separate file from your robot code. You can create ``robot.py`` and ``vision.py`` in the same directory.

``robot.py`` contents:

.. code-block:: python
Expand Down Expand Up @@ -103,6 +105,17 @@ If you're interested in just switching what the driver sees, and are using Smart
CameraServer.waitForever()
``pyproject.toml`` contents (this only shows the portions you need to update):

.. code-block:: toml
[tool.robotpy]
...
# Add cscore to the robotpy-extras list
robotpy_extras = ["cscore"]
If you're using some other dashboard, you can change the camera used by the camera server dynamically. If you open a stream viewer nominally to camera1, the robot code will change the stream contents to either camera1 or camera2 based on the joystick trigger.

.. tab-set-code::
Expand Down Expand Up @@ -232,6 +245,8 @@ By default, the cscore library is pretty aggressive in turning off cameras not i
.. tab-item:: PYTHON
:sync: tabcode-python

.. note:: Python requires you to place your image processing code in a separate file from your robot code. You can create ``robot.py`` and ``vision.py`` in the same directory.

``robot.py`` contents:

.. code-block:: python
Expand Down Expand Up @@ -270,6 +285,17 @@ By default, the cscore library is pretty aggressive in turning off cameras not i
CameraServer.waitForever()
``pyproject.toml`` contents (this only shows the portions you need to update):

.. code-block:: toml
[tool.robotpy]
...
# Add cscore to the robotpy-extras list
robotpy_extras = ["cscore"]
.. note::
If both cameras are USB, you may run into USB bandwidth limitations with higher resolutions, as in all of these cases the roboRIO is going to be streaming data from both cameras to the roboRIO simultaneously (for a short period in options 1 and 2, and continuously in option 3). It is theoretically possible for the library to avoid this simultaneity in the option 2 case (only), but this is not currently implemented.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ In the following example a thread created in robotInit() gets the Camera Server

This introduces a number of rules that your image processing code must follow to efficiently and safely run on the RoboRIO:

* Your image processing code must be in its own file
* Your image processing code must be in its own file. It's easiest to just place it next to your ``robot.py``
* Never import the ``cscore`` package from your robot code, it will just waste memory
* Never import the ``wpilib`` or ``hal`` packages from your image processing file
* The camera code will be killed when the ``robot.py`` program exits. If you wish to perform cleanup, you should register an atexit handler.
* ``robotpy-cscore`` is not installed on the roboRIO by default, you need to update your ``pyproject.toml`` file to install it

.. warning:: ``wpilib`` may not be imported from two programs on the RoboRIO. If this happens, the second program will attempt to kill the first program.

Expand All @@ -85,4 +86,15 @@ In the following example a thread created in robotInit() gets the Camera Server
:lines: 12-55
:linenos:

You need to update ``pyproject.toml`` contents to include cscore in the robotpy-extras key (this only shows the portions you need to update):

.. code-block:: toml
[tool.robotpy]
...
# Add cscore to the robotpy-extras list
robotpy_extras = ["cscore"]
Notice that in these examples, the ``PutVideo()`` method writes the video to a named stream. To view that stream on SmartDashboard or Shuffleboard, select that named stream. In this case that is "Rectangle".
13 changes: 13 additions & 0 deletions source/docs/yearly-overview/known-issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ Issues with WPILib Dashboards and Simulation on Windows N Editions

**Solution:** Install the `Media Feature Pack <https://www.microsoft.com/en-us/software-download/mediafeaturepack>`__

Python - CameraServer/cscore runs out of memory on roboRIO 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**Issue:** When using CameraServer on a roboRIO 1, the image processing program will sometimes exit with a ``SIGABRT`` or "Error code 6" or a ``MemoryError``.

**Solution:** You may be able to workaround this issue by disabling the NI webserver using the following robotpy-installer command:

.. code-block:: shell
python -m robotpy installer niweb disable
.. seealso:: `Github issue <https://github.com/robotpy/mostrobotpy/issues/61>`__

Fixed in WPILib 2024.2.1
------------------------

Expand Down

0 comments on commit 30d8b1d

Please sign in to comment.