mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpimath] Reorder TrapezoidProfile.calculate() arguments (#5874)
ProfiledPIDController and ExponentialProfile use current, then goal. This isn't a breaking change because this overload of calculate() is new for 2024.
This commit is contained in:
@@ -34,7 +34,7 @@ TEST(TrapezoidProfileTest, ReachesGoal) {
|
||||
|
||||
frc::TrapezoidProfile<units::meter> profile{constraints};
|
||||
for (int i = 0; i < 450; ++i) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
}
|
||||
EXPECT_EQ(state, goal);
|
||||
}
|
||||
@@ -47,8 +47,8 @@ TEST(TrapezoidProfileTest, PosContinousUnderVelChange) {
|
||||
frc::TrapezoidProfile<units::meter>::State goal{12_m, 0_mps};
|
||||
|
||||
frc::TrapezoidProfile<units::meter> profile{constraints};
|
||||
auto state = profile.Calculate(kDt, goal,
|
||||
frc::TrapezoidProfile<units::meter>::State{});
|
||||
auto state = profile.Calculate(
|
||||
kDt, frc::TrapezoidProfile<units::meter>::State{}, goal);
|
||||
|
||||
auto lastPos = state.position;
|
||||
for (int i = 0; i < 1600; ++i) {
|
||||
@@ -57,7 +57,7 @@ TEST(TrapezoidProfileTest, PosContinousUnderVelChange) {
|
||||
profile = frc::TrapezoidProfile<units::meter>{constraints};
|
||||
}
|
||||
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
auto estimatedVel = (state.position - lastPos) / kDt;
|
||||
|
||||
if (i >= 400) {
|
||||
@@ -83,7 +83,7 @@ TEST(TrapezoidProfileTest, Backwards) {
|
||||
|
||||
frc::TrapezoidProfile<units::meter> profile{constraints};
|
||||
for (int i = 0; i < 400; ++i) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
}
|
||||
EXPECT_EQ(state, goal);
|
||||
}
|
||||
@@ -96,14 +96,14 @@ TEST(TrapezoidProfileTest, SwitchGoalInMiddle) {
|
||||
|
||||
frc::TrapezoidProfile<units::meter> profile{constraints};
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
}
|
||||
EXPECT_NE(state, goal);
|
||||
|
||||
goal = {0.0_m, 0.0_mps};
|
||||
profile = frc::TrapezoidProfile<units::meter>{constraints};
|
||||
for (int i = 0; i < 550; ++i) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
}
|
||||
EXPECT_EQ(state, goal);
|
||||
}
|
||||
@@ -117,13 +117,13 @@ TEST(TrapezoidProfileTest, TopSpeed) {
|
||||
|
||||
frc::TrapezoidProfile<units::meter> profile{constraints};
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
}
|
||||
EXPECT_NEAR_UNITS(constraints.maxVelocity, state.velocity, 10e-5_mps);
|
||||
|
||||
profile = frc::TrapezoidProfile<units::meter>{constraints};
|
||||
for (int i = 0; i < 2000; ++i) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
}
|
||||
EXPECT_EQ(state, goal);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ TEST(TrapezoidProfileTest, TimingToCurrent) {
|
||||
|
||||
frc::TrapezoidProfile<units::meter> profile{constraints};
|
||||
for (int i = 0; i < 400; i++) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
EXPECT_NEAR_UNITS(profile.TimeLeftUntil(state.position), 0_s, 2e-2_s);
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,7 @@ TEST(TrapezoidProfileTest, TimingToGoal) {
|
||||
auto predictedTimeLeft = profile.TimeLeftUntil(goal.position);
|
||||
bool reachedGoal = false;
|
||||
for (int i = 0; i < 400; i++) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
if (!reachedGoal && state == goal) {
|
||||
// Expected value using for loop index is just an approximation since the
|
||||
// time left in the profile doesn't increase linearly at the endpoints
|
||||
@@ -179,7 +179,7 @@ TEST(TrapezoidProfileTest, TimingBeforeGoal) {
|
||||
auto predictedTimeLeft = profile.TimeLeftUntil(1_m);
|
||||
bool reachedGoal = false;
|
||||
for (int i = 0; i < 400; i++) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
if (!reachedGoal &&
|
||||
(units::math::abs(state.velocity - 1_mps) < 10e-5_mps)) {
|
||||
EXPECT_NEAR(unit_cast<double>(predictedTimeLeft), i / 100.0, 2e-2);
|
||||
@@ -202,7 +202,7 @@ TEST(TrapezoidProfileTest, TimingToNegativeGoal) {
|
||||
auto predictedTimeLeft = profile.TimeLeftUntil(goal.position);
|
||||
bool reachedGoal = false;
|
||||
for (int i = 0; i < 400; i++) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
if (!reachedGoal && state == goal) {
|
||||
// Expected value using for loop index is just an approximation since the
|
||||
// time left in the profile doesn't increase linearly at the endpoints
|
||||
@@ -226,7 +226,7 @@ TEST(TrapezoidProfileTest, TimingBeforeNegativeGoal) {
|
||||
auto predictedTimeLeft = profile.TimeLeftUntil(-1_m);
|
||||
bool reachedGoal = false;
|
||||
for (int i = 0; i < 400; i++) {
|
||||
state = profile.Calculate(kDt, goal, state);
|
||||
state = profile.Calculate(kDt, state, goal);
|
||||
if (!reachedGoal &&
|
||||
(units::math::abs(state.velocity + 1_mps) < 10e-5_mps)) {
|
||||
EXPECT_NEAR(unit_cast<double>(predictedTimeLeft), i / 100.0, 2e-2);
|
||||
|
||||
Reference in New Issue
Block a user