YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
yams::math::TrackingDifferentiator Class Reference

#include <TrackingDifferentiator.hpp>

Public Types

enum class  Method {
  EULER , TOD , LD , RED ,
  INTD
}

Public Member Functions

 TrackingDifferentiator (Method method, wpi::units::second_t dt, std::vector< double > params={})
void SetParameters (std::vector< double > params)
void SetSampleTime (wpi::units::second_t dt)
void Update (double reference)
void Reset (double initialValue)
double GetY () const
double GetYd () const
double GetYdd () const
Method GetMethod () const

Detailed Description

Tracking differentiator.

Written by FRC Team 8331, who contributed active disturbance rejection control to YAMS.

A tracking differentiator turns a raw reference into a smooth reference y together with its first and second derivatives yd and ydd. Feeding the smoothed reference to a controller avoids the large output spikes a step setpoint would otherwise produce: the controller follows a trajectory the mechanism can track instead of demanding an instantaneous change.

Mechanisms rarely construct this class directly; they configure one with ADRCConfig::WithTrackingDifferentiator and the controller applies it to every setpoint.

Five methods are supported, selected with Method. Each takes a short list of parameters; a parameter left out uses its default:

  • EULER, first order smoothing: alpha in [0, 1], default 0.9. Higher is smoother and slower; the time constant is about dt / (1 - alpha), and yd jumps on a step.
  • TOD, bang-bang: r greater than 0, default 1, the acceleration bound in the loop's units per second squared. yd chatters at rest at a 20 ms period.
  • LD, linear: lambda greater than 0, default 1, a time constant in seconds; the sample time must stay below 2 * lambda. No overshoot; a step is followed to 98% in about 5.8 * lambda. The best default.
  • RED, super-twisting: lambda1 (how hard the error pulls) and lambda2 (the bound on how quickly yd changes), greater than 0, default 1 each. Overshoots, and yd chatters at rest at a 20 ms period.
  • INTD, saturating: alpha in [0, 1) default 0.5, then beta and gamma in the loop's units and r per second, greater than 0, default 1 each. Cruises at r * beta / (1 - alpha), then lands like LD with natural frequency r * sqrt(beta / gamma) and damping 0.5 * sqrt(gamma / beta); gamma = 4 * beta is critically damped.

ADRCGuide.md explains how to choose and tune each method.

Invalid parameters throw std::invalid_argument.

td.Update(setpoint);
double smoothSetpoint = td.GetY();
double setpointVelocity = td.GetYd();
Definition TrackingDifferentiator.hpp:51
void Update(double reference)
double GetY() const
Definition TrackingDifferentiator.hpp:103
@ LD
Linear differentiator; lambda greater than 0, default 1.
Definition TrackingDifferentiator.hpp:57
double GetYd() const
Definition TrackingDifferentiator.hpp:105

Member Enumeration Documentation

◆ Method

Differentiation method.

Enumerator
EULER 

First order exponential smoothing; alpha in [0, 1], default 0.9.

TOD 

Bang-bang time optimal differentiator; r greater than 0, default 1.

LD 

Linear differentiator; lambda greater than 0, default 1.

RED 

Super-twisting differentiator; lambda1, lambda2, default 1 each.

INTD 

Saturating differentiator; alpha, beta, gamma, r, defaults 0.5, 1, 1, 1.

Constructor & Destructor Documentation

◆ TrackingDifferentiator()

yams::math::TrackingDifferentiator::TrackingDifferentiator ( Method method,
wpi::units::second_t dt,
std::vector< double > params = {} )

Create a tracking differentiator.

Parameters
methodDifferentiation method.
dtSample time.
paramsMethod parameters in order; empty, or shorter than the method takes, for the defaults.
Exceptions
std::invalid_argumentif the sample time or a parameter is invalid.

Member Function Documentation

◆ GetMethod()

Method yams::math::TrackingDifferentiator::GetMethod ( ) const
inline
Returns
The differentiation method.

◆ GetY()

double yams::math::TrackingDifferentiator::GetY ( ) const
inline
Returns
The filtered reference.

◆ GetYd()

double yams::math::TrackingDifferentiator::GetYd ( ) const
inline
Returns
The filtered reference's derivative.

◆ GetYdd()

double yams::math::TrackingDifferentiator::GetYdd ( ) const
inline
Returns
The filtered reference's second derivative.

◆ Reset()

void yams::math::TrackingDifferentiator::Reset ( double initialValue)

Reset the internal states to a value, at rest.

Parameters
initialValueInitial value of the filtered reference.

◆ SetParameters()

void yams::math::TrackingDifferentiator::SetParameters ( std::vector< double > params)

Replace the method parameters. An empty list leaves them unchanged.

Parameters
paramsNew parameters.
Exceptions
std::invalid_argumentif a parameter is invalid; the previous parameters are kept.

◆ SetSampleTime()

void yams::math::TrackingDifferentiator::SetSampleTime ( wpi::units::second_t dt)

Change the sample time.

Parameters
dtSample time.
Exceptions
std::invalid_argumentif the sample time is invalid, or the parameters are at it.

◆ Update()

void yams::math::TrackingDifferentiator::Update ( double reference)

Advance the differentiator by one sample.

Parameters
referenceRaw reference.

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