00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program; if not, write to the * 00019 * Free Software Foundation, Inc., * 00020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 * * 00022 * $Log: selectiveone2onewiring.h,v $ 00023 * Revision 1.6 2009/08/05 22:45:25 martius 00024 * added plotMode 00025 * 00026 * Revision 1.5 2009/08/05 22:32:21 martius 00027 * big change: 00028 * abstractwiring is responsable for providing sensors and motors 00029 * and noise to the inspectable interface. 00030 * external interface: unchanged except plotMode in constructor 00031 * internal interface: all subclasses have to overload 00032 * initIntern, wireSensorsIntern, wireMotorsIntern 00033 * All existing implementation are changed 00034 * 00035 * Revision 1.4 2008/04/17 14:54:45 martius 00036 * randomGen added, which is a random generator with long period and an 00037 * internal state. Each Agent has an instance and passed it to the controller 00038 * and the wiring. This is good for 00039 * a) repeatability on agent basis, 00040 * b) parallel execution as done in ode_robots 00041 * 00042 * Revision 1.3 2006/12/21 11:44:17 martius 00043 * commenting style for doxygen //< -> ///< 00044 * FOREACH and FOREACHC are macros for collection iteration 00045 * 00046 * Revision 1.2 2006/07/14 12:24:02 martius 00047 * selforg becomes HEAD 00048 * 00049 * Revision 1.1.2.1 2005/11/16 11:24:28 martius 00050 * moved to selforg 00051 * 00052 * Revision 1.2 2005/10/24 13:32:07 fhesse 00053 * comments adjusted and in doxygen style 00054 * 00055 * Revision 1.1 2005/08/22 17:28:13 martius 00056 * a 1 to 1 wiring that supports the selection of some sensors only 00057 * 00058 * * 00059 ***************************************************************************/ 00060 #ifndef __SELECTIVEONE2ONEWIRING_H 00061 #define __SELECTIVEONE2ONEWIRING_H 00062 00063 #include "one2onewiring.h" 00064 #include <functional> 00065 00066 /** predicate to select sensors. 00067 First parameter is the index 00068 and the second parameter is the length (or number of sensors). 00069 */ 00070 struct select_predicate : public std::binary_function< int, int, bool> { 00071 virtual ~select_predicate(){} 00072 virtual bool operator()( int index, int len) { return true; } 00073 }; 00074 00075 struct select_all : public select_predicate { }; 00076 00077 struct select_firsthalf : public select_predicate { 00078 virtual ~select_firsthalf(){} 00079 virtual bool operator()( int index, int len) { return index < len/2; } 00080 }; 00081 00082 /// select sensors in the range \f[ [from, to] \f] (inclusively) 00083 struct select_from_to : public select_predicate { 00084 virtual ~select_from_to(){} 00085 select_from_to( int from, int to) : from(from), to(to) {} 00086 virtual bool operator()( int index, int len) { return (index >= from) && (index <= to); } 00087 int from; 00088 int to; 00089 }; 00090 00091 /** 00092 * Implements a selective one to one wireing of robot sensors to inputs of the controller 00093 * and controller outputs to robot motors. 00094 */ 00095 class SelectiveOne2OneWiring : public One2OneWiring{ 00096 public: 00097 /** constructor 00098 @param noise NoiseGenerator that is used for adding noise to sensor values 00099 @param sel_sensor binary predicate taking the index and the length (number of sensors) 00100 and decides which sensor to select 00101 */ 00102 SelectiveOne2OneWiring(NoiseGenerator* noise, select_predicate* sel_sensor, int plotMode = Controller); 00103 virtual ~SelectiveOne2OneWiring(); 00104 00105 protected: 00106 /** initializes the number of sensors and motors on robot side, calculate 00107 number of sensors and motors on controller side 00108 */ 00109 virtual bool initIntern(int robotsensornumber, int robotmotornumber, RandGen* randGen=0); 00110 00111 /// Realizes one to one wiring from robot sensors to controller sensors. 00112 // @param rsensors pointer to array of sensorvalues from robot 00113 // @param rsensornumber number of sensors from robot 00114 // @param csensors pointer to array of sensorvalues for controller 00115 // @param csensornumber number of sensors to controller 00116 // @param noise size of the noise added to the sensors 00117 virtual bool wireSensorsIntern(const sensor* rsensors, int rsensornumber, 00118 sensor* csensors, int csensornumber, 00119 double noise); 00120 00121 protected: 00122 select_predicate* sel_sensor; 00123 00124 }; 00125 00126 #endif