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

Add Java unit support for RobotController #7278

Merged
merged 4 commits into from
Oct 28, 2024
Merged
Changes from 2 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
128 changes: 128 additions & 0 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@

package edu.wpi.first.wpilibj;

import static edu.wpi.first.units.Units.Amps;
import static edu.wpi.first.units.Units.Celsius;
import static edu.wpi.first.units.Units.Microseconds;
import static edu.wpi.first.units.Units.Volts;

import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.HALUtil;
import edu.wpi.first.hal.LEDJNI;
import edu.wpi.first.hal.PowerJNI;
import edu.wpi.first.hal.can.CANJNI;
import edu.wpi.first.hal.can.CANStatus;
import edu.wpi.first.units.measure.Current;
import edu.wpi.first.units.measure.Temperature;
import edu.wpi.first.units.measure.Time;
import edu.wpi.first.units.measure.Voltage;

/** Contains functions for roboRIO functionality. */
public final class RobotController {
Expand Down Expand Up @@ -76,6 +85,15 @@ public static long getFPGATime() {
return HALUtil.getFPGATime();
}

/**
* Read the microsecond timer in a measure from the FPGA.
*
* @return The current time according to the FPGA in a measure.
*/
public static Time getMeasureFPGATime() {
return Microseconds.of(HALUtil.getFPGATime());
}

/**
* Get the state of the "USER" button on the roboRIO.
*
Expand All @@ -98,6 +116,15 @@ public static double getBatteryVoltage() {
return PowerJNI.getVinVoltage();
}

/**
* Read the battery voltage in a measure.
*
* @return The battery voltage in a measure.
*/
public static Voltage getMeasureBatteryVoltage() {
return Volts.of(PowerJNI.getVinVoltage());
}

/**
* Gets a value indicating whether the FPGA outputs are enabled. The outputs may be disabled if
* the robot is disabled or e-stopped, the watchdog has expired, or if the roboRIO browns out.
Expand Down Expand Up @@ -154,6 +181,15 @@ public static double getInputVoltage() {
return PowerJNI.getVinVoltage();
}

/**
* Get the input voltage to the robot controller in a measure.
*
* @return The controller input voltage value in a measure.
*/
public static Voltage getMeasureInputVoltage() {
return Volts.of(PowerJNI.getVinVoltage());
}

/**
* Get the input current to the robot controller.
*
Expand All @@ -163,6 +199,15 @@ public static double getInputCurrent() {
return PowerJNI.getVinCurrent();
}

/**
* Get the input current to the robot controller in a measure.
*
* @return The controller input current value in a measure.
*/
public static Current getMeasureInputCurrent() {
return Amps.of(PowerJNI.getVinCurrent());
}

/**
* Get the voltage of the 3.3V rail.
*
Expand All @@ -172,6 +217,15 @@ public static double getVoltage3V3() {
return PowerJNI.getUserVoltage3V3();
}

/**
* Get the voltage in a measure of the 3.3V rail.
*
* @return The controller 3.3V rail voltage value in a measure.
*/
public static Voltage getMeasureVoltage3V3() {
return Volts.of(PowerJNI.getUserVoltage3V3());
}

/**
* Get the current output of the 3.3V rail.
*
Expand All @@ -181,6 +235,15 @@ public static double getCurrent3V3() {
return PowerJNI.getUserCurrent3V3();
}

/**
* Get the current output in a measure of the 3.3V rail.
*
* @return The controller 3.3V rail output current value in a measure.
*/
public static Current getMeasureCurrent3V3() {
return Amps.of(PowerJNI.getUserCurrent3V3());
}

/**
* Enables or disables the 3.3V rail.
*
Expand Down Expand Up @@ -218,6 +281,15 @@ public static double getVoltage5V() {
return PowerJNI.getUserVoltage5V();
}

/**
* Get the voltage in a measure of the 5V rail.
*
* @return The controller 5V rail voltage value in a measure.
*/
public static Voltage getMeasureVoltage5V() {
return Volts.of(PowerJNI.getUserVoltage5V());
}

/**
* Get the current output of the 5V rail.
*
Expand All @@ -227,6 +299,15 @@ public static double getCurrent5V() {
return PowerJNI.getUserCurrent5V();
}

/**
* Get the current output in a measure of the 5V rail.
*
* @return The controller 5V rail output current value in a measure.
*/
public static Current getMeasureCurrent5V() {
return Amps.of(PowerJNI.getUserCurrent5V());
}

/**
* Enables or disables the 5V rail.
*
Expand Down Expand Up @@ -264,6 +345,15 @@ public static double getVoltage6V() {
return PowerJNI.getUserVoltage6V();
}

/**
* Get the voltage in a measure of the 6V rail.
*
* @return The controller 6V rail voltage value in a measure.
*/
public static Voltage getMeasureVoltage6V() {
return Volts.of(PowerJNI.getUserVoltage6V());
}

/**
* Get the current output of the 6V rail.
*
Expand All @@ -273,6 +363,15 @@ public static double getCurrent6V() {
return PowerJNI.getUserCurrent6V();
}

/**
* Get the current output in a measure of the 6V rail.
*
* @return The controller 6V rail output current value in a measure.
*/
public static Current getMeasureCurrent6V() {
return Amps.of(PowerJNI.getUserCurrent6V());
}

/**
* Enables or disables the 6V rail.
*
Expand Down Expand Up @@ -315,6 +414,15 @@ public static double getBrownoutVoltage() {
return PowerJNI.getBrownoutVoltage();
}

/**
* Get the current brownout voltage setting in a measure.
*
* @return The brownout voltage in a measure.
*/
public static Voltage getMeasureBrownoutVoltage() {
return Volts.of(PowerJNI.getBrownoutVoltage());
}

/**
* Set the voltage the roboRIO will brownout and disable all outputs.
*
Expand All @@ -326,6 +434,17 @@ public static void setBrownoutVoltage(double brownoutVoltage) {
PowerJNI.setBrownoutVoltage(brownoutVoltage);
}

/**
* Set the voltage in a measure the roboRIO will brownout and disable all outputs.
*
* <p>Note that this only does anything on the roboRIO 2. On the roboRIO it is a no-op.
*
* @param brownoutVoltage The brownout voltage in a measure
*/
public static void setBrownoutVoltage(Voltage brownoutVoltage) {
PowerJNI.setBrownoutVoltage(brownoutVoltage.baseUnitMagnitude());
}

/**
* Get the current CPU temperature in degrees Celsius.
*
Expand All @@ -335,6 +454,15 @@ public static double getCPUTemp() {
return PowerJNI.getCPUTemp();
}

/**
* Get the current CPU temperature in a measure.
*
* @return current CPU temperature in a measure.
*/
public static Temperature getMeasureCPUTemp() {
return Celsius.of(PowerJNI.getCPUTemp());
}

/** State for the radio led. */
public enum RadioLEDState {
/** Off. */
Expand Down
Loading