回转速率限制器

FRC | reg |中过滤器的常见用法用于软化控制输入的行为(例如,驱动程序控件的操纵杆输入)。不幸的是,一个简单的低通滤波器不适合该工作。低通滤波器将软化输入流对突然变化的响应,但同时也会淘汰精细的控制细节并引入相位滞后。更好的解决方案是直接限制控制输入的变化率。这是通过*压摆率限制器*执行的-限制信号最大变化率的滤波器。

回转速率限制器可以被认为是一种原始的运动曲线。事实上,回转速率限制器是由WPILib支持的梯形运动曲线:ref:Trapezoidal Motion Profile <docs/software/advanced-controls/controllers/trapezoidal-profiles:Trapezoidal Motion Profiles in WPILib> 的一阶等价物。它恰恰是梯形运动的极限情况下,当加速度约束被允许趋向于无穷大。因此,转换速率限制器是一个很好的选择,应用实际的运动剖面流的速度设定值(或电压,通常是近似成比例的速度)。对于控制位置的输入流,通常最好使用适当的梯形剖面。

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

创建一个SlewRateLimiter

备注

C ++的“ SlewRateLimiter”类以输入的单位类型为模板。有关C ++单元的更多信息,请参见:ref:docs/software/basic-programming/cpp-units:The C++ Units Library.

备注

因为过滤器具有“内存”,所以每个输入流都需要其自己的过滤器对象。 *不要*尝试对多个输入流使用相同的过滤器对象。

创建SlewRateLimiter很简单:

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

使用SlewRateLimiter

创建过滤器后,使用起来很容易-只需使用最新输入调用calculate()方法即可获取过滤后的输出:

// 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

备注

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)