[wpimath] Refactor TrapezoidProfile API (#5457)

This commit is contained in:
Gold856
2023-07-19 20:25:10 -04:00
committed by GitHub
parent 72a4543493
commit 86e91e6724
24 changed files with 492 additions and 184 deletions

View File

@@ -4,6 +4,8 @@
#pragma once
#include <wpi/deprecated.h>
#include "units/time.h"
#include "wpimath/MathShared.h"
@@ -21,13 +23,14 @@ namespace frc {
* @code{.cpp}
* TrapezoidProfile::Constraints constraints{kMaxV, kMaxA};
* double previousProfiledReference = initialReference;
* TrapezoidProfile profile{constraints};
* @endcode
*
* Run on update:
* @code{.cpp}
* TrapezoidProfile profile{constraints, unprofiledReference,
* previousProfiledReference};
* previousProfiledReference = profile.Calculate(timeSincePreviousUpdate);
* previousProfiledReference = profile.Calculate(timeSincePreviousUpdate,
* unprofiledReference,
* previousProfiledReference);
* @endcode
*
* where `unprofiledReference` is free to change between calls. Note that when
@@ -71,13 +74,26 @@ class TrapezoidProfile {
bool operator==(const State&) const = default;
};
/**
* Construct a TrapezoidProfile.
*
* @param constraints The constraints on the profile, like maximum velocity.
*/
TrapezoidProfile(Constraints constraints); // NOLINT
/**
* Construct 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
*/
WPI_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}});
@@ -91,9 +107,25 @@ class TrapezoidProfile {
* where the beginning of the profile was at time t = 0.
*
* @param t The time since the beginning of the profile.
* @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")]]
State Calculate(units::second_t t) const;
/**
* Calculate the correct position and velocity for the profile at a time t
* where the beginning of the profile was at time t = 0.
*
* @param t The time since the beginning of the profile.
* @param goal The desired state when the profile is complete.
* @param current The initial state (usually the current state).
*/
State Calculate(units::second_t t, State goal, State current);
/**
* Returns the time left until a target distance in the profile is reached.
*
@@ -141,8 +173,9 @@ class TrapezoidProfile {
int m_direction;
Constraints m_constraints;
State m_initial;
State m_goal;
State m_current;
State m_goal; // TODO: remove
bool m_newAPI; // TODO: remove
units::second_t m_endAccel;
units::second_t m_endFullSpeed;