Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #pragma once
00031 #ifndef TACTILE_FILTER_H
00032 #define TACTILE_FILTER_H
00033
00034 #include <ros/ros.h>
00035 #include <string>
00036 #include <math.h>
00037
00038 #include <opencv2/highgui/highgui.hpp>
00039 #include <opencv2/imgproc/imgproc.hpp>
00040 #include <opencv/cv.h>
00041
00042
00043 #include "srs_assisted_grasping/services_list.h"
00044 #include "srs_assisted_grasping/topics_list.h"
00045
00046
00047 #include "schunk_sdh/TactileSensor.h"
00048
00049 #include <boost/thread.hpp>
00050
00051
00052 namespace srs_assisted_grasping {
00053
00054 struct TactileFilterParams {
00055
00056 bool median_prefilter;
00057
00058 int median_width;
00059
00060 int gaussian_width;
00061
00062 int gaussian_height;
00063
00064 double gaussian_sigma_x;
00065
00066 double gaussian_sigma_y;
00067
00068 };
00069
00070 class TactileFilter {
00071
00072 public:
00073
00074
00075 TactileFilter() {
00076
00077 data_received_ = false;
00078
00079
00080 ros::param::param<bool>("~median_prefilter",params_.median_prefilter,true);
00081 ros::param::param<int>("~median_width",params_.median_width,3);
00082 ros::param::param<int>("~gaussian_width",params_.gaussian_width,3);
00083 ros::param::param<int>("~gaussian_height",params_.gaussian_height,3);
00084 ros::param::param<double>("~gaussian_sigma_x",params_.gaussian_sigma_x,0.0);
00085 ros::param::param<double>("~gaussian_sigma_y",params_.gaussian_sigma_y,0.0);
00086
00087
00088 if ((params_.median_width+1)%2!=0) {
00089
00090 ROS_WARN("Param. 'median_width' must be odd and greater than zero! Using default value.");
00091 params_.median_width = 3;
00092
00093 }
00094
00095 if ( (params_.gaussian_height == 0) && (params_.gaussian_width == 0) ) {
00096
00097 if (params_.gaussian_sigma_x==0) {
00098
00099 ROS_WARN("sigma_x could not be zero while height and width are zero");
00100 params_.gaussian_sigma_x = 0.1;
00101
00102 }
00103
00104
00105 } else {
00106
00107 if ((params_.gaussian_width+1)%2!=0) {
00108
00109 ROS_WARN("Param. 'gaussian_width' must be odd and greater than zero! Using default value.");
00110 params_.gaussian_width = 3;
00111
00112 }
00113
00114 if ((params_.gaussian_height+1)%2!=0) {
00115
00116 ROS_WARN("Param. 'gaussian_height' must be odd and greater than zero! Using default value.");
00117 params_.gaussian_height = 3;
00118
00119 }
00120
00121 }
00122
00123 if (params_.median_prefilter) {
00124
00125 ROS_INFO("Using median prefilter, width: %d",params_.median_width);
00126 }
00127
00128 ROS_INFO("Using gaussian filter with size(%d,%d), sigma(%f,%f)",params_.gaussian_width,params_.gaussian_height,params_.gaussian_sigma_x,params_.gaussian_sigma_y);
00129
00130 tact_publisher_ = nh_.advertise<schunk_sdh::TactileSensor>("tact_out", 10);
00131 tact_subscriber_ = nh_.subscribe("tact_in", 10, &TactileFilter::TactileDataCallback,this);
00132
00133 ROS_INFO("Initialized");
00134
00135 }
00136
00137 ~TactileFilter() {
00138
00139
00140
00141 }
00142
00143 protected:
00144
00145 ros::NodeHandle nh_;
00146
00147 ros::Publisher tact_publisher_;
00148 ros::Subscriber tact_subscriber_;
00149
00150 bool data_received_;
00151
00152 void TactileDataCallback(const schunk_sdh::TactileSensor::ConstPtr & msg);
00153
00154 boost::mutex tact_data_mutex_;
00155 std::vector<cv::Mat> tact_data_;
00156 std::vector<cv::Mat> tact_data_filtered_;
00157
00158
00159
00160 TactileFilterParams params_;
00161
00162 private:
00163
00164
00165
00166 };
00167
00168 }
00169
00170 #endif