allwpilib icon indicating copy to clipboard operation
allwpilib copied to clipboard

TrapezoidProfile methods (somewhat) incompatible with new API

Open chauser opened this issue 5 months ago • 2 comments

Describe the bug Several of the methods in TrapezoidProfile have surprising behavior in some cases when used with the new (non-deprecated, single-argument) constructor because member variables they depend on are not initialized by the new constructor.

Java: timeLeftUntil uses m_current -- it will get a null pointer exception if called before calculate is called. totalTime uses m_endDeccel -- it will return zero if called before calculate is called. isFinished uses totalTime() -- it will return true if called before calculate is called. If calculate has been called, totalTime and timeLeftUntil return (I think) the times for a profile starting at the current state of the last call to calculate and ending at its goal state.

C++: Essentially the same issues when any of these methods is called before calculate. Since m_current isn't a reference it probably won't segfault, but m_current and m_endDeccel are uninitialized in the same cases and the actual behavior may be less predictable than for Java.

It is not clear to me how useful any of these stateful methods are when using the new API. Should they be deprecated as well? And if that were done, couldn't the whole API be boiled down to a single stateless method calculate(Constraints constraints, double t, State current, State goal)?

chauser avatar Mar 19 '24 19:03 chauser