Open WesleyJ-128 opened 1 year ago
Instead of adding this logic to every motion profile class (we have two now), it should probably be refactored into a separate MathUtil function that operates on a goal and setpoint.
Here's the profile wrapping code: https://github.com/wpilibsuite/allwpilib/blob/main/wpimath/src/main/java/edu/wpi/first/math/controller/ProfiledPIDController.java#L344-L356 https://github.com/wpilibsuite/allwpilib/blob/main/wpimath/src/main/native/include/frc/controller/ProfiledPIDController.h#L309-L323
The function can go here: https://github.com/wpilibsuite/allwpilib/blob/main/wpimath/src/main/java/edu/wpi/first/math/MathUtil.java https://github.com/wpilibsuite/allwpilib/blob/main/wpimath/src/main/native/include/frc/MathUtil.h
This refactor would allow users to easily plumb the motion profile and PID controller themselves, so the profile implementation can be swapped out. Possible resolution to https://github.com/wpilibsuite/allwpilib/issues/5915.
Something like this is an option:
<State> State continuousProfileShortestGoal(double minimumPosition, double maximumPosition, State current, State goal);
but we can't really make it generic without a base class for the motion profile trajectory states, and adding that might be a breaking change that has to wait for 2025.
Perhaps things will get better after this refactor, which moves State to a common base class: https://github.com/jlmcmchl/allwpilib/blob/jmcmichael/motion-profile-rework/wpimath/src/main/java/edu/wpi/first/math/trajectory/MotionProfile.java
Is your feature request related to a problem? Please describe.
ProfiledPIDController
allows for a trapezoidal motion profile to be used on a system with continuous input. However,TrapezoidProfile
itself does not have this feature, meaning that using aTrapezoidProfile
to feed a different control loop, such as a smart motor controller on a continuous mechanism is not natively supported.Describe the solution you'd like Add an
enableContinuousInput()
method toTrapezoidProfile
. This should be trivial to implement by adding the same distance test and modulus addition logic thatPIDController
andProfiledPIDController
use to modify the given goal and setpoint at the beginning of theTrapezoidProfile
constructor.Describe alternatives you've considered In my particular case, a
ProfiledPIDController
should be usable, but I've been having issues getting it to function correctly. However, this is still a useful feature for anyone who wants to use motion profiling with a motor controller PID loop.Additional context My current solution. Note that here the maximum and minimum inputs have been hardcoded to pi and -pi. It should be simple to add the continuous input logic to the
TrapezoidProfile
constructor.If I was better able to test this and ensure it's working properly, I'd write a pull request instead.