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 * frankguettler@gmx.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 * $Log: abstractcontrolleradapter.h,v $ 00024 * Revision 1.2 2008/04/17 14:54:44 martius 00025 * randomGen added, which is a random generator with long period and an 00026 * internal state. Each Agent has an instance and passed it to the controller 00027 * and the wiring. This is good for 00028 * a) repeatability on agent basis, 00029 * b) parallel execution as done in ode_robots 00030 * 00031 * Revision 1.1 2007/03/22 08:05:03 robot3 00032 * this is an adapter class which implements all needed things. This class is 00033 * used for example by the DiscreteControllerAdapter. 00034 * 00035 00036 * * 00037 ***************************************************************************/ 00038 #ifndef __ABSTRACTCONTROLLERADAPTER_H 00039 #define __ABSTRACTCONTROLLERADAPTER_H 00040 00041 #include "abstractcontroller.h" 00042 00043 /** 00044 * Abstract adapter class (interface) for robot controller. 00045 * The controller gets a number of input sensor values each timestep 00046 * and has to generate a number of output motor values. 00047 * 00048 * Interface assumes the following usage: 00049 * - init() is called first to initialise the dimension of sensor- and motor space 00050 * - each time step 00051 * either step() or stepNoLearning() is called to ask the controller for motor values. 00052 * 00053 * This is an abstract adapter class, it's useful for implementing adapters such as the 00054 * DescreteController, which can be used with all Controllers. 00055 */ 00056 class AbstractControllerAdapter : public AbstractController { 00057 public: 00058 00059 /// contructor (hint: use $ID$ for revision) 00060 AbstractControllerAdapter(AbstractController* controller) 00061 : AbstractController(controller->getName(),controller->getRevision()), controller(controller) {} 00062 00063 virtual ~AbstractControllerAdapter() {} 00064 00065 /****************************************************************************/ 00066 /* AbstractControllerAdapter must implement the following classes: */ 00067 /* AbstractController, Configurable, Inspectable, Storeable */ 00068 /****************************************************************************/ 00069 00070 00071 /****************************************************************************/ 00072 /* BEGIN methods of AbstractController */ 00073 /****************************************************************************/ 00074 00075 /** initialisation of the controller with the given sensor/ motornumber 00076 * Must NORMALLY be called before use. For all ControllerAdapters 00077 * call first AbstractControllerAdapter::init(sensornumber,motornumber) 00078 * if you overwrite this method 00079 */ 00080 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0){ 00081 this->sensorNumber=sensornumber; 00082 this->motorNumber=motornumber; 00083 controller->init(sensornumber,motornumber); 00084 } 00085 00086 /** @return Number of sensors the controller 00087 was initialised with or 0 if not initialised */ 00088 virtual int getSensorNumber() const { return controller->getSensorNumber();} 00089 00090 /** @return Number of motors the controller 00091 was initialised with or 0 if not initialised */ 00092 virtual int getMotorNumber() const {return controller->getMotorNumber();} 00093 00094 /** performs one step (includes learning). 00095 Calculates motor commands from sensor inputs. 00096 @param sensors sensors inputs scaled to [-1,1] 00097 @param sensornumber length of the sensor array 00098 @param motors motors outputs. MUST have enough space for motor values! 00099 @param motornumber length of the provided motor array 00100 */ 00101 virtual void step(const sensor* sensors, int sensornumber, 00102 motor* motors, int motornumber) 00103 { controller->step(sensors, sensornumber, motors, motornumber); } 00104 00105 /** performs one step without learning. 00106 @see step 00107 */ 00108 virtual void stepNoLearning(const sensor* sensors , int sensornumber, 00109 motor* motors, int motornumber) 00110 { controller->stepNoLearning(sensors,sensornumber,motors,motornumber); } 00111 00112 /****************************************************************************/ 00113 /* END methods of AbstractController */ 00114 /****************************************************************************/ 00115 00116 /****************************************************************************/ 00117 /* BEGIN methods of Configurable */ 00118 /****************************************************************************/ 00119 00120 00121 00122 /****************************************************************************/ 00123 /* END methods of Configurable */ 00124 /****************************************************************************/ 00125 00126 /****************************************************************************/ 00127 /* BEGIN methods of Inspectable */ 00128 /****************************************************************************/ 00129 00130 /** The list of the names of all internal parameters given by getInternalParams(). 00131 The naming convention is "v[i]" for vectors 00132 and "A[i][j]" for matrices, where i, j start at 0. 00133 @return: list of keys 00134 */ 00135 virtual iparamkeylist getInternalParamNames() const { return controller->getInternalParamNames();} 00136 00137 /** @return: list of values 00138 */ 00139 virtual iparamvallist getInternalParams() const { return controller->getInternalParams(); } 00140 00141 /****************************************************************************/ 00142 /* END methods of Inspectable */ 00143 /****************************************************************************/ 00144 00145 00146 00147 protected: 00148 AbstractController* controller; // the controller for the adapter to handle 00149 int sensorNumber; // number of sensors the controller has 00150 int motorNumber; // number of motors the controller has 00151 00152 }; 00153 00154 #endif