Skip to content

Commit

Permalink
Add python CAN devices info (#2620)
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald authored Mar 29, 2024
1 parent 0f15c8b commit 3a7f5f1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion source/docs/software/can-devices/pneumatic-hub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Pneumatic Hub

The Pneumatic Hub (:term:`PH`) is a :term:`CAN`-based device that provides complete control over the compressor and up to 16 solenoids per module. The PH is integrated into WPILib through a series of classes that make it simple to use.

The closed loop control of the Compressor and Pressure switch is handled by the :code:`Compressor` class (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/Compressor.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_compressor.html>`__), and the Solenoids are handled by the :code:`Solenoid` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/Solenoid.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_solenoid.html>`__) and :code:`DoubleSolenoid` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/DoubleSolenoid.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_double_solenoid.html>`__) classes.
The closed loop control of the Compressor and Pressure switch is handled by the :code:`Compressor` class (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/Compressor.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_compressor.html>`__, :external:py:class:`Python <wpilib.Compressor>`), and the Solenoids are handled by the :code:`Solenoid` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/Solenoid.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_solenoid.html>`__, :external:py:class:`Python <wpilib.Solenoid>`) and :code:`DoubleSolenoid` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/DoubleSolenoid.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_double_solenoid.html>`__, :external:py:class:`Python <wpilib.DoubleSolenoid>`) classes.

An additional PH module can be used where the module's corresponding solenoids are differentiated by the module number in the constructors of the Solenoid and Compressor classes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Pneumatics Control Module

The Pneumatics Control Module (:term:`PCM`) is a :term:`CAN`-based device that provides complete control over the compressor and up to 8 solenoids per module. The PCM is integrated into WPILib through a series of classes that make it simple to use.

The closed loop control of the Compressor and Pressure switch is handled by the :code:`Compressor` class (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/Compressor.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_compressor.html>`__), and the Solenoids are handled by the :code:`Solenoid` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/Solenoid.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_solenoid.html>`__) and :code:`DoubleSolenoid` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/DoubleSolenoid.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_double_solenoid.html>`__) classes.
The closed loop control of the Compressor and Pressure switch is handled by the :code:`Compressor` class (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/Compressor.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_compressor.html>`__, :external:py:class:`Python <wpilib.Compressor>`), and the Solenoids are handled by the :code:`Solenoid` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/Solenoid.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_solenoid.html>`__, :external:py:class:`Python <wpilib.Solenoid>`) and :code:`DoubleSolenoid` (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/DoubleSolenoid.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_double_solenoid.html>`__, :external:py:class:`Python <wpilib.DoubleSolenoid>`) classes.

An additional PCM module can be used where the module's corresponding solenoids are differentiated by the module number in the constructors of the Solenoid and Compressor classes.

Expand Down
41 changes: 40 additions & 1 deletion source/docs/software/can-devices/power-distribution-module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The CTRE Power Distribution Panel (:term:`PDP`) and Rev Power Distribution Hub (
Creating a Power Distribution Object
------------------------------------

To use the either Power Distribution module, create an instance of the :code:`PowerDistribution` class (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/PowerDistribution.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_power_distribution.html>`__). With no arguments, the Power Distribution object will be detected, and must use CAN ID of 0 for CTRE or 1 for REV. If the CAN ID is non-default, additional constructors are available to specify the CAN ID and type.
To use the either Power Distribution module, create an instance of the :code:`PowerDistribution` class (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/PowerDistribution.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_power_distribution.html>`__, :external:py:class:`Python <wpilib.PowerDistribution>`). With no arguments, the Power Distribution object will be detected, and must use CAN ID of 0 for CTRE or 1 for REV. If the CAN ID is non-default, additional constructors are available to specify the CAN ID and type.

.. tab-set-code::

Expand All @@ -22,6 +22,14 @@ To use the either Power Distribution module, create an instance of the :code:`Po
PowerDistribution examplePD{0, frc::PowerDistribution::ModuleType::kCTRE};
PowerDistribution examplePD{1, frc::PowerDistribution::ModuleType::kRev};

.. code-block:: python
from wpilib import PowerDistribution
examplePD = PowerDistribution()
examplePD = PowerDistribution(0, PowerDistribution.ModuleType.kCTRE)
examplePD = PowerDistribution(1, PowerDistribution.ModuleType.kRev)
Note: it is not necessary to create a PowerDistribution object unless you need to read values from it. The board will work and supply power on all the channels even if the object is never created.

.. warning:: To enable voltage and current logging in the Driver Station, the CAN ID for the CTRE Power Distribution Panel *must* be 0, and for the REV Power Distribution Hub it *must* be 1.
Expand All @@ -45,6 +53,14 @@ Reading the Bus Voltage
:linenos:
:lineno-start: 28


.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/CANPDP/robot.py
:language: python
:lines: 34-37
:linenos:
:lineno-start: 34


Monitoring the bus voltage can be useful for (among other things) detecting when the robot is near a brownout, so that action can be taken to avoid brownout in a controlled manner. See the :doc:`roboRIO Brownouts document</docs/software/roborio-info/roborio-brownouts>` for more information.

Reading the Temperature
Expand All @@ -64,6 +80,12 @@ Reading the Temperature
:linenos:
:lineno-start: 33

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/CANPDP/robot.py
:language: python
:lines: 39-41
:linenos:
:lineno-start: 39

Monitoring the temperature can be useful for detecting if the robot has been drawing too much power and needs to be shut down for a while, or if there is a short or other wiring problem.

Reading the Total Current, Power, and Energy
Expand All @@ -83,6 +105,12 @@ Reading the Total Current, Power, and Energy
:linenos:
:lineno-start: 37

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/CANPDP/robot.py
:language: python
:lines: 43-55
:linenos:
:lineno-start: 43

Monitoring the total current, power and energy can be useful for controlling how much power is being drawn from the battery, both for preventing brownouts and ensuring that mechanisms have sufficient power available to perform the actions required. Power is the bus voltage multiplied by the current with the units Watts. Energy is the power summed over time with units Joules.

Reading Individual Channel Currents
Expand All @@ -104,6 +132,12 @@ The PDP/PDH also allows users to monitor the current drawn by the individual dev
:linenos:
:lineno-start: 22

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/CANPDP/robot.py
:language: python
:lines: 28-32
:linenos:
:lineno-start: 28

Monitoring individual device current draws can be useful for detecting shorts or stalled motors.

Using the Switchable Channel (PDH)
Expand All @@ -122,3 +156,8 @@ The REV PDH has one channel that can be switched on or off to control custom cir

examplePD.SetSwitchableChannel(true);
examplePD.SetSwitchableChannel(false);

.. code-block:: python
examplePD.setSwitchableChannel(True)
examplePD.setSwitchableChannel(False)

0 comments on commit 3a7f5f1

Please sign in to comment.