diff --git a/wpilibc/src/main/native/cpp/motorcontrol/PWMMotorController.cpp b/wpilibc/src/main/native/cpp/motorcontrol/PWMMotorController.cpp index 7e1666b57a..1f1d2628ab 100644 --- a/wpilibc/src/main/native/cpp/motorcontrol/PWMMotorController.cpp +++ b/wpilibc/src/main/native/cpp/motorcontrol/PWMMotorController.cpp @@ -37,6 +37,10 @@ double PWMMotorController::Get() const { return m_pwm.GetSpeed() * (m_isInverted ? -1.0 : 1.0); } +units::volt_t PWMMotorController::GetVoltage() const { + return Get() * RobotController::GetBatteryVoltage(); +} + void PWMMotorController::SetInverted(bool isInverted) { m_isInverted = isInverted; } diff --git a/wpilibc/src/main/native/include/frc/motorcontrol/PWMMotorController.h b/wpilibc/src/main/native/include/frc/motorcontrol/PWMMotorController.h index 54a16bbd16..593d8aa858 100644 --- a/wpilibc/src/main/native/include/frc/motorcontrol/PWMMotorController.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/PWMMotorController.h @@ -72,6 +72,15 @@ class PWMMotorController : public MotorController, */ double Get() const override; + /** + * Gets the voltage output of the motor controller, nominally between -12 V + * and 12 V. + * + * @return The voltage of the motor controller, nominally between -12 V and 12 + * V. + */ + virtual units::volt_t GetVoltage() const; + void SetInverted(bool isInverted) override; bool GetInverted() const override; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMMotorController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMMotorController.java index cfb691df34..803f57d73b 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMMotorController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMMotorController.java @@ -9,6 +9,7 @@ import edu.wpi.first.util.sendable.SendableBuilder; import edu.wpi.first.util.sendable.SendableRegistry; import edu.wpi.first.wpilibj.MotorSafety; import edu.wpi.first.wpilibj.PWM; +import edu.wpi.first.wpilibj.RobotController; import java.util.ArrayList; /** Common base class for all PWM Motor Controllers. */ @@ -75,6 +76,15 @@ public abstract class PWMMotorController extends MotorSafety return m_pwm.getSpeed() * (m_isInverted ? -1.0 : 1.0); } + /** + * Gets the voltage output of the motor controller, nominally between -12 V and 12 V. + * + * @return The voltage of the motor controller, nominally between -12 V and 12 V. + */ + public double getVoltage() { + return get() * RobotController.getBatteryVoltage(); + } + @Override public void setInverted(boolean isInverted) { m_isInverted = isInverted;