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.7 2010/01/26 09:50:19 martius 00024 * comments 00025 * 00026 * Revision 1.6 2009/08/05 22:45:25 martius 00027 * added plotMode 00028 * 00029 * Revision 1.5 2009/08/05 22:32:21 martius 00030 * big change: 00031 * abstractwiring is responsable for providing sensors and motors 00032 * and noise to the inspectable interface. 00033 * external interface: unchanged except plotMode in constructor 00034 * internal interface: all subclasses have to overload 00035 * initIntern, wireSensorsIntern, wireMotorsIntern 00036 * All existing implementation are changed 00037 * 00038 * Revision 1.4 2008/04/17 14:54:45 martius 00039 * randomGen added, which is a random generator with long period and an 00040 * internal state. Each Agent has an instance and passed it to the controller 00041 * and the wiring. This is good for 00042 * a) repeatability on agent basis, 00043 * b) parallel execution as done in ode_robots 00044 * 00045 * Revision 1.3 2006/12/21 11:44:17 martius 00046 * commenting style for doxygen //< -> ///< 00047 * FOREACH and FOREACHC are macros for collection iteration 00048 * 00049 * Revision 1.2 2006/07/14 12:24:02 martius 00050 * selforg becomes HEAD 00051 * 00052 * Revision 1.1.2.1 2005/11/16 11:24:28 martius 00053 * moved to selforg 00054 * 00055 * Revision 1.2 2005/10/24 13:32:07 fhesse 00056 * comments adjusted and in doxygen style 00057 * 00058 * Revision 1.1 2005/08/22 17:28:13 martius 00059 * a 1 to 1 wiring that supports the selection of some sensors only 00060 * 00061 * * 00062 ***************************************************************************/ 00063 #ifndef __SELECTIVEONE2ONEWIRING_H 00064 #define __SELECTIVEONE2ONEWIRING_H 00065 00066 #include "one2onewiring.h" 00067 #include <functional> 00068 00069 /** predicate to select sensors. 00070 First parameter is the index 00071 and the second parameter is the length (or number of sensors). 00072 */ 00073 struct select_predicate : public std::binary_function< int, int, bool> { 00074 virtual ~select_predicate(){} 00075 virtual bool operator()( int index, int len) { return true; } 00076 }; 00077 00078 struct select_all : public select_predicate { }; 00079 00080 struct select_firsthalf : public select_predicate { 00081 virtual ~select_firsthalf(){} 00082 virtual bool operator()( int index, int len) { return index < len/2; } 00083 }; 00084 00085 /// select sensors in the range \f[ [from, to] \f] (inclusively) 00086 struct select_from_to : public select_predicate { 00087 virtual ~select_from_to(){} 00088 select_from_to( int from, int to) : from(from), to(to) {} 00089 virtual bool operator()( int index, int len) { return (index >= from) && (index <= to); } 00090 int from; 00091 int to; 00092 }; 00093 00094 /** 00095 * Implements a selective one to one wiring of robot sensors to inputs of the controller 00096 * and controller outputs to robot motors. 00097 */ 00098 class SelectiveOne2OneWiring : public One2OneWiring{ 00099 public: 00100 /** constructor 00101 @param noise NoiseGenerator that is used for adding noise to sensor values 00102 @param sel_sensor binary predicate taking the index and the length (number of sensors) 00103 and decides which sensor to select 00104 */ 00105 SelectiveOne2OneWiring(NoiseGenerator* noise, select_predicate* sel_sensor, int plotMode = Controller); 00106 virtual ~SelectiveOne2OneWiring(); 00107 00108 protected: 00109 /** initializes the number of sensors and motors on robot side, calculate 00110 number of sensors and motors on controller side 00111 */ 00112 virtual bool initIntern(int robotsensornumber, int robotmotornumber, RandGen* randGen=0); 00113 00114 /// Realizes one to one wiring from robot sensors to controller sensors. 00115 // @param rsensors pointer to array of sensorvalues from robot 00116 // @param rsensornumber number of sensors from robot 00117 // @param csensors pointer to array of sensorvalues for controller 00118 // @param csensornumber number of sensors to controller 00119 // @param noise size of the noise added to the sensors 00120 virtual bool wireSensorsIntern(const sensor* rsensors, int rsensornumber, 00121 sensor* csensors, int csensornumber, 00122 double noise); 00123 00124 protected: 00125 select_predicate* sel_sensor; 00126 00127 }; 00128 00129 #endif