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

Generated on Tue Sep 16 22:00:22 2008 for Robotsystem of the Robot Group Leipzig by  doxygen 1.4.7