Skip to content

Conversation

@tervay
Copy link
Contributor

@tervay tervay commented Nov 18, 2025

DCMotor wasn't using freeCurrent; this meant that trying to get the torque of a motor at freeSpeed would be a nonzero torque. This fixes it and adds a handful of possibly over-parameterized tests. (Wanted to make sure the math works on a variety of motor specs.)

Draft until I can fix all the tests.

@github-actions github-actions bot added the component: wpimath Math library label Nov 18, 2025
* @return The angular speed of the motor.
*/
public double getSpeed(double torqueNm, double voltageInputVolts) {
return voltageInputVolts * KvRadPerSecPerVolt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right, since plugging in a torque and voltage of zero results in a nonzero speed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

free current scales with voltage right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I was only ever taught about free current with respect to the free speed at the test voltage. I'm unable to find more info online either.

@calcmogul
Copy link
Member

calcmogul commented Nov 18, 2025

Shouldn't these equations also technically be multiplying the free current by the sign of the velocity? Otherwise, the free current makes the model behavior asymmetric for positive and negative speeds. The problem with doing that is the DC motor model becomes nonlinear instead of linear, which violates modeling assumptions everywhere else in the library.

@tervay
Copy link
Contributor Author

tervay commented Nov 18, 2025

Shouldn't these equations also technically be multiplying the free current by the sign of the velocity? Otherwise, the free current makes the model behavior asymmetric for positive and negative speeds.

probably, yes, in ReCalc I simply pretend negative speeds don't exist so i overlooked this. will fix

*/
public double getTorque(double currentAmpere) {
return currentAmpere * KtNMPerAmp;
return (currentAmpere - freeCurrentAmps) * KtNMPerAmp;
Copy link
Contributor

@bhall-ctre bhall-ctre Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns a negative torque at 0 A, but at 0 velocity, 0 A actually corresponds to 0 torque. (This and getSpeed() are what makes accounting for free current so difficult/annoying.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants