FirFilter.cpp
Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011  Antonio Franchi
00006 //
00007 // This file is part of TeleKyb.
00008 //
00009 // TeleKyb is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // TeleKyb is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with TeleKyb. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de 
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00027 #include <telekyb_base/Filter/FirFilter.hpp>
00028 
00029 #include <ros/console.h>
00030 
00031 namespace TELEKYB_NAMESPACE
00032 {
00033 
00034 void FirFilter::_eraseOldSamples(){
00035         std::list<double>::iterator sampIt = _var.samples.begin();
00036         std::list<Time>::iterator    timeIt = _var.timeStamps.begin();
00037         std::list<double>::iterator sampItEnd = _var.samples.end();
00038         sampItEnd--;
00039         std::list<Time>::iterator    timeItEnd = _var.timeStamps.end();
00040         timeItEnd--;
00041         while((sampIt != (sampItEnd)) && (timeIt != (timeItEnd))){
00042                 if(*timeIt >= _var.lastTimeStamp - _par.lag){
00043                         break;
00044                 }
00045                 sampIt++;
00046                 timeIt++; 
00047         }
00048         if(timeIt != _var.timeStamps.begin()){
00049                 _var.samples.erase(_var.samples.begin(),sampIt);
00050                 _var.timeStamps.erase(_var.timeStamps.begin(),timeIt);
00051         }
00052 }
00053                 
00054 void FirFilter::_average(FirFilterOut& out){
00055         double sum = 0.0;
00056         std::list<double>::iterator sampIt = _var.samples.begin();
00057         while(sampIt != _var.samples.end()){
00058                 sum += *sampIt;
00059                 sampIt++;
00060         }
00061         out.size = _var.samples.size();
00062         if(out.size == 0){
00063                 ROS_WARN("FirFilter: Number of samples zero, something's wrong.");
00064         }
00065         out.sample = sum /(double) out.size;
00066 }
00067 
00068 void  FirFilter::step(FirFilterIn& in,FirFilterOut& out){
00069         _var.samples.push_back(in.sample);
00070         _var.lastTimeStamp=Time();
00071         _var.timeStamps.push_back(_var.lastTimeStamp);
00072         _eraseOldSamples();
00073         _average(out);
00074 }
00075 
00076 } // namespace
00077 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


telekyb_base
Author(s): Dr. Antonio Franchi and Martin Riedel
autogenerated on Mon Nov 11 2013 11:12:34