WPILibC++ 2024.3.2
frc::TrapezoidProfile< Distance > Class Template Reference

A trapezoid-shaped velocity profile. More...

#include <frc/trajectory/TrapezoidProfile.h>

Classes

class  Constraints
 Profile constraints. More...
 
class  State
 Profile state. More...
 

Public Types

using Distance_t = units::unit_t< Distance >
 
using Velocity = units::compound_unit< Distance, units::inverse< units::seconds > >
 
using Velocity_t = units::unit_t< Velocity >
 
using Acceleration = units::compound_unit< Velocity, units::inverse< units::seconds > >
 
using Acceleration_t = units::unit_t< Acceleration >
 

Public Member Functions

 TrapezoidProfile (Constraints constraints)
 Constructs a TrapezoidProfile. More...
 
 TrapezoidProfile (Constraints constraints, State goal, State initial=State{Distance_t{0}, Velocity_t{0}})
 Constructs a TrapezoidProfile. More...
 
 TrapezoidProfile (const TrapezoidProfile &)=default
 
TrapezoidProfileoperator= (const TrapezoidProfile &)=default
 
 TrapezoidProfile (TrapezoidProfile &&)=default
 
TrapezoidProfileoperator= (TrapezoidProfile &&)=default
 
State Calculate (units::second_t t) const
 Calculates the position and velocity for the profile at a time t where the current state is at time t = 0. More...
 
State Calculate (units::second_t t, State current, State goal)
 Calculates the position and velocity for the profile at a time t where the current state is at time t = 0. More...
 
units::second_t TimeLeftUntil (Distance_t target) const
 Returns the time left until a target distance in the profile is reached. More...
 
units::second_t TotalTime () const
 Returns the total time the profile takes to reach the goal. More...
 
bool IsFinished (units::second_t t) const
 Returns true if the profile has reached the goal. More...
 

Detailed Description

template<class Distance>
class frc::TrapezoidProfile< Distance >

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{kMaxV, kMaxA};
double previousProfiledReference = initialReference;
TrapezoidProfile profile{constraints};
Profile constraints.
Definition: TrapezoidProfile.h:58
A trapezoid-shaped velocity profile.
Definition: TrapezoidProfile.h:45

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

Member Typedef Documentation

◆ Acceleration

template<class Distance >
using frc::TrapezoidProfile< Distance >::Acceleration = units::compound_unit<Velocity, units::inverse<units::seconds> >

◆ Acceleration_t

template<class Distance >
using frc::TrapezoidProfile< Distance >::Acceleration_t = units::unit_t<Acceleration>

◆ Distance_t

template<class Distance >
using frc::TrapezoidProfile< Distance >::Distance_t = units::unit_t<Distance>

◆ Velocity

template<class Distance >
using frc::TrapezoidProfile< Distance >::Velocity = units::compound_unit<Distance, units::inverse<units::seconds> >

◆ Velocity_t

template<class Distance >
using frc::TrapezoidProfile< Distance >::Velocity_t = units::unit_t<Velocity>

Constructor & Destructor Documentation

◆ TrapezoidProfile() [1/4]

template<class Distance >
frc::TrapezoidProfile< Distance >::TrapezoidProfile ( Constraints  constraints)

Constructs a TrapezoidProfile.

Parameters
constraintsThe constraints on the profile, like maximum velocity.

◆ TrapezoidProfile() [2/4]

template<class Distance >
frc::TrapezoidProfile< Distance >::TrapezoidProfile ( Constraints  constraints,
State  goal,
State  initial = State{Distance_t{0}, Velocity_t{0}} 
)

Constructs a TrapezoidProfile.

Parameters
constraintsThe constraints on the profile, like maximum velocity.
goalThe desired state when the profile is complete.
initialThe 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

◆ TrapezoidProfile() [3/4]

template<class Distance >
frc::TrapezoidProfile< Distance >::TrapezoidProfile ( const TrapezoidProfile< Distance > &  )
default

◆ TrapezoidProfile() [4/4]

template<class Distance >
frc::TrapezoidProfile< Distance >::TrapezoidProfile ( TrapezoidProfile< Distance > &&  )
default

Member Function Documentation

◆ Calculate() [1/2]

template<class Distance >
TrapezoidProfile< Distance >::State frc::TrapezoidProfile< Distance >::Calculate ( units::second_t  t) const

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

Parameters
tHow long to advance from the current state toward the desired state.
Returns
The position and velocity of the profile at time t.
Deprecated:
Pass the desired and current state into calculate instead of constructing a new TrapezoidProfile with the desired and current state

◆ Calculate() [2/2]

template<class Distance >
TrapezoidProfile< Distance >::State frc::TrapezoidProfile< Distance >::Calculate ( units::second_t  t,
State  current,
State  goal 
)

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

Parameters
tHow long to advance from the current state toward the desired state.
currentThe current state.
goalThe desired state when the profile is complete.
Returns
The position and velocity of the profile at time t.

◆ IsFinished()

template<class Distance >
bool frc::TrapezoidProfile< Distance >::IsFinished ( units::second_t  t) const
inline

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
tThe time since the beginning of the profile.
Returns
True if the profile has reached the goal.

◆ operator=() [1/2]

template<class Distance >
TrapezoidProfile & frc::TrapezoidProfile< Distance >::operator= ( const TrapezoidProfile< Distance > &  )
default

◆ operator=() [2/2]

template<class Distance >
TrapezoidProfile & frc::TrapezoidProfile< Distance >::operator= ( TrapezoidProfile< Distance > &&  )
default

◆ TimeLeftUntil()

template<class Distance >
units::second_t frc::TrapezoidProfile< Distance >::TimeLeftUntil ( Distance_t  target) const

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

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

◆ TotalTime()

template<class Distance >
units::second_t frc::TrapezoidProfile< Distance >::TotalTime ( ) const
inline

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

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

The documentation for this class was generated from the following files: