Skip to content

Commit

Permalink
Adding Python to LV Dashboard docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondaming committed Jan 6, 2024
1 parent 57731c9 commit fba04c5
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 61 deletions.
2 changes: 1 addition & 1 deletion source/docs/software/dashboards/dashboard-intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Specific Dashboards (oldest to newest)

.. note:: SmartDashboard and Shuffleboard have a long history of aiding FRC teams. However, they do not have a person to maintain them so are not receiving bug fixes or improvements. Notably, Shuffleboard may experience performance issues on some machines under certain scenarios. PRs from external contributors will be reviewed.

:ref:`LabVIEW Dashboard <docs/software/dashboards/labview-dashboard/index:LabVIEW Dashboard>` (Driver / Programming) - easy to use and provides a lot of features straight out of the box like: camera streams, autonomous selection, and joystick feedback. It can be customized using LabVIEW by creating a new Dashboard project. While it :ref:`can be used <docs/software/dashboards/labview-dashboard/using-the-labview-dashboard-with-c++-java-code:Using the LabVIEW Dashboard with C++/Java Code>` by Java or C++ teams, they generally prefer SmartDashboard or Shuffleboard which can be customized in their respective language.
:ref:`LabVIEW Dashboard <docs/software/dashboards/labview-dashboard/index:LabVIEW Dashboard>` (Driver / Programming) - easy to use and provides a lot of features straight out of the box like: camera streams, autonomous selection, and joystick feedback. It can be customized using LabVIEW by creating a new Dashboard project. While it :ref:`can be used <docs/software/dashboards/labview-dashboard/using-the-labview-dashboard-with-c++-java-code:Using the LabVIEW Dashboard with C++, Java, or Python Code>` by Java or C++ teams, they generally prefer SmartDashboard or Shuffleboard which can be customized in their respective language.

:ref:`SmartDashboard <docs/software/dashboards/smartdashboard/index:SmartDashboard>` (Driver) - simple and efficient dashboard that uses relatively few computer resources. It does not have the fancy look or some of the features Shuffleboard has, but it displays network tables data with a variety of widgets without bogging down the driver station computer.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
LabVIEW Dashboard
=================

The LabVIEW Dashboard is easy to use and provides a lot of features straight out of the box like: camera streams, autonomous selection, and joystick feedback. It can be customized using LabVIEW by creating a new Dashboard project. While it :ref:`can be used <docs/software/dashboards/labview-dashboard/using-the-labview-dashboard-with-c++-java-code:Using the LabVIEW Dashboard with C++/Java Code>` by Java or C++ teams, they generally prefer SmartDashboard or Shuffleboard which can be customized in their respective language.
The LabVIEW Dashboard is easy to use and provides a lot of features straight out of the box like: camera streams, autonomous selection, and joystick feedback. It can be customized using LabVIEW by creating a new Dashboard project. While it :ref:`can be used <docs/software/dashboards/labview-dashboard/using-the-labview-dashboard-with-c++-java-code:Using the LabVIEW Dashboard with C++, Java, or Python Code>` by Java, C++, or Python teams, they generally prefer SmartDashboard or Shuffleboard which can be customized in their respective language.

.. toctree::
:maxdepth: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Using the LabVIEW Dashboard with C++/Java Code
==============================================
Using the LabVIEW Dashboard with C++, Java, or Python Code
==========================================================

The default LabVIEW Dashboard utilizes :term:`NetworkTables` to pass values and is therefore compatible with C++ and Java robot programs. This article covers the keys and value ranges to use to work with the Dashboard.
The default LabVIEW Dashboard utilizes :term:`NetworkTables` to pass values and is therefore compatible with C++, Java, and Python robot programs. This article covers the keys and value ranges to use to work with the Dashboard.

Drive Tab
---------
Expand All @@ -12,59 +12,87 @@ The :guilabel:`Select Autonomous...` dropdown can be used so show the available

.. tab-set-code::

.. code-block:: java
.. code-block:: java
SmartDashboard.putStringArray("Auto List", {"Drive Forwards", "Drive Backwards", "Shoot"});
SmartDashboard.putStringArray("Auto List", {"Drive Forwards", "Drive Backwards", "Shoot"});
// At the beginning of auto
String autoName = SmartDashboard.getString("Auto Selector", "Drive Forwards") // This would make "Drive Forwards the default auto
switch(autoName) {
case "Drive Forwards":
// auto here
case "Drive Backwards":
// auto here
case "Shoot":
// auto here
}
// At the beginning of auto
String autoName = SmartDashboard.getString("Auto Selector", "Drive Forwards") // This would make "Drive Forwards the default auto
switch(autoName) {
case "Drive Forwards":
// auto here
case "Drive Backwards":
// auto here
case "Shoot":
// auto here
}
.. code-block:: c++
.. code-block:: c++

frc::SmartDashboard::PutStringArray("Auto List", {"Drive Forwards", "Drive Backwards", "Shoot"});
frc::SmartDashboard::PutStringArray("Auto List", {"Drive Forwards", "Drive Backwards", "Shoot"});

// At the beginning of auto
String autoName = SmartDashboard.GetString("Auto Selector", "Drive Forwards") // This would make "Drive Forwards the default auto
switch(autoName) {
case "Drive Forwards":
// auto here
case "Drive Backwards":
// auto here
case "Shoot":
// auto here
}
// At the beginning of auto
String autoName = SmartDashboard.GetString("Auto Selector", "Drive Forwards") // This would make "Drive Forwards the default auto
switch(autoName) {
case "Drive Forwards":
// auto here
case "Drive Backwards":
// auto here
case "Shoot":
// auto here
}

.. code-block:: python
from wpilib import SmartDashboard
SmartDashboard.putStringArray("Auto List", ["Drive Forwards", "Drive Backwards", "Shoot"])
# At the beginning of auto
autoName = SmartDashboard.getString("Auto Selector", "Drive Forwards") # This would make "Drive Forwards the default auto
match autoName:
case "Drive Forwards":
# auto here
case "Drive Backwards":
# auto here
case "Shoot":
# auto here
Sending to the "Gyro" NetworkTables entry will populate the gyro here.

.. tab-set-code::

.. code-block:: java
.. code-block:: java
SmartDashboard.putNumber("Gyro", drivetrain.getHeading());
.. code-block:: c++

frc::SmartDashboard::PutNumber("Gyro", Drivetrain.GetHeading());

SmartDashboard.putNumber("Gyro", drivetrain.getHeading());
.. code-block:: python
.. code-block:: c++
from wpilib import SmartDashboard
frc::SmartDashboard::PutNumber("Gyro", Drivetrain.GetHeading());
SmartDashboard.putNumber("Gyro", self.drivetrain.getHeading())
There are four outputs that show the motor power to the drivetrain. This is configured for 2 motors per side and a tank style drivetrain. This is done by setting "RobotDrive Motors" like the example below.

.. tab-set-code::

.. code-block:: java
.. code-block:: java
SmartDashboard.putNumberArray("RobotDrive Motors", {drivetrain.getLeftFront(), drivetrain.getRightFront(), drivetrain.getLeftBack(), drivetrain.getRightBack()});
SmartDashboard.putNumberArray("RobotDrive Motors", {drivetrain.getLeftFront(), drivetrain.getRightFront(), drivetrain.getLeftBack(), drivetrain.getRightBack()});
.. code-block:: c++
.. code-block:: c++

frc::SmartDashboard::PutNumberArray("Gyro", {drivetrain.GetLeftFront(), drivetrain.GetRightFront(), drivetrain.GetLeftBack(), drivetrain.GetRightBack()});
frc::SmartDashboard::PutNumberArray("Gyro", {drivetrain.GetLeftFront(), drivetrain.GetRightFront(), drivetrain.GetLeftBack(), drivetrain.GetRightBack()});

.. code-block:: python
from wpilib import SmartDashboard
SmartDashboard.putNumberArray("RobotDrive Motors", [self.drivetrain.getLeftFront(), self.drivetrain.getRightFront(), self.drivetrain.getLeftBack(), self.drivetrain.getRightBack()])
Basic Tab
---------
Expand All @@ -82,25 +110,37 @@ The strings are labeled top-to-bottom, left-to-right from "DB/String 0" to "DB/S

.. tab-set-code::

.. code-block:: java
.. code-block:: java
SmartDashboard.putString("DB/String 0", "My 21 Char TestString");
SmartDashboard.putString("DB/String 0", "My 21 Char TestString");
.. code-block:: c++

.. code-block:: c++
frc::SmartDashboard::PutString("DB/String 0", "My 21 Char TestString");

frc::SmartDashboard::PutString("DB/String 0", "My 21 Char TestString");
.. code-block:: python
from wpilib import SmartDashboard
SmartDashboard.putString("DB/String 0", "My 21 Char TestString")
To read string data entered on the Dashboard:

.. tab-set-code::

.. code-block:: java
.. code-block:: java
String dashData = SmartDashboard.getString("DB/String 0", "myDefaultData");
String dashData = SmartDashboard.getString("DB/String 0", "myDefaultData");
.. code-block:: c++

.. code-block:: c++
std::string dashData = frc::SmartDashboard::GetString("DB/String 0", "myDefaultData");

std::string dashData = frc::SmartDashboard::GetString("DB/String 0", "myDefaultData");
.. code-block:: python
from wpilib import SmartDashboard
dashData = SmartDashboard.getString("DB/String 0", "myDefaultData")
Buttons and LEDs
^^^^^^^^^^^^^^^^
Expand All @@ -111,25 +151,37 @@ The Buttons and LEDs are boolean values and are labeled top-to-bottom from "DB/B

.. tab-set-code::

.. code-block:: java
.. code-block:: java
SmartDashboard.putBoolean("DB/Button 0", true);
.. code-block:: c++

SmartDashboard.putBoolean("DB/Button 0", true);
frc::SmartDashboard::PutBoolean("DB/Button 0", true);

.. code-block:: c++
.. code-block:: python
frc::SmartDashboard::PutBoolean("DB/Button 0", true);
from wpilib import SmartDashboard
SmartDashboard.putBoolean("DB/Button 0", true)
To read from the Buttons: (default value is false)

.. tab-set-code::

.. code-block:: java
.. code-block:: java
boolean buttonValue = SmartDashboard.getBoolean("DB/Button 0", false);
.. code-block:: c++

boolean buttonValue = SmartDashboard.getBoolean("DB/Button 0", false);
bool buttonValue = frc::SmartDashboard::GetBoolean("DB/Button 0", false);

.. code-block:: c++
.. code-block:: python
bool buttonValue = frc::SmartDashboard::GetBoolean("DB/Button 0", false);
from wpilib import SmartDashboard
buttonValue = SmartDashboard.getBoolean("DB/Button 0", false)
Sliders
^^^^^^^
Expand All @@ -140,22 +192,34 @@ The Sliders are bi-directional analog (double) controls/indicators with a range

.. tab-set-code::

.. code-block:: java
.. code-block:: java
SmartDashboard.putNumber("DB/Slider 0", 2.58);
.. code-block:: c++

frc::SmartDashboard::PutNumber("DB/Slider 0", 2.58);

SmartDashboard.putNumber("DB/Slider 0", 2.58);
.. code-block:: python
.. code-block:: c++
from wpilib import SmartDashboard
frc::SmartDashboard::PutNumber("DB/Slider 0", 2.58);
SmartDashboard.putNumber("DB/Slider 0", 2.58)
To read values from the Dashboard into the robot program: (default value of 0.0)

.. tab-set-code::

.. code-block:: java
.. code-block:: java
double dashData = SmartDashboard.getNumber("DB/Slider 0", 0.0);
.. code-block:: c++

double dashData = frc::SmartDashboard::GetNumber("DB/Slider 0", 0.0);

double dashData = SmartDashboard.getNumber("DB/Slider 0", 0.0);
.. code-block:: python
.. code-block:: c++
from wpilib import SmartDashboard
double dashData = frc::SmartDashboard::GetNumber("DB/Slider 0", 0.0);
dashData = SmartDashboard.getNumber("DB/Slider 0", 0.0)

0 comments on commit fba04c5

Please sign in to comment.