Class TrapezoidProfile
java.lang.Object
org.wpilib.math.trajectory.TrapezoidProfile
A trapezoid-shaped velocity profile.
While this class can be used for a profiled movement from start to finish, the intended usage is to filter a reference's dynamics based on trapezoidal velocity constraints. To compute the reference obeying this constraint, do the following.
Initialization:
TrapezoidProfile.Constraints constraints =
new TrapezoidProfile.Constraints(kMaxV, kMaxA);
TrapezoidProfile.State previousProfiledReference =
new TrapezoidProfile.State(initialReference, 0.0);
TrapezoidProfile profile = new TrapezoidProfile(constraints);
Run on update:
previousProfiledReference =
profile.calculate(timeSincePreviousUpdate, previousProfiledReference, unprofiledReference);
where `unprofiledReference` is free to change between calls. Note that when the unprofiled reference is within the constraints, `calculate()` returns the unprofiled reference unchanged.
Otherwise, a timer can be started to provide monotonic values for `calculate()` and to determine when the profile has completed via `isFinished()`.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classProfile constraints.static classProfile Timing.static classProfile state. -
Constructor Summary
ConstructorsConstructorDescriptionTrapezoidProfile(TrapezoidProfile.Constraints constraints) Constructs a TrapezoidProfile. -
Method Summary
Modifier and TypeMethodDescriptioncalculate(double t, TrapezoidProfile.State current, TrapezoidProfile.State goal) Calculates the position and velocity for the profile at a time t where the current state is at time t = 0.doubleduration()Returns the duration of the profile.booleanisFinished(double t) Returns true if the profile has reached the goal.doubletimeLeftUntil(TrapezoidProfile.State current, TrapezoidProfile.State goal) Returns the time to get between two states.
-
Constructor Details
-
TrapezoidProfile
Constructs a TrapezoidProfile.- Parameters:
constraints- The constraints on the profile, like maximum velocity.
-
-
Method Details
-
calculate
public TrapezoidProfile.State calculate(double t, TrapezoidProfile.State current, TrapezoidProfile.State goal) Calculates the position and velocity for the profile at a time t where the current state is at time t = 0.- Parameters:
t- The amount of time to advance from the current state toward the desired state.current- The current state.goal- The desired state when the profile is complete.- Returns:
- The position and velocity of the profile at time t.
-
timeLeftUntil
Returns the time to get between two states. This does not affect the internal variables, and as a result, may be used for states not on the active trajectory.- Parameters:
current- The current state.goal- The goal state.- Returns:
- The time to transition between the two states while respecting profile constraints.
-
duration
public double duration()Returns the duration of the profile.- Returns:
- The duration of the profile, or zero if no goal was set.
-
isFinished
public boolean isFinished(double t) Returns true if the profile has reached the goal.The profile has reached the goal if the time since the profile started has exceeded the profile's total time.
- Parameters:
t- The time since the beginning of the profile.- Returns:
- True if the profile has reached the goal.
-