From 30d8b1db9d7e03fb19e818855d685fac5041852f Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Thu, 2 May 2024 21:27:41 -0400 Subject: [PATCH] Update python cscore/cameraserver documentation to be clearer about install (#2625) - Fixes #2624 --- .../roborio/using-multiple-cameras.rst | 26 +++++++++++++++++++ .../using-the-cameraserver-on-the-roborio.rst | 14 +++++++++- source/docs/yearly-overview/known-issues.rst | 13 ++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/source/docs/software/vision-processing/roborio/using-multiple-cameras.rst b/source/docs/software/vision-processing/roborio/using-multiple-cameras.rst index ba841d442d..c5468e3379 100644 --- a/source/docs/software/vision-processing/roborio/using-multiple-cameras.rst +++ b/source/docs/software/vision-processing/roborio/using-multiple-cameras.rst @@ -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 @@ -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:: @@ -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 @@ -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. diff --git a/source/docs/software/vision-processing/roborio/using-the-cameraserver-on-the-roborio.rst b/source/docs/software/vision-processing/roborio/using-the-cameraserver-on-the-roborio.rst index 5063a6dae1..ad9ca54929 100644 --- a/source/docs/software/vision-processing/roborio/using-the-cameraserver-on-the-roborio.rst +++ b/source/docs/software/vision-processing/roborio/using-the-cameraserver-on-the-roborio.rst @@ -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. @@ -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". diff --git a/source/docs/yearly-overview/known-issues.rst b/source/docs/yearly-overview/known-issues.rst index 157412e971..76f79565b8 100644 --- a/source/docs/yearly-overview/known-issues.rst +++ b/source/docs/yearly-overview/known-issues.rst @@ -155,6 +155,19 @@ Issues with WPILib Dashboards and Simulation on Windows N Editions **Solution:** Install the `Media Feature Pack `__ +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 `__ + Fixed in WPILib 2024.2.1 ------------------------