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 __ONECONTROLLERPERCHANNEL_H 00025 #define __ONECONTROLLERPERCHANNEL_H 00026 00027 #include <selforg/abstractcontroller.h> 00028 #include <vector> 00029 #include <functional> 00030 00031 00032 /** generator for controller 00033 00034 derive a struct and overload the operator. For example: 00035 00036 struct ControlGen : public ControllerGenerator { 00037 virtual ~ControlGen(){} 00038 virtual AbstractController* operator()( int index) { 00039 AbstractController* c; 00040 c= new Sox(0.8); 00041 c->setParam("epsC",0.02); 00042 c->setParam("epsA",0.01); 00043 return c; 00044 } 00045 }; 00046 00047 // to see the values in the inspectable do after 00048 agent = new OdeAgent(global); 00049 // this line 00050 agent->addInspectable(((OneControllerPerChannel*)controller)->getControllers()[0]); 00051 .... 00052 Make sure you initialize the OneControllerPerChannel with sufficiently many initial controller. 00053 00054 */ 00055 struct ControllerGenerator : public std::unary_function< int, AbstractController*> { 00056 virtual ~ControllerGenerator(){} 00057 virtual AbstractController* operator()( int index) = 0; 00058 }; 00059 00060 00061 /** 00062 * class for using multiple controller, one for each joint. Each controller 00063 * has dimension 1x1. The controller are generated on the fly with a generator object 00064 * 00065 */ 00066 class OneControllerPerChannel : public AbstractController { 00067 public: 00068 00069 /** @param controllerGenerator generator object for controller 00070 @param controllerName name 00071 @param numCtrlCreateBeforeInit number of controller that are generated before the init function is called. Useful if they should be put into the inspectable list of the agent 00072 @param numContextSensors number of context sensors (counted from the end) 00073 passed to all controllers 00074 */ 00075 OneControllerPerChannel(ControllerGenerator* controllerGenerator, 00076 std::string controllerName, 00077 int numCtrlCreateBeforeInit = 1, 00078 int numContextSensors = 0 00079 ); 00080 00081 virtual ~OneControllerPerChannel(); 00082 00083 00084 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0); 00085 00086 virtual void step(const sensor* sensors, int sensornumber, 00087 motor* motors, int motornumber); 00088 00089 virtual void stepNoLearning(const sensor* sensors , int sensornumber, 00090 motor* motors, int motornumber); 00091 00092 virtual int getSensorNumber() const {return sensornumber; } 00093 virtual int getMotorNumber() const {return motornumber; } 00094 00095 /*********** STORABLE **************/ 00096 00097 virtual bool store(FILE* f) const; 00098 00099 virtual bool restore(FILE* f); 00100 00101 00102 virtual std::vector<AbstractController*> getControllers() const { return ctrl;} 00103 00104 protected: 00105 std::vector<AbstractController*> ctrl; 00106 ControllerGenerator* controllerGenerator; 00107 int numCtrlCreateBeforeInit; 00108 int numContextSensors; 00109 int motornumber; 00110 int sensornumber; 00111 double* sensorbuffer; 00112 }; 00113 00114 #endif