mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpimath] Fix TrapezoidProfile limiting velocity incorrectly (#8030)
This commit is contained in:
@@ -253,4 +253,46 @@ class TrapezoidProfileTest {
|
||||
assertNear(profile.timeLeftUntil(0), 0, 1e-10);
|
||||
assertNear(profile.totalTime(), 0, 1e-10);
|
||||
}
|
||||
|
||||
@Test
|
||||
void initialVelocityConstraints() {
|
||||
TrapezoidProfile.Constraints constraints = new TrapezoidProfile.Constraints(0.75, 0.75);
|
||||
TrapezoidProfile.State goal = new TrapezoidProfile.State(10, 0);
|
||||
TrapezoidProfile.State state = new TrapezoidProfile.State(0, -10);
|
||||
|
||||
TrapezoidProfile profile = new TrapezoidProfile(constraints);
|
||||
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
state = profile.calculate(kDt, state, goal);
|
||||
assertLessThanOrEquals(Math.abs(state.velocity), Math.abs(constraints.maxVelocity));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void goalVelocityConstraints() {
|
||||
TrapezoidProfile.Constraints constraints = new TrapezoidProfile.Constraints(0.75, 0.75);
|
||||
TrapezoidProfile.State goal = new TrapezoidProfile.State(10, 5);
|
||||
TrapezoidProfile.State state = new TrapezoidProfile.State(0, 0.75);
|
||||
|
||||
TrapezoidProfile profile = new TrapezoidProfile(constraints);
|
||||
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
state = profile.calculate(kDt, state, goal);
|
||||
assertLessThanOrEquals(Math.abs(state.velocity), Math.abs(constraints.maxVelocity));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void negativeGoalVelocityConstraints() {
|
||||
TrapezoidProfile.Constraints constraints = new TrapezoidProfile.Constraints(0.75, 0.75);
|
||||
TrapezoidProfile.State goal = new TrapezoidProfile.State(10, -5);
|
||||
TrapezoidProfile.State state = new TrapezoidProfile.State(0, 0.75);
|
||||
|
||||
TrapezoidProfile profile = new TrapezoidProfile(constraints);
|
||||
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
state = profile.calculate(kDt, state, goal);
|
||||
assertLessThanOrEquals(Math.abs(state.velocity), Math.abs(constraints.maxVelocity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,3 +241,48 @@ TEST(TrapezoidProfileTest, InitalizationOfCurrentState) {
|
||||
EXPECT_NEAR_UNITS(profile.TimeLeftUntil(0_m), 0_s, 1e-10_s);
|
||||
EXPECT_NEAR_UNITS(profile.TotalTime(), 0_s, 1e-10_s);
|
||||
}
|
||||
|
||||
TEST(TrapezoidProfileTest, InitialVelocityConstraints) {
|
||||
frc::TrapezoidProfile<units::meter>::Constraints constraints{0.75_mps,
|
||||
0.75_mps_sq};
|
||||
frc::TrapezoidProfile<units::meter>::State goal{10_m, 0_mps};
|
||||
frc::TrapezoidProfile<units::meter>::State state{0_m, -10_mps};
|
||||
|
||||
frc::TrapezoidProfile<units::meter> profile{constraints};
|
||||
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
EXPECT_LE(units::math::abs(state.velocity),
|
||||
units::math::abs(constraints.maxVelocity));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TrapezoidProfileTest, GoalVelocityConstraints) {
|
||||
frc::TrapezoidProfile<units::meter>::Constraints constraints{0.75_mps,
|
||||
0.75_mps_sq};
|
||||
frc::TrapezoidProfile<units::meter>::State goal{10_m, 5_mps};
|
||||
frc::TrapezoidProfile<units::meter>::State state{0_m, 0.75_mps};
|
||||
|
||||
frc::TrapezoidProfile<units::meter> profile{constraints};
|
||||
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
EXPECT_LE(units::math::abs(state.velocity),
|
||||
units::math::abs(constraints.maxVelocity));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TrapezoidProfileTest, NegativeGoalVelocityConstraints) {
|
||||
frc::TrapezoidProfile<units::meter>::Constraints constraints{0.75_mps,
|
||||
0.75_mps_sq};
|
||||
frc::TrapezoidProfile<units::meter>::State goal{10_m, -5_mps};
|
||||
frc::TrapezoidProfile<units::meter>::State state{0_m, 0.75_mps};
|
||||
|
||||
frc::TrapezoidProfile<units::meter> profile{constraints};
|
||||
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
EXPECT_LE(units::math::abs(state.velocity),
|
||||
units::math::abs(constraints.maxVelocity));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user