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 __ABSTRACTMULTICONTROLLER_H 00025 #define __ABSTRACTMULTICONTROLLER_H 00026 00027 #include "abstractcontrolleradapter.h" 00028 00029 /** 00030 * Abstract class (interface) for using multiple controller. 00031 * A controller gets a number of input sensor values each timestep 00032 * and has to generate a number of output motor values 00033 * 00034 * 00035 * This is an abstract class, it's useful for implementing multicontrollers such as the 00036 * OneActiveMultiPassiveController, which can be used with all Controllers. 00037 * 00038 * Any MulitController implementing this class should overwrite the methods step(...) and 00039 * stepNoLearning(...). 00040 */ 00041 class AbstractMultiController : public AbstractControllerAdapter { 00042 public: 00043 00044 /// contructor (hint: use $ID$ for revision) 00045 AbstractMultiController(AbstractController* controller, const std::string& name, const std::string& revision); 00046 00047 virtual ~AbstractMultiController(); 00048 00049 /** 00050 * Adds a passive controller to this MultiController. If the Agent calls step(..) 00051 * or stepNoLearning(..), the MultiController calls not only the active controllers 00052 * step(...) but also the step(...) of all the passive controllers. (same for 00053 * stepNoLearning(..) ). 00054 * 00055 * Note: The initialisation of the MultiController with init(sensornumber, motornumber) 00056 * must be called after all passive controllers are added, otherwise you must 00057 * init the passive controller yourself (not recommended and can generate problems) 00058 */ 00059 virtual void addPassiveController(AbstractController* passiveController); 00060 00061 /****************************************************************************/ 00062 /* AbstractMultiController should implement the following classes: */ 00063 /* AbstractController, Configurable, Inspectable, Storeable */ 00064 /****************************************************************************/ 00065 00066 00067 /****************************************************************************/ 00068 /* BEGIN methods of AbstractController */ 00069 /****************************************************************************/ 00070 00071 00072 /** initialisation of the controller with the given sensor/ motornumber 00073 * Must NORMALLY be called before use. For all multicontroller 00074 * call first AbstractMultiController::init(sensornumber,motornumber) 00075 * if you overwrite this method 00076 */ 00077 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0); 00078 00079 /** performs one step (includes learning). 00080 Calculates motor commands from sensor inputs. 00081 @param sensors sensors inputs scaled to [-1,1] 00082 @param sensornumber length of the sensor array 00083 @param motors motors outputs. MUST have enough space for motor values! 00084 @param motornumber length of the provided motor array 00085 */ 00086 virtual void step(const sensor* sensors, int sensornumber, 00087 motor* motors, int motornumber)=0; 00088 00089 /** performs one step without learning. 00090 @see step 00091 */ 00092 virtual void stepNoLearning(const sensor* sensors , int sensornumber, 00093 motor* motors, int motornumber)=0; 00094 00095 00096 /****************************************************************************/ 00097 /* END methods of AbstractController */ 00098 /****************************************************************************/ 00099 00100 /****************************************************************************/ 00101 /* BEGIN methods of Configurable */ 00102 /****************************************************************************/ 00103 00104 00105 00106 /****************************************************************************/ 00107 /* END methods of Configurable */ 00108 /****************************************************************************/ 00109 00110 /****************************************************************************/ 00111 /* BEGIN methods of Inspectable */ 00112 /****************************************************************************/ 00113 00114 // nothing to overwrite 00115 00116 00117 /****************************************************************************/ 00118 /* END methods of Inspectable */ 00119 /****************************************************************************/ 00120 00121 /****************************************************************************/ 00122 /* BEGIN methods of Storeable */ 00123 /****************************************************************************/ 00124 00125 /** stores the object to the given file stream (binary). 00126 */ 00127 virtual bool store(FILE* f) const; 00128 00129 /** loads the object from the given file stream (binary). 00130 */ 00131 virtual bool restore(FILE* f); 00132 00133 00134 /****************************************************************************/ 00135 /* END methods of Storeable */ 00136 /****************************************************************************/ 00137 00138 protected: 00139 // The AbstractController* controller is defined in AbstractControllerAdapter! 00140 std::list<AbstractController*> controllerList; // stores the other controllers 00141 std::list<std::string> controllerNameList; // stores the names of the controllers 00142 00143 }; 00144 00145 #endif