mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpimath] Add DCMotor.getCurrent() overload accepting torque (#7132)
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user