mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpimath] Fix TrapezoidProfile limiting velocity incorrectly (#8030)
This commit is contained in:
@@ -77,8 +77,8 @@ class TrapezoidProfile {
|
||||
/**
|
||||
* Constructs constraints for a Trapezoid Profile.
|
||||
*
|
||||
* @param maxVelocity Maximum velocity.
|
||||
* @param maxAcceleration Maximum acceleration.
|
||||
* @param maxVelocity Maximum velocity, must be non-negative.
|
||||
* @param maxAcceleration Maximum acceleration, must be non-negative.
|
||||
*/
|
||||
constexpr Constraints(Velocity_t maxVelocity,
|
||||
Acceleration_t maxAcceleration)
|
||||
@@ -87,6 +87,10 @@ class TrapezoidProfile {
|
||||
wpi::math::MathSharedStore::ReportUsage(
|
||||
wpi::math::MathUsageId::kTrajectory_TrapezoidProfile, 1);
|
||||
}
|
||||
|
||||
if (maxVelocity < Velocity_t{0} || maxAcceleration < Acceleration_t{0}) {
|
||||
throw std::domain_error("Constraints must be non-negative");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -131,8 +135,9 @@ class TrapezoidProfile {
|
||||
m_direction = ShouldFlipAcceleration(current, goal) ? -1 : 1;
|
||||
m_current = Direct(current);
|
||||
goal = Direct(goal);
|
||||
if (m_current.velocity > m_constraints.maxVelocity) {
|
||||
m_current.velocity = m_constraints.maxVelocity;
|
||||
if (units::math::abs(m_current.velocity) > m_constraints.maxVelocity) {
|
||||
m_current.velocity =
|
||||
units::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