threshold_filter.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright 2016 Intelligent Industrial Robotics (IIROB) Group,
4  * Institute for Anthropomatics and Robotics (IAR) -
5  * Intelligent Process Control and Robotics (IPR),
6  * Karlsruhe Institute of Technology (KIT)
7  *
8  * Author: Alexandar Pollmann
9  * Denis Štogl, email: denis.stogl@kit.edu
10  *
11  * Date of creation: 2015-2016
12  *
13  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14  *
15  * Redistribution and use in source and binary forms,
16  * with or without modification, are permitted provided
17  * that the following conditions are met:
18  *
19  * * Redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer.
21  * * Redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution.
24  * * Neither the name of the copyright holder nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * This package is free software: you can redistribute it and/or modify
29  * it under the terms of the GNU Lesser General Public License as published by
30  * the Free Software Foundation, either version 3 of the License, or
31  * (at your option) any later version.
32  *
33  * This package is distributed in the hope that it will be useful,
34  * but WITHOUT ANY WARRANTY; without even the implied warranty of
35  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36  * GNU Lesser General Public License for more details.
37  *
38  * You should have received a copy of the GNU Lesser General Public License
39  * along with this package. If not, see <http://www.gnu.org/licenses/>.
40 *****************************************************************************/
41 
42 #ifndef IIROB_FILTERS_THRESHOLD_FILTER_H
43 #define IIROB_FILTERS_THRESHOLD_FILTER_H
44 
45 #include <ros/ros.h>
46 #include <geometry_msgs/WrenchStamped.h>
47 #include <iirob_filters/ThresholdParameters.h>
48 #include <iirob_filters/ThresholdConfig.h>
49 #include <dynamic_reconfigure/server.h>
50 #include <filters/filter_base.h>
51 
52 namespace iirob_filters{
53 template <typename T>
55 {
56 public:
58 
60  virtual bool configure();
61  virtual bool update(const T & data_in, T& data_out);
62 
63  private:
64  iirob_filters::ThresholdParameters params_;
65  double threshold_;
68 
69  dynamic_reconfigure::Server<iirob_filters::ThresholdConfig> reconfigCalibrationSrv_; // Dynamic reconfiguration service
70 
71  void reconfigureConfigurationRequest(iirob_filters::ThresholdConfig& config, uint32_t level);
72 
73 };
74 
75 template <typename T>
76 ThresholdFilter<T>::ThresholdFilter(): params_{ros::NodeHandle("~/ThresholdFilter/params").getNamespace()}
77 {
79 }
80 
81 template <typename T>
83 {
84 }
85 
86 template <typename T>
88 {
89  params_.fromParamServer();
90  threshold_ = params_.threshold;
91  threshold_lin_ = params_.linear_threshold;
92  threshold_angular_ = params_.angular_threshold;
93  if(threshold_lin_ == 0)
94  ROS_ERROR("ThresholdFilter did not find param linear_threshold");
95  if(threshold_angular_ == 0)
96  ROS_ERROR("ThresholdFilter did not find param angular_threshold");
97 
98  ROS_INFO("Threshhold Filter Params: Threshold: %f; Treshold lin.: %f; Threshold Anglular: %f" ,
100 
101  return true;
102 }
103 
104 template <typename T>
105 bool ThresholdFilter<T>::update(const T & data_in, T& data_out)
106 {
107  data_out = data_in;
108 
109  if (fabs(data_in) > threshold_) {
110  double sign = (data_in > 0) ? 1 : -1;
111  data_out = threshold_*sign;
112  }
113  return true;
114 }
115 
116 template <>
117 inline bool ThresholdFilter<geometry_msgs::WrenchStamped>::update(const geometry_msgs::WrenchStamped & data_in, geometry_msgs::WrenchStamped& data_out)
118 {
119  data_out = data_in;
120 
121  if (fabs(data_in.wrench.force.x) > threshold_lin_)
122  {
123  double sign = (data_in.wrench.force.x > 0) ? 1 : -1;
124  data_out.wrench.force.x = data_in.wrench.force.x-threshold_lin_*sign;
125  }
126  else
127  {
128  data_out.wrench.force.x = 0;
129  }
130  if (fabs(data_in.wrench.force.y) > threshold_lin_)
131  {
132  double sign = (data_in.wrench.force.y > 0) ? 1 : -1;
133  data_out.wrench.force.y = data_in.wrench.force.y-threshold_lin_*sign;
134  }
135  else
136  {
137  data_out.wrench.force.y = 0;
138  }
139  if (fabs(data_in.wrench.force.z) > threshold_lin_)
140  {
141  double sign = (data_in.wrench.force.z > 0) ? 1 : -1;
142  data_out.wrench.force.z = data_in.wrench.force.z-threshold_lin_*sign;
143  }
144  else
145  {
146  data_out.wrench.force.z = 0;
147  }
148  if (fabs(data_in.wrench.torque.x) > threshold_angular_)
149  {
150  double sign = (data_in.wrench.torque.x > 0) ? 1 : -1;
151  data_out.wrench.torque.x = data_in.wrench.torque.x-threshold_angular_*sign;
152  }
153  else
154  {
155  data_out.wrench.torque.x = 0;
156  }
157  if (fabs(data_in.wrench.torque.y) > threshold_angular_)
158  {
159  double sign = (data_in.wrench.force.y > 0) ? 1 : -1;
160  data_out.wrench.torque.y = data_in.wrench.torque.y-threshold_angular_*sign;
161  }
162  else
163  {
164  data_out.wrench.torque.y = 0;
165  }
166  if (fabs(data_in.wrench.torque.z) > threshold_angular_)
167  {
168  double sign = (data_in.wrench.torque.z > 0) ? 1 : -1;
169  data_out.wrench.torque.z = data_in.wrench.torque.z-threshold_angular_*sign;
170  }
171  else
172  {
173  data_out.wrench.torque.z = 0;
174  }
175  return true;
176 }
177 
178 template <typename T>
179 void ThresholdFilter<T>::reconfigureConfigurationRequest(iirob_filters::ThresholdConfig& config, uint32_t level)
180 {
181  //params_.fromConfig(config);
182  threshold_ = params_.threshold;
183  threshold_lin_ = params_.linear_threshold;
184  threshold_angular_ = params_.angular_threshold;
185 };
186 
187 template <typename T>
189 {
190 public:
193 
194  virtual bool configure();
195  virtual bool update(const std::vector<T>& data_in, std::vector<T>& data_out);
196 
197 private:
198 
199  //ROS Objects
200  iirob_filters::ThresholdParameters params_;
201  double threshold_;
204 
206 };
207 
208 template <typename T>
210 {
211 }
212 
213 template <typename T>
215 {
216 }
217 
218 
219 template <typename T>
221 {
222  params_.fromParamServer();
223  threshold_ = params_.threshold;
224  threshold_lin_ = params_.linear_threshold;
225  threshold_angular_ = params_.angular_threshold;
226  if(threshold_lin_ == 0)
227  ROS_ERROR("ThresholdFilter did not find param linear_threshold");
228  if(threshold_angular_ == 0)
229  ROS_ERROR("ThresholdFilter did not find param angular_threshold");
230 
231  return true;
232 }
233 
234 template <typename T>
235 bool MultiChannelThresholdFilter<T>::update(const std::vector<T>& data_in, std::vector<T>& data_out)
236 {
237 
238 
239  if (data_in.size() != number_of_channels_ || data_out.size() != number_of_channels_)
240  {
241  ROS_ERROR("Configured with wrong size config:%d in:%d out:%d", number_of_channels_, (int)data_in.size(), (int)data_out.size());
242  return false;
243  }
244 
245  for(int i = 0; i < data_in.size(); i++)
246  {
247  data_out[i] = data_in[i];
248  if (fabs(data_in[i]) > threshold_) {
249  double sign = (data_in[i] > 0) ? 1 : -1;
250  data_out[i] = threshold_*sign;
251  }
252  else
253  {
254  data_out[i] = 0;
255  }
256  }
257  return true;
258 };
259 }
260 #endif
dynamic_reconfigure::Server< iirob_filters::ThresholdConfig > reconfigCalibrationSrv_
double sign(double arg)
void reconfigureConfigurationRequest(iirob_filters::ThresholdConfig &config, uint32_t level)
iirob_filters::ThresholdParameters params_
#define ROS_INFO(...)
iirob_filters::ThresholdParameters params_
virtual bool update(const std::vector< T > &data_in, std::vector< T > &data_out)
#define ROS_ERROR(...)
virtual bool update(const T &data_in, T &data_out)


iirob_filters
Author(s): Denis Štogl
autogenerated on Fri Sep 18 2020 03:32:19