diff --git a/wpimath/src/main/java/edu/wpi/first/math/system/plant/DCMotor.java b/wpimath/src/main/java/edu/wpi/first/math/system/plant/DCMotor.java index 6d18846f25..de8346d7dd 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/system/plant/DCMotor.java +++ b/wpimath/src/main/java/edu/wpi/first/math/system/plant/DCMotor.java @@ -82,6 +82,16 @@ public class DCMotor implements ProtobufSerializable, StructSerializable { return -1.0 / KvRadPerSecPerVolt / rOhms * speedRadiansPerSec + 1.0 / rOhms * voltageInputVolts; } + /** + * Calculate current drawn by motor for a given torque. + * + * @param torqueNm The torque produced by the motor. + * @return The current drawn by the motor. + */ + public double getCurrent(double torqueNm) { + return torqueNm / KtNMPerAmp; + } + /** * Calculate torque produced by the motor with a given current. * diff --git a/wpimath/src/main/native/include/frc/system/plant/DCMotor.h b/wpimath/src/main/native/include/frc/system/plant/DCMotor.h index a267945247..90dc8299ea 100644 --- a/wpimath/src/main/native/include/frc/system/plant/DCMotor.h +++ b/wpimath/src/main/native/include/frc/system/plant/DCMotor.h @@ -84,6 +84,15 @@ class WPILIB_DLLEXPORT DCMotor { return -1.0 / Kv / R * speed + 1.0 / R * inputVoltage; } + /** + * Returns current drawn by motor for a given torque. + * + * @param torque The torque produced by the motor. + */ + constexpr units::ampere_t Current(units::newton_meter_t torque) const { + return torque / Kt; + } + /** * Returns torque produced by the motor with a given current. *