rm_control
Loading...
Searching...
No Matches
lp_filter.h
Go to the documentation of this file.
1/*******************************************************************************
2 * BSD 3-Clause License
3 *
4 * Copyright (c) 2021, Qiayuan Liao
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * * Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
33
34//
35// Created by qiayuan on 1/5/21.
36//
37
38#pragma once
39
40#include <dynamic_reconfigure/server.h>
41#include <realtime_tools/realtime_publisher.h>
42#include <rm_msgs/LpData.h>
43
45{
46public:
47 explicit LowPassFilter(ros::NodeHandle& nh);
48 explicit LowPassFilter(double cutoff_freq);
49 void input(double in);
50 void input(double in, ros::Time time);
51 double output();
52 void reset();
53
54private:
55 double in_[3]{};
56 double out_[3]{};
57
58 // Cutoff frequency for the derivative calculation in Hz.
59 // Negative -> Has not been set by the user yet, so use a default.
60 double cutoff_frequency_ = -1;
61 // Used in filter calculations. Default 1.0 corresponds to a cutoff frequency
62 // at 1/4 of the sample rate.
63 double c_ = 1.;
64 // Used to check for tan(0)==>NaN in the filter calculation
65 double tan_filt_ = 1.;
66 bool is_debug_{};
67
68 ros::Time prev_time_;
69 ros::Duration delta_t_;
70
71 std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::LpData>> realtime_pub_{};
72};
Definition lp_filter.h:45
double output()
Definition lp_filter.cpp:117
LowPassFilter(ros::NodeHandle &nh)
Definition lp_filter.cpp:41
void reset()
Definition lp_filter.cpp:122
void input(double in)
Definition lp_filter.cpp:112