Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python docs for FRC #2323

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 78 additions & 10 deletions source/docs/software/vscode-overview/deploying-robot-code.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,88 @@
Building and Deploying Robot Code
=================================

Robot projects must be compiled ("built") and deployed in order to run on the roboRIO. Since the code is not compiled natively on the robot controller, this is known as "cross-compilation."
.. tabs::

To build and deploy a robot project, do one of:
.. group-tab:: Java/C++

1. Open the Command Palette and enter/select "Build Robot Code"
2. Open the shortcut menu indicated by the ellipses in the top right corner of the VS Code window and select "Build Robot Code"
3. Right-click on the build.gradle file in the project hierarchy and select "Build Robot Code"
Robot projects must be compiled ("built") and deployed in order to run on the roboRIO. Since the code is not compiled natively on the robot controller, this is known as "cross-compilation."

.. image:: images/deploying-robot-code/building-code-options.png
To build and deploy a robot project, do one of:

Deploy robot code by selecting "Deploy Robot Code" from any of the three locations from the previous instructions. That will build (if necessary) and deploy the robot program to the roboRIO.
1. Open the Command Palette and enter/select "Build Robot Code"
2. Open the shortcut menu indicated by the ellipses in the top right corner of the VS Code window and select "Build Robot Code"
3. Right-click on the build.gradle file in the project hierarchy and select "Build Robot Code"

.. warning:: Avoid powering off the robot while deploying robot code. Interrupting the deployment process can corrupt the roboRIO filesystem and prevent your code from working until the roboRIO is :doc:`re-imaged </docs/zero-to-robot/step-3/imaging-your-roborio>`.
.. image:: images/deploying-robot-code/building-code-options.png

If successful, we will see a "Build Successful" message (1) and the RioLog will open with the console output from the robot program as it runs (2).
Deploy robot code by selecting "Deploy Robot Code" from any of the three locations from the previous instructions. That will build (if necessary) and deploy the robot program to the roboRIO.

.. image:: images/deploying-robot-code/build-successful.png
.. warning:: Avoid powering off the robot while deploying robot code. Interrupting the deployment process can corrupt the roboRIO filesystem and prevent your code from working until the roboRIO is :doc:`re-imaged </docs/zero-to-robot/step-3/imaging-your-roborio>`.

If successful, we will see a "Build Successful" message (1) and the RioLog will open with the console output from the robot program as it runs (2).

.. image:: images/deploying-robot-code/build-successful.png

.. group-tab:: Python

.. note:: Before deploying the code to your robot, you must start by :ref:`installing RobotPy on your roboRIO <docs/zero-to-robot/step-3/installing-robotpy:RobotPy installation on roboRIO>`

To deploy code to your robot, you can simply run the following command and it will upload the code and start it immediately.

.. tabs::

.. group-tab:: Windows

.. code-block:: sh

py -3 robot.py deploy

.. group-tab:: Linux/macOS

.. code-block:: sh

python3 robot.py deploy

Through VS Code, a terminal is accessible by opening your :guilabel:`robot.py` file and then clicking Terminal -> New Terminal from the top menu.

This command will first run any unit tests on your robot code, and if they pass then it will upload the robot code to the roboRIO. Running the tests is really important, it allows you to catch errors in your code before you run it on the robot.

You can watch your robot code's output (and see any problems) with netconsole by using the Driver Station Log Viewer or `pynetconsole <https://github.com/robotpy/pynetconsole>`__. You can use netconsole and the normal FRC tools to interact with the running robot code.

**Immediate feedback via Netconsole**

When deploying the code to the roboRIO, you can have immediate feedback by adding the option :guilabel:`--nc`. This will cause the deploy command to show your program's console output, by launching a netconsole listener.

.. tabs::

.. group-tab:: Windows

.. code-block:: sh

py -3 robot.py deploy --nc

.. group-tab:: Linux/macOS

.. code-block:: sh

python3 robot.py deploy --nc

.. Note:: This requires the driver station software to be connected to your robot

**Skipping Tests**

In the event that the tests are failing but you want to upload the code anyway, you can skip them by adding the option :guilabel:`--skip-tests`.

.. tabs::

.. group-tab:: Windows

.. code-block:: sh

py -3 robot.py deploy --skip-tests

.. group-tab:: Linux/macOS

.. code-block:: sh

python3 robot.py deploy --skip-tests
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ WPILib Commands in Visual Studio Code
=====================================
This document contains a complete list of the commands provided by the WPILib VS Code Extension and what they do.

.. note:: The current Python integration is not compatible with the WPILib commands in VS Code. Refer to :ref:`Building and Deploying Robot Code<docs/software/vscode-overview/deploying-robot-code:Building and Deploying Robot Code>` instead.

To access these commands, press Ctrl+Shift+P to open the Command Palette, then begin typing the command name as shown here to filter the list of commands. Click on the command name to execute it.

- **WPILib: Build Robot Code** - Builds open project using GradleRIO
Expand Down
45 changes: 35 additions & 10 deletions source/docs/software/wpilib-tools/robot-simulation/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Introduction to Robot Simulation

Often a team may want to test their code without having an actual robot available. WPILib provides teams with the ability to simulate various robot features using simple gradle commands.

If you are using Python, you can skip to :ref:`Running Robot Simulation <docs/software/wpilib-tools/robot-simulation/introduction:Running Robot Simulation>`

Enabling Desktop Support
------------------------

Expand Down Expand Up @@ -38,21 +40,44 @@ Ensure the :guilabel:`Desktop Development with C++` option is checked in the Vis
Running Robot Simulation
------------------------

Basic robot simulation can be run using VS Code. This can be done without using any commands by using VS Code's command palette.
.. tabs::

.. group-tab:: Java/C++

Basic robot simulation can be run using VS Code. This can be done without using any commands by using VS Code's command palette.

.. image:: images/vscode-run-simulation.png
:alt: Running robot simulation through VS Code

Your console output in Visual Studio Code should look like the below. However, teams probably will want to actually *test* their code versus just running the simulation. This can be done using :doc:`WPILib's Simulation GUI <simulation-gui>`.

.. code-block:: console

********** Robot program starting **********
Default disabledInit() method... Override me!
Default disabledPeriodic() method... Override me!
Default robotPeriodic() method... Override me!

.. important:: Simulation can also be run outside of VS Code using ``./gradlew simulateJava`` for Java or ``./gradlew simulateNative`` for C++.

.. group-tab:: Python

To run the GUI simulator, the easiest way is to open your :guilabel:`robot.py` file and start a new terminal by clicking Terminal -> New Terminal from the top menu. You can then execute the code with the :guilabel:`sim` argument.

.. tabs::

.. group-tab:: Windows

.. code-block:: sh

.. image:: images/vscode-run-simulation.png
:alt: Running robot simulation through VS Code
py -3 robot.py sim

Your console output in Visual Studio Code should look like the below. However, teams probably will want to actually *test* their code versus just running the simulation. This can be done using :doc:`WPILib's Simulation GUI <simulation-gui>`.
.. group-tab:: Linux/macOS

.. code-block:: console
.. code-block:: sh

********** Robot program starting **********
Default disabledInit() method... Override me!
Default disabledPeriodic() method... Override me!
Default robotPeriodic() method... Override me!
python3 robot.py sim

.. important:: Simulation can also be run outside of VS Code using ``./gradlew simulateJava`` for Java or ``./gradlew simulateNative`` for C++.

Running Robot Dashboards
------------------------
Expand Down
8 changes: 7 additions & 1 deletion source/docs/zero-to-robot/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ LabVIEW

- `NI Learn LabVIEW <https://www.ni.com/getting-started/labview-basics/>`__


Python
^^^^^^

- `W3Schools <https://www.w3schools.com/python/>`__

Zero to Robot
-------------

The remaining pages in this tutorial are designed to be completed in order to go from zero to a working basic robot. The documents will walk you through wiring your robot, installation of all needed software, configuration of hardware, and loading a basic example program that should allow your robot to operate. When you complete a page, simply click **Next** to navigate to the next page and continue with the process. When you're done, you can click **Next** to continue to an overview of WPILib in C++/Java or jump back to the home page using the logo at the top left to explore the rest of the content.
The remaining pages in this tutorial are designed to be completed in order to go from zero to a working basic robot. The documents will walk you through wiring your robot, installation of all needed software, configuration of hardware, and loading a basic example program that should allow your robot to operate. When you complete a page, simply click **Next** to navigate to the next page and continue with the process. When you're done, you can click **Next** to continue to an overview of WPILib in C++/Java/Python or jump back to the home page using the logo at the top left to explore the rest of the content.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion source/docs/zero-to-robot/step-2/labview-setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Installing LabVIEW for FRC (LabVIEW only)
=========================================

.. note:: This installation is for teams programming in LabVIEW or using NI Vision Assistant only. C++ and Java teams not using these features do not need to install LabVIEW and should proceed to :doc:`Installing the FRC Game Tools </docs/zero-to-robot/step-2/frc-game-tools>`.
.. note:: This installation is for teams programming in LabVIEW or using NI Vision Assistant only. C++, Java and Python teams not using these features do not need to install LabVIEW and should proceed to :doc:`Installing the FRC Game Tools </docs/zero-to-robot/step-2/frc-game-tools>`.

Download and installation times will vary widely with computer and internet connection specifications, however note that this process involves a large file download and installation and will likely take at least an hour to complete.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This article contains instructions/links to components you will want to gather i

.. tip:: This document compiles all the download links from the following documents to make it easier to install on offline computers or on multiple computers. If you are you installing on a single computer that is connected to the internet, you can skip this page.

.. note:: The order in which these tools are installed does not matter for Java and C++ teams. LabVIEW should be installed before the FRC Game Tools or 3rd Party Libraries.
.. note:: The order in which these tools are installed does not matter for Java, C++ and Python teams. LabVIEW should be installed before the FRC Game Tools or 3rd Party Libraries.

Documentation
-------------
Expand Down Expand Up @@ -47,6 +47,11 @@ Then click on the correct binary for your OS and architecture to begin the downl

.. note:: After downloading the Java/C++ WPILib installer, run it once while connected to the internet and select :guilabel:`Install for this User` then :guilabel:`Create VS Code zip to share with other computers/OSes for offline install` and save the downloaded VS Code zip file for future offline installations.

Python Teams
^^^^^^^^^^^^

There is no offline installation yet for the Python teams, please skip to :doc:`Installing the FRC Game Tools </docs/zero-to-robot/step-2/frc-game-tools>`.

3rd Party Libraries/Software
----------------------------

Expand Down
69 changes: 67 additions & 2 deletions source/docs/zero-to-robot/step-2/wpilib-setup.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WPILib Installation Guide
=========================

This guide is intended for Java and C++ teams. LabVIEW teams can skip to :doc:`labview-setup`. Additionally, the below tutorial shows Windows 10, but the steps are identical for all operating systems. Notes differentiating operating systems will be shown.
This guide is intended for Java, C++ and Python teams. LabVIEW teams can skip to :doc:`labview-setup`. Additionally, the below tutorial shows Windows 10, but the steps are identical for all operating systems. Notes differentiating operating systems will be shown.

Prerequisites
-------------
Expand All @@ -15,6 +15,16 @@ Supported Operating Systems and Architectures:

WPILib is designed to install to different folders for different years, so that it is not necessary to uninstall a previous version before installing this year's WPILib.

.. note::
**For Python users**

Python 3.8 or higher must be installed
* `Python for Windows <https://www.python.org/downloads/windows/>`__
* `Python for macOS <https://www.python.org/downloads/macos/>`__
* Python should already be installed for Linux users

All WPILib code is currently accessible through the Python Package :guilabel:`RobotPy`. updating the RobotPy version will overwrite the previously installed one. Consider using `venv <https://docs.python.org/3/library/venv.html>`__ if you want to keep distinct versions.

Downloading
-----------

Expand Down Expand Up @@ -154,6 +164,61 @@ Some operating systems require some final action to complete installation.

.. note:: Installing desktop tools and rebooting will create a folder on the desktop called ``YYYY WPILib Tools``, where ``YYYY`` is the current year. Desktop tool shortcuts are not available on Linux and macOS.


Additional Steps for Python Installation
----------------------------------------

.. tabs::

.. group-tab:: Windows 10+

Run the following command from cmd or Powershell to install RobotPy with all its optional and vendor packages:

.. code-block:: sh

py -3 -m pip install robotpy[all]

To upgrade, you can run this:

.. code-block:: sh

py -3 -m pip install --upgrade robotpy[all]

If you don't have administrative rights on your computer, either use `venv <https://docs.python.org/3/library/venv.html>`__, or you can install to the user site-packages directory:

.. code-block:: sh

py -3 -m pip install --user robotpy

.. group-tab:: Linux/macOS

On a Linux or macOS system that has pip installed, just run the following command from the Terminal application (may require admin rights):

.. code-block:: sh

pip3 install robotpy[all]

This will install RobotPy with all its optional and vendor packages.

To upgrade, you can run this:

.. code-block:: sh

pip3 install --upgrade robotpy[all]

If you don't have administrative rights on your computer, either use `venv <https://docs.python.org/3/library/venv.html>`__, or you can install to the user site-packages directory:

.. code-block:: sh

pip3 install --user robotpy

In VS Code, it is highly recommended to install the official Python extension that offers IntelliSense, Linting and more.

Access the extension menu on the left pane. Search for Python and install the official extension from Microsoft.

.. image:: images/wpilib-setup/python-ext.png
:alt: Access VS Code Extension menu, search for python and install the official Microsoft Python Extension.

Additional C++ Installation for Simulation
------------------------------------------

Expand Down Expand Up @@ -217,4 +282,4 @@ WPILib is designed to install to different folders for different years, so that
Troubleshooting
---------------

In case the installer fails, please open an issue on the installer repository. A link is available `here <https://github.com/wpilibsuite/wpilibinstaller-avalonia>`__. The installer should give a message on the cause of the error, please include this in the description of your issue.
In case the installer fails, please open an issue on the installer repository. Links are available `here (C++/Java) <https://github.com/wpilibsuite/wpilibinstaller-avalonia>`__ and `here (Python) <https://github.com/robotpy/robotpy-wpilib/issues>`__. The installer should give a message on the cause of the error, please include this in the description of your issue.
1 change: 1 addition & 0 deletions source/docs/zero-to-robot/step-3/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Step 3: Preparing Your Robot
roborio2-imaging
imaging-your-roborio
radio-programming
installing-robotpy
Loading