Slew Rate Limiter - Limitador de velocidad de respuesta

Un uso común para los filtros en FRC® es suavizar el comportamiento de las entradas del control (por ejemplo, las entradas del joysitick de los controladores del driver). Desafortunadamente, un simple filtro de bajo-paso está pobremente adecuado para el trabajo; mientras que el filtro de bajo-paso suaviza la respuesta de un flujo de entrada a cambios súbitos, también limpiará detalles finos de control e introducirá una fase de retraso. Una mejor solución es limitar directamente la tasa de cambio de la entrada del control. Esto se hace con un slew rate limiter, un filtro que se encarga de la máxima tasa de cambio de la señal.

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
frc::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.arcadeDrive(forward, turn)

# Slew-rate limits the forward/backward input, limiting forward/backward acceleration
drivetrain.arcadeDrive(filter.calculate(forward), turn)