WPILibC++ 2023.4.3-108-ge5452e3
frc::TrapezoidProfile< Distance > Class Template Reference

A trapezoid-shaped velocity profile. More...

#include <frc/trajectory/TrapezoidProfile.h>

Classes

class  Constraints
 
class  State
 

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, State goal, State initial=State{Distance_t{0}, Velocity_t{0}})
 Construct a TrapezoidProfile. More...
 
 TrapezoidProfile (const TrapezoidProfile &)=default
 
TrapezoidProfileoperator= (const TrapezoidProfile &)=default
 
 TrapezoidProfile (TrapezoidProfile &&)=default
 
TrapezoidProfileoperator= (TrapezoidProfile &&)=default
 
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. 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;
Definition: TrapezoidProfile.h:52

Run on update:

TrapezoidProfile profile{constraints, unprofiledReference,
previousProfiledReference};
previousProfiledReference = profile.Calculate(timeSincePreviousUpdate);
A trapezoid-shaped velocity profile.
Definition: TrapezoidProfile.h:42
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 pr...
Definition: TrapezoidProfile.inc:62

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/3]

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

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

◆ TrapezoidProfile() [2/3]

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

◆ TrapezoidProfile() [3/3]

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

Member Function Documentation

◆ Calculate()

template<class Distance >
TrapezoidProfile< Distance >::State frc::TrapezoidProfile< Distance >::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.

Parameters
tThe time since the beginning of the profile.

◆ 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.

◆ 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.

◆ TotalTime()

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

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


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