libstp
Robotics library for Botball
Loading...
Searching...
No Matches
libstp::motion::TrapezoidalProfile Class Reference

#include <trapezoidal_profile.hpp>

Classes

struct  Constraints
struct  State

Public Member Functions

 TrapezoidalProfile (const State &initial, double target, const Constraints &constraints)
State getSetpoint (double elapsed_time) const
bool isComplete (double elapsed_time) const
double getTotalTime () const

Static Public Member Functions

static State calculate (double dt, const State &current, const State &goal, const Constraints &constraints)

Detailed Description

Generates a trapezoidal velocity profile for smooth motion.

The profile has three phases:

  1. Acceleration: ramp up from 0 to max_velocity
  2. Cruise: maintain max_velocity
  3. Deceleration: ramp down from max_velocity to 0

For short distances, the profile may be triangular (no cruise phase). Supports asymmetric acceleration/deceleration rates.

Definition at line 20 of file trapezoidal_profile.hpp.

Constructor & Destructor Documentation

◆ TrapezoidalProfile()

libstp::motion::TrapezoidalProfile::TrapezoidalProfile ( const State & initial,
double target,
const Constraints & constraints )
inline

Initialize the profile.

Parameters
initialInitial state (usually {0, 0})
targetTarget position
constraintsVelocity and acceleration limits

Definition at line 61 of file trapezoidal_profile.hpp.

Member Function Documentation

◆ calculate()

State libstp::motion::TrapezoidalProfile::calculate ( double dt,
const State & current,
const State & goal,
const Constraints & constraints )
inlinestatic

Compute the next setpoint along a trapezoidal trajectory from current toward goal.

Analytical approach (ported from FRC WPILib TrapezoidProfile::Calculate): each call recomputes the full trapezoidal profile from current state to goal, then evaluates it at exactly t=dt. This is analytically exact – no discretisation overshoot regardless of timestep.

Supports asymmetric acceleration/deceleration rates.

Parameters
dtTime step (seconds)
currentCurrent profiled state (position, velocity)
goalDesired goal state (position, velocity)
constraintsVelocity and acceleration limits
Returns
The exact setpoint state after dt

Definition at line 139 of file trapezoidal_profile.hpp.

◆ getSetpoint()

State libstp::motion::TrapezoidalProfile::getSetpoint ( double elapsed_time) const
inline

Get the setpoint at a given time.

Parameters
elapsed_timeTime since profile started (seconds)
Returns
Desired state at this time

Definition at line 82 of file trapezoidal_profile.hpp.

◆ getTotalTime()

double libstp::motion::TrapezoidalProfile::getTotalTime ( ) const
inline

Get the total time for the profile.

Definition at line 242 of file trapezoidal_profile.hpp.

◆ isComplete()

bool libstp::motion::TrapezoidalProfile::isComplete ( double elapsed_time) const
inline

Check if the profile is complete.

Definition at line 234 of file trapezoidal_profile.hpp.


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