[wpilib] Add getVoltage to PWMMotorController (#6044)

This commit is contained in:
Jade
2024-09-08 13:24:51 +08:00
committed by GitHub
parent 6e8feb154c
commit cd9922af49
3 changed files with 23 additions and 0 deletions

View File

@@ -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;