wpilibsuite / allwpilib

Official Repository of WPILibJ and WPILibC
https://wpilib.org/
Other
1.08k stars 611 forks source link

Add physics simulation classes with torque input instead of voltage input #7130

Open calcmogul opened 1 month ago

calcmogul commented 1 month ago

Is your feature request related to a problem? Please describe. Current and torque control are becoming popular in CTRE's ecosystem, and our physics sim classes that use a voltage input aren't compatible with it.

Describe the solution you'd like The current class is hardcoded to use a voltage input, so it's cleanest to have separate classes for each model type. Of the two choices, current or torque, the latter is more generalizable to all kinds of mechanisms.

The torque input should be the direct actuator output, not what the mechanism experiences directly. Thus, the model should include a gear ratio.

Describe alternatives you've considered We could make all physics sim classes take a torque input, with add-ons for the motor dynamics to adapt voltage inputs to torque inputs (torque = −kₜ/(Rkᵥ) ω + kₜ/R V) or current inputs to torque inputs (torque = kₜ * current). Being able to isolate the actuator dynamics in this way is desirable.

narmstro2020 commented 1 month ago

I'd like to take a stab at this.

I have a PR for DCMotorSim waiting to be merged. My next logical steps were Elevator and Arm cleanup, but I can roll that into this as well, unless you would like separate PR's