TrapezoidProfile

class wpimath.trajectory.TrapezoidProfile(*args, **kwargs)

Bases: pybind11_object

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:

constraints = TrapezoidProfile.Constraints(kMaxV, kMaxA)
previousProfiledReference = initialReference

Run on update:

profile = TrapezoidProfile(constraints, unprofiledReference, previousProfiledReference)
previousProfiledReference = profile.calculate(timeSincePreviousUpdate)

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().

Overloaded function.

  1. __init__(self: wpimath._controls._controls.trajectory.TrapezoidProfile, constraints: wpimath._controls._controls.trajectory.TrapezoidProfile.Constraints) -> None

Constructs a TrapezoidProfile.

Parameters:

constraints – The constraints on the profile, like maximum velocity.

  1. __init__(self: wpimath._controls._controls.trajectory.TrapezoidProfile, constraints: wpimath._controls._controls.trajectory.TrapezoidProfile.Constraints, goal: wpimath._controls._controls.trajectory.TrapezoidProfile.State, initial: wpimath._controls._controls.trajectory.TrapezoidProfile.State = <wpimath._controls._controls.trajectory.TrapezoidProfile.State object at 0x7fd5a357c0b0>) -> None

Constructs a TrapezoidProfile.

Deprecated:

Pass the desired and current state into calculate instead of constructing a new TrapezoidProfile with the desired and current state

Parameters:
  • constraints – The constraints on the profile, like maximum velocity.

  • goal – The desired state when the profile is complete.

  • initial – The initial state (usually the current state).

class Constraints(maxVelocity: wpimath.units.units_per_second, maxAcceleration: wpimath.units.units_per_second_squared)

Bases: pybind11_object

Profile constraints.

Constructs constraints for a Trapezoid Profile.

Parameters:
  • maxVelocity – Maximum velocity.

  • maxAcceleration – Maximum acceleration.

property maxAcceleration wpimath.units.units_per_second_squared

Maximum acceleration.

property maxVelocity wpimath.units.units_per_second

Maximum velocity.

class State(position: float = 0, velocity: wpimath.units.units_per_second = 0)

Bases: pybind11_object

Profile state.

property position float

The position at this state.

property velocity wpimath.units.units_per_second

The velocity at this state.

calculate(*args, **kwargs)

Overloaded function.

  1. calculate(self: wpimath._controls._controls.trajectory.TrapezoidProfile, t: wpimath.units.seconds) -> wpimath._controls._controls.trajectory.TrapezoidProfile.State

Calculates the position and velocity for the profile at a time t where the current state is at time t = 0.

Deprecated:

Pass the desired and current state into calculate instead of constructing a new TrapezoidProfile with the desired and current state

Parameters:

t – How long to advance from the current state toward the desired state.

Returns:

The position and velocity of the profile at time t.

  1. calculate(self: wpimath._controls._controls.trajectory.TrapezoidProfile, t: wpimath.units.seconds, current: wpimath._controls._controls.trajectory.TrapezoidProfile.State, goal: wpimath._controls._controls.trajectory.TrapezoidProfile.State) -> wpimath._controls._controls.trajectory.TrapezoidProfile.State

Calculates the position and velocity for the profile at a time t where the current state is at time t = 0.

Parameters:
  • t – How long 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.

isFinished(t: wpimath.units.seconds) bool

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.

timeLeftUntil(target: float) wpimath.units.seconds

Returns the time left until a target distance in the profile is reached.

Parameters:

target – The target distance.

Returns:

The time left until a target distance in the profile is reached.

totalTime() wpimath.units.seconds

Returns the total time the profile takes to reach the goal.

Returns:

The total time the profile takes to reach the goal.