mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpimath] Remove deprecated TrapezoidProfile constructors (#6558)
This commit is contained in:
@@ -102,23 +102,6 @@ class TrapezoidProfile {
|
||||
* @param constraints The constraints on the profile, like maximum velocity.
|
||||
*/
|
||||
TrapezoidProfile(Constraints constraints); // NOLINT
|
||||
|
||||
/**
|
||||
* Constructs a TrapezoidProfile.
|
||||
*
|
||||
* @param constraints The constraints on the profile, like maximum velocity.
|
||||
* @param goal The desired state when the profile is complete.
|
||||
* @param initial The initial state (usually the current state).
|
||||
* @deprecated Pass the desired and current state into calculate instead of
|
||||
* constructing a new TrapezoidProfile with the desired and current state
|
||||
*/
|
||||
[[deprecated(
|
||||
"Pass the desired and current state into calculate instead of "
|
||||
"constructing a new TrapezoidProfile with the desired and current "
|
||||
"state")]]
|
||||
TrapezoidProfile(Constraints constraints, State goal,
|
||||
State initial = State{Distance_t{0}, Velocity_t{0}});
|
||||
|
||||
TrapezoidProfile(const TrapezoidProfile&) = default;
|
||||
TrapezoidProfile& operator=(const TrapezoidProfile&) = default;
|
||||
TrapezoidProfile(TrapezoidProfile&&) = default;
|
||||
@@ -204,8 +187,6 @@ class TrapezoidProfile {
|
||||
|
||||
Constraints m_constraints;
|
||||
State m_current;
|
||||
State m_goal; // TODO: remove
|
||||
bool m_newAPI; // TODO: remove
|
||||
|
||||
units::second_t m_endAccel;
|
||||
units::second_t m_endFullSpeed;
|
||||
|
||||
@@ -12,89 +12,8 @@
|
||||
namespace frc {
|
||||
template <class Distance>
|
||||
TrapezoidProfile<Distance>::TrapezoidProfile(Constraints constraints)
|
||||
: m_constraints(constraints), m_newAPI(true) {}
|
||||
: m_constraints(constraints) {}
|
||||
|
||||
template <class Distance>
|
||||
TrapezoidProfile<Distance>::TrapezoidProfile(Constraints constraints,
|
||||
State goal, State initial)
|
||||
: m_direction{ShouldFlipAcceleration(initial, goal) ? -1 : 1},
|
||||
m_constraints(constraints),
|
||||
m_current(Direct(initial)),
|
||||
m_goal(Direct(goal)),
|
||||
m_newAPI(false) {
|
||||
if (m_current.velocity > m_constraints.maxVelocity) {
|
||||
m_current.velocity = m_constraints.maxVelocity;
|
||||
}
|
||||
|
||||
// Deal with a possibly truncated motion profile (with nonzero initial or
|
||||
// final velocity) by calculating the parameters as if the profile began and
|
||||
// ended at zero velocity
|
||||
units::second_t cutoffBegin =
|
||||
m_current.velocity / m_constraints.maxAcceleration;
|
||||
Distance_t cutoffDistBegin =
|
||||
cutoffBegin * cutoffBegin * m_constraints.maxAcceleration / 2.0;
|
||||
|
||||
units::second_t cutoffEnd = m_goal.velocity / m_constraints.maxAcceleration;
|
||||
Distance_t cutoffDistEnd =
|
||||
cutoffEnd * cutoffEnd * m_constraints.maxAcceleration / 2.0;
|
||||
|
||||
// Now we can calculate the parameters as if it was a full trapezoid instead
|
||||
// of a truncated one
|
||||
|
||||
Distance_t fullTrapezoidDist =
|
||||
cutoffDistBegin + (m_goal.position - m_current.position) + cutoffDistEnd;
|
||||
units::second_t accelerationTime =
|
||||
m_constraints.maxVelocity / m_constraints.maxAcceleration;
|
||||
|
||||
Distance_t fullSpeedDist =
|
||||
fullTrapezoidDist -
|
||||
accelerationTime * accelerationTime * m_constraints.maxAcceleration;
|
||||
|
||||
// Handle the case where the profile never reaches full speed
|
||||
if (fullSpeedDist < Distance_t{0}) {
|
||||
accelerationTime =
|
||||
units::math::sqrt(fullTrapezoidDist / m_constraints.maxAcceleration);
|
||||
fullSpeedDist = Distance_t{0};
|
||||
}
|
||||
|
||||
m_endAccel = accelerationTime - cutoffBegin;
|
||||
m_endFullSpeed = m_endAccel + fullSpeedDist / m_constraints.maxVelocity;
|
||||
m_endDeccel = m_endFullSpeed + accelerationTime - cutoffEnd;
|
||||
}
|
||||
|
||||
template <class Distance>
|
||||
typename TrapezoidProfile<Distance>::State
|
||||
TrapezoidProfile<Distance>::Calculate(units::second_t t) const {
|
||||
if (m_newAPI) {
|
||||
throw std::runtime_error(
|
||||
"Cannot use new constructor with deprecated Calculate()");
|
||||
}
|
||||
State result = m_current;
|
||||
|
||||
if (t < m_endAccel) {
|
||||
result.velocity += t * m_constraints.maxAcceleration;
|
||||
result.position +=
|
||||
(m_current.velocity + t * m_constraints.maxAcceleration / 2.0) * t;
|
||||
} else if (t < m_endFullSpeed) {
|
||||
result.velocity = m_constraints.maxVelocity;
|
||||
result.position += (m_current.velocity +
|
||||
m_endAccel * m_constraints.maxAcceleration / 2.0) *
|
||||
m_endAccel +
|
||||
m_constraints.maxVelocity * (t - m_endAccel);
|
||||
} else if (t <= m_endDeccel) {
|
||||
result.velocity =
|
||||
m_goal.velocity + (m_endDeccel - t) * m_constraints.maxAcceleration;
|
||||
units::second_t timeLeft = m_endDeccel - t;
|
||||
result.position =
|
||||
m_goal.position -
|
||||
(m_goal.velocity + timeLeft * m_constraints.maxAcceleration / 2.0) *
|
||||
timeLeft;
|
||||
} else {
|
||||
result = m_goal;
|
||||
}
|
||||
|
||||
return Direct(result);
|
||||
}
|
||||
template <class Distance>
|
||||
typename TrapezoidProfile<Distance>::State
|
||||
TrapezoidProfile<Distance>::Calculate(units::second_t t, State current,
|
||||
|
||||
Reference in New Issue
Block a user