Robot Simulator of the Robotics Group for Self-Organization of Control: abstractcontrolleradapter.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# abstractcontrolleradapter.h

Go to the documentation of this file.

    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.4  2009/08/05 22:58:13  martius
    00025  *   use copy constructor for abstractcontroller -> config and inspection works
    00026  *   configurable interface passthrough
    00027  *
    00028  *   Revision 1.3  2009/03/25 11:46:58  robot1
    00029  *   bugfix
    00030  *
    00031  *   Revision 1.2  2008/04/17 14:54:44  martius
    00032  *   randomGen added, which is a random generator with long period and an
    00033  *    internal state. Each Agent has an instance and passed it to the controller
    00034  *    and the wiring. This is good for
    00035  *   a) repeatability on agent basis,
    00036  *   b) parallel execution as done in ode_robots
    00037  *
    00038  *   Revision 1.1  2007/03/22 08:05:03  robot3
    00039  *   this is an adapter class which implements all needed things. This class is
    00040  *   used for example by the DiscreteControllerAdapter.
    00041  *
    00042
    00043  *                                                                         *
    00044  ***************************************************************************/
    00045 #ifndef __ABSTRACTCONTROLLERADAPTER_H
    00046 #define __ABSTRACTCONTROLLERADAPTER_H
    00047
    00048 #include "abstractcontroller.h"
    00049
    00050 /**
    00051  * Abstract adapter class (interface) for robot controller.
    00052  * The controller gets a number of input sensor values each timestep
    00053  *  and has to generate a number of output motor values.
    00054  *
    00055  * Interface assumes the following usage:
    00056  *  - init() is called first to initialise the dimension of sensor- and motor space
    00057  *  - each time step
    00058  *     either step() or stepNoLearning() is called to ask the controller for motor values.
    00059  *
    00060  * This is an abstract adapter class, it's useful for implementing adapters such as the
    00061  * DescreteController, which can be used with all Controllers.
    00062  *
    00063  * Note that the configureable and inspectable classes hold internal lists
    00064  *  that are copied here. If a new parameter is added to either interfaces
    00065  *  after the call of the contructor then this will not be visible througt the adapter
    00066  *  (at least partially. get and set will work but not the printing (also used by store))
    00067  */
    00068 class AbstractControllerAdapter : public AbstractController {
    00069 public:
    00070
    00071   AbstractControllerAdapter(AbstractController* controller)
    00072     : AbstractController(*controller), controller(controller)
    00073   { // Note that we use the copy constructor of AbtractController here to
    00074     //  copy the inspectable and configureable lists
    00075   }
    00076
    00077   /// contructor (hint: use $ID$ for revision)
    00078   AbstractControllerAdapter(AbstractController* controller,
    00079                             const std::string& name, const std::string& revision)
    00080     : AbstractController(*controller), controller(controller)
    00081   { // Note that we use the copy constructor of AbtractController here to
    00082     //  copy the inspectable and configureable lists
    00083   }
    00084
    00085
    00086   virtual ~AbstractControllerAdapter() {}
    00087
    00088   /****************************************************************************/
    00089   /*    AbstractControllerAdapter must implement the following classes:         */
    00090   /*    AbstractController, Configurable, Inspectable, Storeable                    */
    00091   /****************************************************************************/
    00092
    00093
    00094   /****************************************************************************/
    00095   /*    BEGIN methods of AbstractController                                     */
    00096   /****************************************************************************/
    00097
    00098   /** initialisation of the controller with the given sensor/ motornumber
    00099    * Must NORMALLY be called before use. For all ControllerAdapters
    00100    * call first AbstractControllerAdapter::init(sensornumber,motornumber)
    00101    * if you overwrite this method
    00102    */
    00103   virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0){
    00104     //          this->sensorNumber=sensornumber;
    00105     //          this->motorNumber=motornumber;
    00106     controller->init(sensornumber,motornumber);
    00107   }
    00108
    00109   /** @return Number of sensors the controller
    00110       was initialised with or 0 if not initialised */
    00111   virtual int getSensorNumber() const { return controller->getSensorNumber();}
    00112
    00113   /** @return Number of motors the controller
    00114       was initialised with or 0 if not initialised */
    00115   virtual int getMotorNumber() const {  return controller->getMotorNumber();}
    00116
    00117   /** performs one step (includes learning).
    00118       Calculates motor commands from sensor inputs.
    00119       @param sensors sensors inputs scaled to [-1,1]
    00120       @param sensornumber length of the sensor array
    00121       @param motors motors outputs. MUST have enough space for motor values!
    00122       @param motornumber length of the provided motor array
    00123   */
    00124   virtual void step(const sensor* sensors, int sensornumber,
    00125                     motor* motors, int motornumber) {
    00126     controller->step(sensors, sensornumber, motors,  motornumber);
    00127   }
    00128
    00129   /** performs one step without learning.
    00130       @see step
    00131   */
    00132   virtual void stepNoLearning(const sensor* sensors , int sensornumber,
    00133                               motor* motors, int motornumber) {
    00134     controller->stepNoLearning(sensors,sensornumber,motors,motornumber);
    00135   }
    00136
    00137   /****************************************************************************/
    00138   /*    END methods of AbstractController                                           */
    00139   /****************************************************************************/
    00140
    00141   /****************************************************************************/
    00142   /*    BEGIN methods of Configurable                                           */
    00143   /****************************************************************************/
    00144
    00145   virtual paramval getParam(const paramkey& key) const {
    00146     return controller->getParam(key);
    00147   }
    00148
    00149   virtual bool setParam(const paramkey& key, paramval val){
    00150     return controller->setParam(key,val);
    00151   }
    00152
    00153   virtual paramlist getParamList() const {
    00154     return controller->getParamList();
    00155   }
    00156
    00157   /****************************************************************************/
    00158   /*    END methods of Configurable                                                 */
    00159   /****************************************************************************/
    00160
    00161   /****************************************************************************/
    00162   /*    BEGIN methods of Inspectable                                            */
    00163   /****************************************************************************/
    00164
    00165   /** The list of the names of all internal parameters given by getInternalParams().
    00166       The naming convention is "v[i]" for vectors
    00167       and "A[i][j]" for matrices, where i, j start at 0.
    00168       @return: list of keys
    00169   */
    00170   virtual iparamkeylist getInternalParamNames() const { return controller->getInternalParamNames();}
    00171
    00172   /** @return: list of values
    00173    */
    00174   virtual iparamvallist getInternalParams() const { return controller->getInternalParams(); }
    00175
    00176   /****************************************************************************/
    00177   /*    END methods of Inspectable                                                  */
    00178   /****************************************************************************/
    00179
    00180   /****************************************************************************/
    00181   /*    BEGIN methods of Storable                                               */
    00182   /****************************************************************************/
    00183
    00184   /********* STORABLE INTERFACE ******/
    00185   /// @see Storable
    00186   virtual bool store(FILE* f) const {
    00187     return controller->store(f);
    00188   }
    00189
    00190   /// @see Storable
    00191   virtual bool restore(FILE* f) {
    00192     return controller->restore(f);
    00193   }
    00194
    00195
    00196   /****************************************************************************/
    00197   /*    END methods of Storable                                             */
    00198   /****************************************************************************/
    00199
    00200
    00201 protected:
    00202   AbstractController* controller; // the controller for the adapter to handle
    00203   //    int sensorNumber; // number of sensors the controller has
    00204   //    int motorNumber; // number of motors the controller has
    00205
    00206 };
    00207
    00208 #endif