Apollo控制模块滤波器–滞环滤波器
hysteresisFilter.h
namespace apollo {
namespace control {
class HysteresisFilter {
public:
HysteresisFilter() = default;
void filter(const double input_value, const double threshold,
const double hysteresis_upper, const double hysteresis_lower,
int *state, double *output_value);
private:
int previous_state_ = 0;
};
} // namespace control
} // namespace apollo
#include "modules/control/control_component/controller_task_base/common/hysteresis_filter.h"
namespace apollo {
namespace control {
void HysteresisFilter::filter(const double input_value, const double threshold,
const double hysteresis_upper,
const double hysteresis_lower, int *state,
double *output_value) {
// Use integer to represent mode as of now, for instance,
// 1 is throttle, 0 is brake, then threshold is speed error
if (input_value > threshold + hysteresis_upper) {
*state = 1;
previous_state_ = *state;
*output_value = threshold + hysteresis_upper;
} else if (input_value < threshold - hysteresis_lower) {
*state = 0;
previous_state_ = *state;
*output_value = threshold - hysteresis_lower;
} else {
*state = previous_state_;
*output_value = input_value;
}
}
} // namespace control
Apollo控制模块滞环滤波器实现,暂时无模块调用;主要用于抗抖振,利用状态记忆和死区机制抑制信号在阈值附近的高频抖振;
设置不对称的上升和下降触发阈值,确保状态只有在输入信号明确地、大幅度地反向穿越死区后才会改变;数值大于上限threshold + hysteresis_upper或小于下限threshold – hysteresis_lower,输出结果与状态改变,阈值死区范围内,输出结果与状态维持不变;
