00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00031 #include "ros/ros.h" 00032 #include "std_msgs/String.h" 00033 #include "std_msgs/Float64.h" 00034 #include <iostream> 00035 #include <stdlib.h> 00036 #include <signal.h> 00037 #include "tcp_client/class_tcp.h" 00038 #include <optoelectric/sensor_sharp_msg.h> 00039 #include <tf/transform_broadcaster.h> 00040 #include <fstream> 00041 #define PFLN {printf("%s %d\n",__FILE__, __LINE__);} 00042 //include eigen library to vector use 00043 #include <vector> 00044 using namespace std; 00045 using namespace ros; 00046 00047 //MedFilt Function 00053 float GetMedian(float a[],int n) 00054 { 00055 00056 float temp; 00057 int i,j; 00058 for(i=0;i<n;i++) 00059 00060 for(j=i+1;j<n;j++) 00061 { 00062 if(a[i]>a[j]) 00063 { 00064 00065 temp=a[j]; 00066 a[j]=a[i]; 00067 a[i]=temp; 00068 } 00069 00070 } 00071 00072 if(n%2==0) 00073 return (a[n/2]+a[n/2-1])/2; 00074 else 00075 return a[n/2]; 00076 00077 } 00082 float Median_Filter(int countt,float dist,float array[]) 00083 { 00084 float med_dist; 00085 if(countt<8) 00086 { 00087 array[countt]=dist; 00088 med_dist=GetMedian(array,countt); 00089 } 00090 else 00091 { 00092 array[7]=dist; 00093 for (int i=0;i<7;i++) 00094 { 00095 array[i]=array[i+1]; 00096 } 00097 med_dist=GetMedian(array,8); 00098 } 00099 return med_dist; 00100 }