# Módulo de distribución de energía

The CTRE Power Distribution Panel (PDP) and Rev Power Distribution Hub (PDH) can use their CAN connectivity to communicate a wealth of status information regarding the robot’s power use to the roboRIO, for use in user code. This has the capability to report current temperature, the bus voltage, the total robot current draw, the total robot energy use, and the individual current draw of each device power channel. This data can be used for a number of advanced control techniques, such as motor limiting and brownout avoidance.

## Creating a Power Distribution Object

To use the either Power Distribution module, create an instance of the PowerDistribution class (Java, C++). 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.

PowerDistribution examplePD = new PowerDistribution();
PowerDistribution examplePD = new PowerDistribution(0, ModuleType.kCTRE);
PowerDistribution examplePD = new PowerDistribution(1, 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.

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.

## Lectura del voltaje del bus

32    // Get the voltage going into the PDP, in Volts.
33    // The PDP returns the voltage in increments of 0.05 Volts.
34    double voltage = m_pdp.getVoltage();
35    SmartDashboard.putNumber("Voltage", voltage);


Monitorear el voltaje del bus puede ser útil para (entre otras cosas) detectar cuando el robot está cerca de un apagón, de modo que se pueden tomar medidas para evitar el apagón de manera controlada. Consulte el documento roboRIO Brownouts document para obtener más información.

## Leyendo la temperatura

37    // Retrieves the temperature of the PDP, in degrees Celsius.
38    double temperatureCelsius = m_pdp.getTemperature();
39    SmartDashboard.putNumber("Temperature", temperatureCelsius);


El monitoreo de la temperatura puede ser útil para detectar si el robot ha consumido demasiada energía y necesita apagarse por un tiempo, o si hay un problema de cableado corto u otro.

## Reading the Total Current, Power, and Energy

41    // Get the total current of all channels.
42    double totalCurrent = m_pdp.getTotalCurrent();
43    SmartDashboard.putNumber("Total Current", totalCurrent);
44
45    // Get the total power of all channels.
46    // Power is the bus voltage multiplied by the current with the units Watts.
47    double totalPower = m_pdp.getTotalPower();
48    SmartDashboard.putNumber("Total Power", totalPower);
49
50    // Get the total energy of all channels.
51    // Energy is the power summed over time with units Joules.
52    double totalEnergy = m_pdp.getTotalEnergy();
53    SmartDashboard.putNumber("Total Energy", totalEnergy);


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.

## Lectura de corrientes de canales individuales

The PDP/PDH also allows users to monitor the current drawn by the individual device power channels. You can read the current on any of the 16 PDP channels (0-15) or 24 PDH channels (0-23).

26    // Get the current going through channel 7, in Amperes.
27    // The PDP returns the current in increments of 0.125A.
28    // At low currents the current readings tend to be less accurate.
29    double current7 = m_pdp.getCurrent(7);
30    SmartDashboard.putNumber("Current Channel 7", current7);


El monitoreo de las corrientes de corriente de dispositivos individuales puede ser útil para detectar cortocircuitos o motores estancados.

## Using the Switchable Channel (PDH)

The REV PDH has one channel that can be switched on or off to control custom circuits.

examplePD.setSwitchableChannel(true);
examplePD.setSwitchableChannel(false);