54 : previous_measurements_{ 0., 0. }
55 , previous_filtered_measurement_(0.)
56 , scale_term_(1. / (1. + low_pass_filter_coeff))
57 , feedback_term_(1. - low_pass_filter_coeff)
60 static_assert(ButterworthFilter::FILTER_LENGTH == 2,
61 "online_signal_smoothing::ButterworthFilter::FILTER_LENGTH should be 2");
63 if (std::isinf(feedback_term_))
64 throw std::length_error(
"online_signal_smoothing::ButterworthFilter: infinite feedback_term_");
66 if (std::isinf(scale_term_))
67 throw std::length_error(
"online_signal_smoothing::ButterworthFilter: infinite scale_term_");
69 if (low_pass_filter_coeff < 1)
71 throw std::length_error(
72 "online_signal_smoothing::ButterworthFilter: Filter coefficient < 1. makes the lowpass filter unstable");
75 if (std::abs(feedback_term_) <
EPSILON)
77 throw std::length_error(
78 "online_signal_smoothing::ButterworthFilter: Filter coefficient value resulted in feedback term of 0");
85 previous_measurements_[1] = previous_measurements_[0];
86 previous_measurements_[0] = new_measurement;
88 previous_filtered_measurement_ = scale_term_ * (previous_measurements_[1] + previous_measurements_[0] -
89 feedback_term_ * previous_filtered_measurement_);
91 return previous_filtered_measurement_;
105 num_joints_ = num_joints;
107 online_signal_smoothing::ParamListener param_listener(node_);
108 double filter_coeff = param_listener.get_params().butterworth_filter_coeff;
110 for (std::size_t i = 0; i < num_joints_; ++i)
112 position_filters_.emplace_back(filter_coeff);
120 const size_t num_positions = positions.size();
121 if (num_positions != position_filters_.size())
123 RCLCPP_ERROR_THROTTLE(node_->get_logger(), *node_->get_clock(), 1000,
124 "Position vector to be smoothed does not have the right length.");
127 for (
size_t i = 0; i < num_positions; ++i)
130 positions[i] = position_filters_.at(i).filter(positions[i]);
136 const Eigen::VectorXd& )
138 const size_t num_positions = positions.size();
139 if (num_positions != position_filters_.size())
141 RCLCPP_ERROR_THROTTLE(node_->get_logger(), *node_->get_clock(), 1000,
142 "Position vector to be reset does not have the right length.");
145 for (
size_t joint_idx = 0; joint_idx < num_positions; ++joint_idx)
147 position_filters_.at(joint_idx).reset(positions[joint_idx]);