mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Fix TrapezoidProfile limiting velocity incorrectly (#8030)
This commit is contained in:
@@ -60,10 +60,14 @@ public class TrapezoidProfile {
|
||||
/**
|
||||
* Constructs constraints for a TrapezoidProfile.
|
||||
*
|
||||
* @param maxVelocity maximum velocity
|
||||
* @param maxAcceleration maximum acceleration
|
||||
* @param maxVelocity Maximum velocity, must be non-negative.
|
||||
* @param maxAcceleration Maximum acceleration, must be non-negative.
|
||||
*/
|
||||
public Constraints(double maxVelocity, double maxAcceleration) {
|
||||
if (maxVelocity < 0.0 || maxAcceleration < 0.0) {
|
||||
throw new IllegalArgumentException("Constraints must be non-negative");
|
||||
}
|
||||
|
||||
this.maxVelocity = maxVelocity;
|
||||
this.maxAcceleration = maxAcceleration;
|
||||
MathSharedStore.reportUsage(MathUsageId.kTrajectory_TrapezoidProfile, 1);
|
||||
@@ -128,8 +132,8 @@ public class TrapezoidProfile {
|
||||
m_current = direct(current);
|
||||
goal = direct(goal);
|
||||
|
||||
if (m_current.velocity > m_constraints.maxVelocity) {
|
||||
m_current.velocity = m_constraints.maxVelocity;
|
||||
if (Math.abs(m_current.velocity) > m_constraints.maxVelocity) {
|
||||
m_current.velocity = Math.copySign(m_constraints.maxVelocity, m_current.velocity);
|
||||
}
|
||||
|
||||
// Deal with a possibly truncated motion profile (with nonzero initial or
|
||||
|
||||
Reference in New Issue
Block a user