WPILibC++  2020.3.2-60-g3011ebe
frc::TrapezoidProfile< Distance > Class Template Reference

A trapezoid-shaped velocity profile. More...

#include <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.
 
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:

TrapezoidalMotionProfile::Constraints constraints{kMaxV, kMaxA};
double previousProfiledReference = initialReference;

Run on update:

TrapezoidalMotionProfile profile{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().

Constructor & Destructor Documentation

◆ TrapezoidProfile()

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

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.

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

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