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

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

- Search for |

- File List
- File Members

# invertmotorspace.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  *                                                                         *
    00007  *   ANY COMMERCIAL USE FORBIDDEN!                                         *
    00008  *   LICENSE:                                                              *
    00009  *   This work is licensed under the Creative Commons                      *
    00010  *   Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of   *
    00011  *   this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
    00012  *   or send a letter to Creative Commons, 543 Howard Street, 5th Floor,   *
    00013  *   San Francisco, California, 94105, USA.                                *
    00014  *                                                                         *
    00015  *   This program is distributed in the hope that it will be useful,       *
    00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *
    00018  *                                                                         *
    00019  *   $Log: invertmotorspace.h,v $
    00020  *   Revision 1.23  2009/10/23 12:39:03  martius
    00021  *   added description for inspectable elements
    00022  *
    00023  *   Revision 1.22  2008/05/30 11:58:27  martius
    00024  *   use cmath instead of math.h
    00025  *
    00026  *   Revision 1.21  2008/04/17 14:54:45  martius
    00027  *   randomGen added, which is a random generator with long period and an
    00028  *    internal state. Each Agent has an instance and passed it to the controller
    00029  *    and the wiring. This is good for
    00030  *   a) repeatability on agent basis,
    00031  *   b) parallel execution as done in ode_robots
    00032  *
    00033  *   Revision 1.20  2006/11/29 16:22:43  martius
    00034  *   name is a variable of configurable and is used as such
    00035  *
    00036  *   Revision 1.19  2006/07/20 17:14:34  martius
    00037  *   removed std namespace from matrix.h
    00038  *   storable interface
    00039  *   abstract model and invertablemodel as superclasses for networks
    00040  *
    00041  *   Revision 1.18  2006/07/18 15:17:16  martius
    00042  *   buffer operations like delayed values and smoothed values moved to invertmotorcontroller
    00043  *
    00044  *   Revision 1.17  2006/07/14 12:23:58  martius
    00045  *   selforg becomes HEAD
    00046  *
    00047  *   Revision 1.15.6.4  2006/07/10 13:05:16  martius
    00048  *   NON-COMMERICAL LICENSE added to controllers
    00049  *
    00050  *   Revision 1.15.6.3  2006/07/10 11:59:24  martius
    00051  *   Matrixlib now in selforg
    00052  *   no namespace std in header files
    00053  *
    00054  *   Revision 1.15.6.2  2006/01/18 16:48:35  martius
    00055  *   stored and restore
    00056  *
    00057  *   Revision 1.15.6.1  2005/11/14 14:54:30  martius
    00058  *   cpp file is separate now
    00059  *
    00060  *   Revision 1.15  2005/10/27 15:46:38  martius
    00061  *   inspectable interface is expanded to structural information for network visualiser
    00062  *
    00063  *   Revision 1.14  2005/10/06 17:08:40  martius
    00064  *   switched to stl lists
    00065  *   Bias noise
    00066  *   correct error_factor for controller learning
    00067  *
    00068  *   Revision 1.13  2005/08/22 20:32:09  martius
    00069  *   C- initialisation variable
    00070  *
    00071  *   Revision 1.12  2005/08/03 20:31:14  martius
    00072  *   destructor added
    00073  *
    00074  *   Revision 1.11  2005/07/21 11:33:01  fhesse
    00075  *   R as internal parameter instead of C
    00076  *
    00077  *   Revision 1.10  2005/07/21 09:40:48  martius
    00078  *   moved squashing and g to superclass
    00079  *
    00080  *   Revision 1.9  2005/07/05 14:48:18  martius
    00081  *   desens removed
    00082  *   zeta update is continuous
    00083  *
    00084  *   Revision 1.8  2005/07/04 15:23:27  martius
    00085  *   x_smooth used for controller learning
    00086  *
    00087  *   Revision 1.7  2005/06/29 08:30:28  martius
    00088  *   inherited from invertmotorcontroller
    00089  *
    00090  *   Revision 1.6  2005/06/21 15:31:11  martius
    00091  *   getSensorNumber and getMotorMumber added controller interface
    00092  *
    00093  *   Revision 1.5  2005/06/20 09:04:16  martius
    00094  *   init function added to controller-interface
    00095  *
    00096  *   Revision 1.4  2005/06/16 14:23:14  martius
    00097  *   GPL and name member added
    00098  *
    00099  ***************************************************************************/
    00100 #ifndef __INVERTMOTORSPACE_H
    00101 #define __INVERTMOTORSPACE_H
    00102
    00103 #include "invertmotorcontroller.h"
    00104 #include <assert.h>
    00105 #include <cmath>
    00106
    00107 #include <selforg/matrix.h>
    00108 #include <selforg/noisegenerator.h>
    00109
    00110 /**
    00111  * class for robot controller that uses the georg's matrixlib for
    00112  *  direct matrix inversion for n channels
    00113  * (simple one layer networks)
    00114  *
    00115  * Implements standart parameters: eps, rho, mu, stepnumber4avg, stepnumber4delay
    00116  */
    00117 class InvertMotorSpace : public InvertMotorController {
    00118
    00119 public:
    00120   InvertMotorSpace(int buffersize, double cInit = 0.1 , bool someInternalParams = true);
    00121   virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
    00122
    00123   virtual ~InvertMotorSpace();
    00124
    00125   /// returns the number of sensors the controller was initialised with or 0 if not initialised
    00126   virtual int getSensorNumber() const { return number_sensors; }
    00127   /// returns the mumber of motors the controller was initialised with or 0 if not initialised
    00128   virtual int getMotorNumber() const  { return number_motors; }
    00129
    00130   /// performs one step (includes learning).
    00131   /// Calulates motor commands from sensor inputs.
    00132   virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
    00133
    00134   /// performs one step without learning. Calulates motor commands from sensor inputs.
    00135   virtual void stepNoLearning(const sensor* , int number_sensors,
    00136                               motor* , int number_motors);
    00137
    00138   /**** STOREABLE ****/
    00139   /** stores the controller values to a given file (binary).  */
    00140   virtual bool store(FILE* f) const;
    00141   /** loads the controller values from a given file (binary). */
    00142   virtual bool restore(FILE* f);
    00143
    00144   // inspectable interface
    00145   virtual std::list<ILayer> getStructuralLayers() const;
    00146   virtual std::list<IConnection> getStructuralConnections() const;
    00147
    00148
    00149 protected:
    00150   unsigned short number_sensors;
    00151   unsigned short number_motors;
    00152
    00153   matrix::Matrix A; // Model Matrix
    00154   matrix::Matrix C; // Controller Matrix
    00155   matrix::Matrix R; // C*A
    00156   matrix::Matrix H; // Controller Bias
    00157   matrix::Matrix B; // Model Bias
    00158   NoiseGenerator* BNoiseGen; // Noisegenerator for noisy bias
    00159   matrix::Matrix* x_buffer;
    00160   matrix::Matrix* y_buffer;
    00161   matrix::Matrix x_smooth;
    00162
    00163   bool someInternalParams;
    00164   double cInit;
    00165
    00166   /// puts the sensors in the ringbuffer, generate controller values and put them in the
    00167   //  ringbuffer as well
    00168   void fillBuffersAndControl(const sensor* x_, int number_sensors,
    00169                              motor* y_, int number_motors);
    00170
    00171   /// learn h,C, delayed motors y and corresponding sensors x
    00172   virtual void learnController(const matrix::Matrix& x, const matrix::Matrix& x_smooth, int delay);
    00173
    00174   /// learn A, using motors y and corresponding sensors x
    00175   virtual void learnModel( const matrix::Matrix& x, const matrix::Matrix& y);
    00176
    00177   /// returns controller output for given sensor values
    00178   virtual matrix::Matrix calculateControllerValues(const matrix::Matrix& x_smooth);
    00179
    00180 };
    00181
    00182 #endif