[wpimath] Add FOC-enabled Falcon constants to the DCMotor class (#5469)

This commit is contained in:
Mihir Patankar
2023-07-24 23:16:48 -04:00
committed by GitHub
parent 1938251436
commit 552f4b76b5
2 changed files with 46 additions and 25 deletions

View File

@@ -21,10 +21,10 @@ public class DCMotor {
* Constructs a DC motor.
*
* @param nominalVoltageVolts Voltage at which the motor constants were measured.
* @param stallTorqueNewtonMeters Torque when stalled in Newton-meters.
* @param stallCurrentAmps Current draw when stalled in amps.
* @param freeCurrentAmps Current draw under no load in amps.
* @param freeSpeedRadPerSec Angular velocity under no load in radians per second.
* @param stallTorqueNewtonMeters Torque when stalled.
* @param stallCurrentAmps Current draw when stalled.
* @param freeCurrentAmps Current draw under no load.
* @param freeSpeedRadPerSec Angular velocity under no load.
* @param numMotors Number of motors in a gearbox.
*/
public DCMotor(
@@ -47,10 +47,10 @@ public class DCMotor {
}
/**
* Estimate the current being drawn by this motor.
* Calculate current drawn by motor with given speed and input voltage.
*
* @param speedRadiansPerSec The speed of the motor.
* @param voltageInputVolts The input voltage.
* @param speedRadiansPerSec The current angular velocity of the motor.
* @param voltageInputVolts The voltage being applied to the motor.
* @return The estimated current.
*/
public double getCurrent(double speedRadiansPerSec, double voltageInputVolts) {
@@ -58,20 +58,20 @@ public class DCMotor {
}
/**
* Calculate the torque produced by the motor for a given current.
* Calculate torque produced by the motor with a given current.
*
* @param currentAmpere The current drawn by the motor.
* @return The torque produced.
* @return The torque output.
*/
public double getTorque(double currentAmpere) {
return currentAmpere * KtNMPerAmp;
}
/**
* Calculate the voltage provided to the motor at a given torque and angular velocity.
* Calculate the voltage provided to the motor for a given torque and angular velocity.
*
* @param torqueNm The torque produced by the motor.
* @param speedRadiansPerSec The speed of the motor.
* @param speedRadiansPerSec The current angular velocity of the motor.
* @return The voltage of the motor.
*/
public double getVoltage(double torqueNm, double speedRadiansPerSec) {
@@ -79,11 +79,11 @@ public class DCMotor {
}
/**
* Calculate the speed of the motor at a given torque and input voltage.
* Calculates the angular speed produced by the motor at a given torque and input voltage.
*
* @param torqueNm The torque produced by the motor.
* @param voltageInputVolts The voltage applied to the motor.
* @return The speed of the motor.
* @return The angular speed of the motor.
*/
public double getSpeed(double torqueNm, double voltageInputVolts) {
return voltageInputVolts * KvRadPerSecPerVolt
@@ -227,6 +227,18 @@ public class DCMotor {
12, 4.69, 257, 1.5, Units.rotationsPerMinuteToRadiansPerSecond(6380.0), numMotors);
}
/**
* Return a gearbox of Falcon 500 motors with FOC (Field-Oriented Control) enabled.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of Falcon 500 FOC enabled motors.
*/
public static DCMotor getFalcon500Foc(int numMotors) {
// https://store.ctr-electronics.com/falcon-500-powered-by-talon-fx/
return new DCMotor(
12, 5.84, 304, 1.5, Units.rotationsPerMinuteToRadiansPerSecond(6080.0), numMotors);
}
/**
* Return a gearbox of Romi/TI_RSLK MAX motors.
*