WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
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
 
using Velocity_t = units::unit_t<Velocity>
 
using Acceleration
 
using Acceleration_t = units::unit_t<Acceleration>
 

Public Member Functions

constexpr TrapezoidProfile (Constraints constraints)
 Constructs a TrapezoidProfile.
 
constexpr TrapezoidProfile (const TrapezoidProfile &)=default
 
constexpr TrapezoidProfileoperator= (const TrapezoidProfile &)=default
 
constexpr TrapezoidProfile (TrapezoidProfile &&)=default
 
constexpr TrapezoidProfileoperator= (TrapezoidProfile &&)=default
 
constexpr 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.
 
constexpr units::second_t TimeLeftUntil (Distance_t target) const
 Returns the time left until a target distance in the profile is reached.
 
constexpr units::second_t TotalTime () const
 Returns the total time the profile takes to reach the goal.
 
constexpr bool IsFinished (units::second_t t) const
 Returns true if the profile has reached the goal.
 

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:59
A trapezoid-shaped velocity profile.
Definition TrapezoidProfile.h:46

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
Initial value:
typename units::detail::compound_impl< U, Us... >::type compound_unit
Represents a unit type made up from other units.
Definition base.h:1438

◆ 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

◆ 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)
inlineconstexpr

Constructs a TrapezoidProfile.

Parameters
constraintsThe constraints on the profile, like maximum velocity.

◆ TrapezoidProfile() [2/3]

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

◆ TrapezoidProfile() [3/3]

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

Member Function Documentation

◆ Calculate()

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

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
inlineconstexpr

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 > & )
constexprdefault

◆ operator=() [2/2]

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

◆ TimeLeftUntil()

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

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
inlineconstexpr

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 file: