selectiveone2onewiring.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
00003  *    Georg Martius  <georg dot martius at web dot de>                     *
00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00022  *                                                                         *
00023  ***************************************************************************/
00024 #ifndef __SELECTIVEONE2ONEWIRING_H
00025 #define __SELECTIVEONE2ONEWIRING_H
00026 
00027 #include "one2onewiring.h"
00028 #include <functional>
00029 
00030 /** predicate to select sensors. 
00031     First parameter is the index 
00032     and the second parameter is the length (or number of sensors).
00033 */
00034 struct select_predicate : public std::binary_function< int,  int, bool> { 
00035   virtual ~select_predicate(){}
00036   virtual bool operator()( int index,  int len) { return true; }
00037 };
00038 
00039 struct select_all : public  select_predicate { };
00040 
00041 struct select_firsthalf : public  select_predicate {  
00042   virtual ~select_firsthalf(){}
00043   virtual bool operator()( int index,  int len) { return index < len/2; }
00044 };
00045 
00046 /// select sensors in the range \f[ [from, to] \f] (inclusively)
00047 struct select_from_to : public  select_predicate {   
00048   virtual ~select_from_to(){}
00049   select_from_to( int from,  int to) : from(from), to(to) {}
00050   virtual bool operator()( int index,  int len) { return (index >= from) && (index <= to); }
00051   int from;
00052   int to;
00053 };
00054 
00055 /** 
00056  *   Implements a selective one to one wiring of robot sensors to inputs of the controller 
00057  *   and controller outputs to robot motors. 
00058  */
00059 class SelectiveOne2OneWiring : public One2OneWiring{
00060 public:
00061   /** constructor
00062       @param noise NoiseGenerator that is used for adding noise to sensor values  
00063       @param sel_sensor binary predicate taking the index and the length (number of sensors) 
00064              and decides which sensor to select
00065   */
00066   SelectiveOne2OneWiring(NoiseGenerator* noise, select_predicate* sel_sensor, int plotMode = Controller, const std::string& name = "SelectiveOne2OneWiring");
00067   virtual ~SelectiveOne2OneWiring();
00068 
00069 protected:
00070   virtual bool initIntern();
00071 
00072   virtual bool wireSensorsIntern(const sensor* rsensors, int rsensornumber, 
00073                                  sensor* csensors, int csensornumber,
00074                                  double noise);
00075 
00076 protected:  
00077   select_predicate* sel_sensor;
00078 
00079 };
00080 
00081 #endif
Generated on Thu Jun 28 14:45:37 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3