Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
invertmotorspace.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 by *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Ralf Der <ralfder at mis dot mpg dot de> *
5  * *
6  * ANY COMMERCIAL USE FORBIDDEN! *
7  * LICENSE: *
8  * This work is licensed under the Creative Commons *
9  * Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of *
10  * this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
11  * or send a letter to Creative Commons, 543 Howard Street, 5th Floor, *
12  * San Francisco, California, 94105, USA. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
17  * *
18  ***************************************************************************/
19 #ifndef __INVERTMOTORSPACE_H
20 #define __INVERTMOTORSPACE_H
21 
22 #include "invertmotorcontroller.h"
23 #include <assert.h>
24 #include <cmath>
25 
26 #include <selforg/matrix.h>
27 #include <selforg/noisegenerator.h>
28 
29 /**
30  * class for robot controller that uses the georg's matrixlib for
31  * direct matrix inversion for n channels
32  * (simple one layer networks)
33  *
34  * Implements standart parameters: eps, rho, mu, stepnumber4avg, stepnumber4delay
35  */
37 
38 public:
39  InvertMotorSpace(int buffersize, double cInit = 0.1 , bool someInternalParams = true);
40  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
41 
42  virtual ~InvertMotorSpace();
43 
44  /// returns the number of sensors the controller was initialised with or 0 if not initialised
45  virtual int getSensorNumber() const { return number_sensors; }
46  /// returns the mumber of motors the controller was initialised with or 0 if not initialised
47  virtual int getMotorNumber() const { return number_motors; }
48 
49  /// performs one step (includes learning).
50  /// Calulates motor commands from sensor inputs.
51  virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
52 
53  /// performs one step without learning. Calulates motor commands from sensor inputs.
54  virtual void stepNoLearning(const sensor* , int number_sensors,
55  motor* , int number_motors);
56 
57  /**** STOREABLE ****/
58  /** stores the controller values to a given file (binary). */
59  virtual bool store(FILE* f) const;
60  /** loads the controller values from a given file (binary). */
61  virtual bool restore(FILE* f);
62 
63  // inspectable interface
64  virtual std::list<ILayer> getStructuralLayers() const;
65  virtual std::list<IConnection> getStructuralConnections() const;
66 
67 
68 protected:
69  unsigned short number_sensors;
70  unsigned short number_motors;
71 
72  matrix::Matrix A; // Model Matrix
73  matrix::Matrix C; // Controller Matrix
74  matrix::Matrix R; // C*A
75  matrix::Matrix H; // Controller Bias
76  matrix::Matrix B; // Model Bias
77  NoiseGenerator* BNoiseGen; // Noisegenerator for noisy bias
81 
83  double cInit;
84 
85  /// puts the sensors in the ringbuffer, generate controller values and put them in the
86  // ringbuffer as well
87  void fillBuffersAndControl(const sensor* x_, int number_sensors,
88  motor* y_, int number_motors);
89 
90  /// learn h,C, delayed motors y and corresponding sensors x
91  virtual void learnController(const matrix::Matrix& x, const matrix::Matrix& x_smooth, int delay);
92 
93  /// learn A, using motors y and corresponding sensors x
94  virtual void learnModel( const matrix::Matrix& x, const matrix::Matrix& y);
95 
96  /// returns controller output for given sensor values
98 
99 };
100 
101 #endif
Matrix type.
Definition: matrix.h:65
matrix::Matrix * y_buffer
Definition: invertmotorspace.h:79
class for robot controller that uses the georg's matrixlib for direct matrix inversion for n channels...
Definition: invertmotorspace.h:36
virtual void init(int sensornumber, int motornumber, RandGen *randGen=0)
initialisation of the controller with the given sensor/ motornumber Must be called before use...
Definition: invertmotorspace.cpp:52
double sensor
Definition: types.h:29
unsigned short number_motors
Definition: invertmotorspace.h:70
virtual std::list< ILayer > getStructuralLayers() const
Specifies which parameter vector forms a structural layer (in terms of a neural network) The ordering...
Definition: invertmotorspace.cpp:240
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
virtual void learnModel(const matrix::Matrix &x, const matrix::Matrix &y)
learn A, using motors y and corresponding sensors x
Definition: invertmotorspace.cpp:192
virtual std::list< IConnection > getStructuralConnections() const
Specifies which parameter matrix forms a connection between layers (in terms of a neural network) The...
Definition: invertmotorspace.cpp:248
unsigned short buffersize
Definition: homeokinbase.h:68
matrix::Matrix x_smooth
Definition: invertmotorspace.h:80
matrix::Matrix B
Definition: invertmotorspace.h:76
matrix::Matrix R
Definition: invertmotorspace.h:74
double sensor
Definition: abstractcontroller.h:48
virtual void learnController(const matrix::Matrix &x, const matrix::Matrix &x_smooth, int delay)
learn h,C, delayed motors y and corresponding sensors x
Definition: invertmotorspace.cpp:137
matrix::Matrix * x_buffer
Definition: invertmotorspace.h:78
matrix::Matrix A
Definition: invertmotorspace.h:72
Extended HomeokinBase class (still abstract) for robot controller work in motorspace and use possibly...
Definition: invertmotorcontroller.h:36
virtual matrix::Matrix calculateControllerValues(const matrix::Matrix &x_smooth)
returns controller output for given sensor values
Definition: invertmotorspace.cpp:212
matrix::Matrix C
Definition: invertmotorspace.h:73
virtual bool store(FILE *f) const
stores the controller values to a given file (binary).
Definition: invertmotorspace.cpp:217
virtual int getSensorNumber() const
returns the number of sensors the controller was initialised with or 0 if not initialised ...
Definition: invertmotorspace.h:45
void fillBuffersAndControl(const sensor *x_, int number_sensors, motor *y_, int number_motors)
puts the sensors in the ringbuffer, generate controller values and put them in the ...
Definition: invertmotorspace.cpp:112
virtual int getMotorNumber() const
returns the mumber of motors the controller was initialised with or 0 if not initialised ...
Definition: invertmotorspace.h:47
double cInit
Definition: invertmotorspace.h:83
double motor
Definition: types.h:30
virtual ~InvertMotorSpace()
Definition: invertmotorspace.cpp:44
virtual void step(const sensor *, int number_sensors, motor *, int number_motors)
performs one step (includes learning).
Definition: invertmotorspace.cpp:86
virtual bool restore(FILE *f)
loads the controller values from a given file (binary).
Definition: invertmotorspace.cpp:228
unsigned short number_sensors
Definition: invertmotorspace.h:69
InvertMotorSpace(int buffersize, double cInit=0.1, bool someInternalParams=true)
Definition: invertmotorspace.cpp:25
bool someInternalParams
Definition: invertmotorspace.h:82
double motor
Definition: abstractcontroller.h:49
matrix::Matrix H
Definition: invertmotorspace.h:75
virtual void stepNoLearning(const sensor *, int number_sensors, motor *, int number_motors)
performs one step without learning. Calulates motor commands from sensor inputs.
Definition: invertmotorspace.cpp:105
NoiseGenerator * BNoiseGen
Definition: invertmotorspace.h:77
Interface and basic class for noise generator.
Definition: noisegenerator.h:37