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

# invertmotorspace.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 by                                            *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00005  *                                                                         *
    00006  *   ANY COMMERCIAL USE FORBIDDEN!                                         *
    00007  *   LICENSE:                                                              *
    00008  *   This work is licensed under the Creative Commons                      *
    00009  *   Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of   *
    00010  *   this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
    00011  *   or send a letter to Creative Commons, 543 Howard Street, 5th Floor,   *
    00012  *   San Francisco, California, 94105, USA.                                *
    00013  *                                                                         *
    00014  *   This program is distributed in the hope that it will be useful,       *
    00015  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00016  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *
    00017  *                                                                         *
    00018  ***************************************************************************/
    00019 #ifndef __INVERTMOTORSPACE_H
    00020 #define __INVERTMOTORSPACE_H
    00021
    00022 #include "invertmotorcontroller.h"
    00023 #include <assert.h>
    00024 #include <cmath>
    00025
    00026 #include <selforg/matrix.h>
    00027 #include <selforg/noisegenerator.h>
    00028
    00029 /**
    00030  * class for robot controller that uses the georg's matrixlib for
    00031  *  direct matrix inversion for n channels
    00032  * (simple one layer networks)
    00033  *
    00034  * Implements standart parameters: eps, rho, mu, stepnumber4avg, stepnumber4delay
    00035  */
    00036 class InvertMotorSpace : public InvertMotorController {
    00037
    00038 public:
    00039   InvertMotorSpace(int buffersize, double cInit = 0.1 , bool someInternalParams = true);
    00040   virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
    00041
    00042   virtual ~InvertMotorSpace();
    00043
    00044   /// returns the number of sensors the controller was initialised with or 0 if not initialised
    00045   virtual int getSensorNumber() const { return number_sensors; }
    00046   /// returns the mumber of motors the controller was initialised with or 0 if not initialised
    00047   virtual int getMotorNumber() const  { return number_motors; }
    00048
    00049   /// performs one step (includes learning).
    00050   /// Calulates motor commands from sensor inputs.
    00051   virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
    00052
    00053   /// performs one step without learning. Calulates motor commands from sensor inputs.
    00054   virtual void stepNoLearning(const sensor* , int number_sensors,
    00055                               motor* , int number_motors);
    00056
    00057   /**** STOREABLE ****/
    00058   /** stores the controller values to a given file (binary).  */
    00059   virtual bool store(FILE* f) const;
    00060   /** loads the controller values from a given file (binary). */
    00061   virtual bool restore(FILE* f);
    00062
    00063   // inspectable interface
    00064   virtual std::list<ILayer> getStructuralLayers() const;
    00065   virtual std::list<IConnection> getStructuralConnections() const;
    00066
    00067
    00068 protected:
    00069   unsigned short number_sensors;
    00070   unsigned short number_motors;
    00071
    00072   matrix::Matrix A; // Model Matrix
    00073   matrix::Matrix C; // Controller Matrix
    00074   matrix::Matrix R; // C*A
    00075   matrix::Matrix H; // Controller Bias
    00076   matrix::Matrix B; // Model Bias
    00077   NoiseGenerator* BNoiseGen; // Noisegenerator for noisy bias
    00078   matrix::Matrix* x_buffer;
    00079   matrix::Matrix* y_buffer;
    00080   matrix::Matrix x_smooth;
    00081
    00082   bool someInternalParams;
    00083   double cInit;
    00084
    00085   /// puts the sensors in the ringbuffer, generate controller values and put them in the
    00086   //  ringbuffer as well
    00087   void fillBuffersAndControl(const sensor* x_, int number_sensors,
    00088                              motor* y_, int number_motors);
    00089
    00090   /// learn h,C, delayed motors y and corresponding sensors x
    00091   virtual void learnController(const matrix::Matrix& x, const matrix::Matrix& x_smooth, int delay);
    00092
    00093   /// learn A, using motors y and corresponding sensors x
    00094   virtual void learnModel( const matrix::Matrix& x, const matrix::Matrix& y);
    00095
    00096   /// returns controller output for given sensor values
    00097   virtual matrix::Matrix calculateControllerValues(const matrix::Matrix& x_smooth);
    00098
    00099 };
    00100
    00101 #endif