[wpimath] Add DCMotor.getCurrent() overload accepting torque (#7132)

This commit is contained in:
Benjamin Hall
2024-09-28 12:33:15 -04:00
committed by GitHub
parent eab93f4fdc
commit 6b1e656659
2 changed files with 19 additions and 0 deletions

View File

@@ -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.
*

View File

@@ -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.
*