Slew Rate Limiter - Limitador de velocidad de respuesta

A common use for filters in FRC® & FTC® is to soften the behavior of control inputs (for example, the joystick inputs from your driver controls). Unfortunately, a simple low-pass filter is poorly-suited for this job; while a low-pass filter will soften the response of an input stream to sudden changes, it will also wash out fine control detail and introduce phase lag. A better solution is to limit the rate-of-change of the control input directly. This is performed with a slew rate limiter - a filter that caps the maximum rate-of-change of the signal.

Un slew rate limiter puede ser pensado como un tipo de perfil de movimiento primitivo, De hecho, el slew rate limiter es el equivalente en primer orden de un Perfil de movimiento Trapezoidal soportado por WPILib – precisamente es el caso limitador de un movimiento trapezoidal cuando la restricción de aceleración es permitida a tender a infinito. De acuerdo con esto, un slew rate limiter es una buena opción para aplicar un perfil de movimiento verdadero a un flujo de velocidad con punto fijo (o voltajes, que son usualmente aproximadamente proporcionales a la velocidad). Para flujos de entrada que controlan posición, usualmente es mejor usar un perfil trapezoidal adecuado.

Slew rate limiting is supported in WPILib through the SlewRateLimiter class (Java, C++, Python).

Creando un SlewRateLimiter

Nota

La clase de C++ SlewRateLimiter está basada en el tipo de unidad de la entrada. Para más informacion de unidades de C++, ver Biblioteca de unidades de C++.

Nota

Debido a que los filtros tienen “memoria”, cada entrada de flujo requiere su propio objeto filtro. No intente usar el mismo objeto filtro para múltiples entradas de flujo.

Crear un SlewRateLimiter es simple:

// Creates a SlewRateLimiter that limits the rate of change of the signal to 0.5 units per second
SlewRateLimiter filter = new SlewRateLimiter(0.5);
// Creates a SlewRateLimiter that limits the rate of change of the signal to 0.5 volts per second
wpi::math::SlewRateLimiter<units::volts> filter{0.5_V / 1_s};
from wpimath.filter import SlewRateLimiter
# Creates a SlewRateLimiter that limits the rate of change of the signal to 0.5 units per second
filter = SlewRateLimiter(0.5)

Usar un SlewRateLimiter

Una vez que su filtro ha sido creado, usarlo es sencillo - simplemente llame al método ``calculate()``con la entrada más reciente para obtener la salida filtrada:

// Calculates the next value of the output
filter.calculate(input);
// Calculates the next value of the output
filter.Calculate(input);
# Calculates the next value of the output
filter.calculate(input)

Using a SlewRateLimiter with DifferentialDrive

Nota

The C++ example below templates the filter on units::scalar for use with doubles, since joystick values are typically dimensionless.

A typical use of a SlewRateLimiter is to limit the acceleration of a robot’s drive. This can be especially handy for robots that are very top-heavy, or that have very powerful drives. To do this, apply a SlewRateLimiter to a value passed into your robot drive function:

// Ordinary call with no ramping applied
drivetrain.arcadeDrive(forward, turn);
// Slew-rate limits the forward/backward input, limiting forward/backward acceleration
drivetrain.arcadeDrive(filter.calculate(forward), turn);
// Ordinary call with no ramping applied
drivetrain.ArcadeDrive(forward, turn);
// Slew-rate limits the forward/backward input, limiting forward/backward acceleration
drivetrain.ArcadeDrive(filter.Calculate(forward), turn);
# Ordinary call with no ramping applied
drivetrain.arcade_drive(forward, turn)
# Slew-rate limits the forward/backward input, limiting forward/backward acceleration
drivetrain.arcade_drive(filter.calculate(forward), turn)