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
universalcontroller.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __UNIVERSALCONTROLLER_H
25 #define __UNIVERSALCONTROLLER_H
26 
27 
28 #include <stdio.h>
29 #include <vector>
30 #include "abstractcontroller.h"
31 #include "elman.h"
32 #include "matrix.h"
33 
34 typedef struct _UniversalControllerConf {
35  unsigned int buffersize; ///< buffersize size of the time-buffer for x,y,v
36  double init; ///< init size of the matrices of the network.
37  double squashsize; ///< update squashing
38  bool someInternalParams; ///< someInternalParams if true only some internal parameters are exported, all otherwise
39 
40  Elman* net; ///< entire contoller network (should have at least 2 layers)
41  int motorlayer; ///< index of motor layer in the network (if -1 then one but last layer)
43 
44 
45 /**
46  * class for robot control with sine and cosine
47  *
48  *
49  */
51 public:
52 
54  virtual ~UniversalController();
55 
58  c.buffersize = 50;
59  c.init = 1;
60  c.squashsize = 0.05;
61  c.someInternalParams = true;
62  c.net = 0;
63  c.motorlayer = -1;
64  return c;
65  }
66 
69  std::vector<Layer> layers;
70  // layers.push_back(Layer(20,0.5,FeedForwardNN::tanh)); // hidden layer
71  layers.push_back(Layer(0,1,FeedForwardNN::tanhr)); // motor layer
72  // size of output layer is automatically set
73  layers.push_back(Layer(1,0,FeedForwardNN::linear));
74 
75  Elman* e = new Elman(1,layers,false, false, false);
76  c.net = e;
77  return c;
78  }
79 
80  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
81 
82  virtual int getSensorNumber() const {return number_sensors;}
83 
84  virtual int getMotorNumber() const {return number_motors;}
85 
86  virtual void step(const sensor* sensors, int sensornumber,
87  motor* motors, int motornumber);
88 
89  virtual void stepNoLearning(const sensor* , int number_sensors,
90  motor* , int number_motors);
91 
92 protected:
93  /** puts the sensors in the ringbuffer,
94  generate controller values (by activating the network) and put them in the
95  ringbuffer as well */
96  void fillBuffersAndControl(const sensor* x_, int number_sensors,
97  motor* y_, int number_motors);
98 
99  /// calculate time-smoothed values
101  int number_steps_for_averaging_);
102 
103  /// calculate controller outputs (and activates inputs)
105 
106  // put new value in ring buffer
107  void putInBuffer(matrix::Matrix* buffer, const matrix::Matrix& vec, int delay=0){
108  buffer[(t-delay)%conf.buffersize] = vec;
109  }
110 
111  /** calculates the error_factor for
112  1: square (E=sqrt(e^t*e)) error;
113  2: logarithmic (E=ln(e^T*e)) or 0 for normal
114  */
115  static double calcErrorFactor(const matrix::Matrix& e, int Enorm);
116 
117 
118 public:
119  /********* INSPECTABLE INTERFACE ******/
120  virtual std::list<iparamkey> getInternalParamNames() const;
121  virtual std::list<iparamval> getInternalParams() const;
122  virtual ilayerlist getStructuralLayers() const;
124 
125  /********* STORABLE INTERFACE ******/
126  virtual bool store(FILE* f) const;
127  virtual bool restore(FILE* f);
128 
129 protected:
130 
131  unsigned int t;
132  unsigned int number_sensors;
133  unsigned int number_motors;
135 
140 
144 
153 };
154 
155 #endif
Matrix type.
Definition: matrix.h:65
static double tanhr(double z)
Definition: feedforwardnn.h:67
std::list< IConnection > iconnectionlist
Definition: inspectable.h:88
static UniversalControllerConf getDefaultNetConf()
Definition: universalcontroller.h:67
paramval s4del
Definition: universalcontroller.h:150
Definition: layer.h:31
bool initialised
Definition: universalcontroller.h:134
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
matrix::Matrix calculateSmoothValues(const matrix::Matrix *buffer, int number_steps_for_averaging_)
calculate time-smoothed values
Definition: universalcontroller.cpp:213
paramval s4avg
Definition: universalcontroller.h:149
virtual ilayerlist getStructuralLayers() const
Specifies which parameter vector forms a structural layer (in terms of a neural network) The ordering...
Definition: universalcontroller.cpp:278
double init
init size of the matrices of the network.
Definition: universalcontroller.h:36
matrix::Matrix v
Definition: universalcontroller.h:141
Elman * net
entire contoller network (should have at least 2 layers)
Definition: universalcontroller.h:40
unsigned int number_sensors
Definition: universalcontroller.h:132
double sensor
Definition: types.h:29
virtual int getMotorNumber() const
Definition: universalcontroller.h:84
Definition: universalcontroller.h:34
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
paramval epsM
Definition: universalcontroller.h:146
paramval epsDyn
Definition: universalcontroller.h:152
double paramval
Definition: configurable.h:88
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step (includes learning).
Definition: universalcontroller.cpp:94
Multilayer Neural Network with context neurons (after Elman and Jordan) Example of 2 hidden layer net...
Definition: elman.h:58
struct _UniversalControllerConf UniversalControllerConf
unsigned int number_motors
Definition: universalcontroller.h:133
paramval eps
Definition: universalcontroller.h:145
matrix::Matrix * v_buffer
Definition: universalcontroller.h:139
bool someInternalParams
someInternalParams if true only some internal parameters are exported, all otherwise ...
Definition: universalcontroller.h:38
unsigned int buffersize
buffersize size of the time-buffer for x,y,v
Definition: universalcontroller.h:35
paramval Enorm
Definition: universalcontroller.h:151
int motorlayer
index of motor layer in the network (if -1 then one but last layer)
Definition: universalcontroller.h:41
virtual void stepNoLearning(const sensor *, int number_sensors, motor *, int number_motors)
performs one step without learning.
Definition: universalcontroller.cpp:178
virtual iconnectionlist getStructuralConnections() const
Specifies which parameter matrix forms a connection between layers (in terms of a neural network) The...
Definition: universalcontroller.cpp:282
void putInBuffer(matrix::Matrix *buffer, const matrix::Matrix &vec, int delay=0)
Definition: universalcontroller.h:107
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: universalcontroller.cpp:59
UniversalControllerConf conf
Definition: universalcontroller.h:136
virtual int getSensorNumber() const
Definition: universalcontroller.h:82
matrix::Matrix * y_buffer
Definition: universalcontroller.h:138
double motor
Definition: types.h:30
virtual std::list< iparamval > getInternalParams() const
Definition: universalcontroller.cpp:266
paramval epsV
Definition: universalcontroller.h:147
matrix::Matrix J
Definition: universalcontroller.h:142
virtual std::list< iparamkey > getInternalParamNames() const
The list of the names of all internal parameters given by getInternalParams().
Definition: universalcontroller.cpp:254
class for robot control with sine and cosine
Definition: universalcontroller.h:50
virtual bool restore(FILE *f)
loads the object from the given file stream (ASCII preferred).
Definition: universalcontroller.cpp:244
matrix::Matrix xsi_smooth
Definition: universalcontroller.h:143
matrix::Matrix * x_buffer
Definition: universalcontroller.h:137
static double calcErrorFactor(const matrix::Matrix &e, int Enorm)
calculates the error_factor for 1: square (E=sqrt(e^t*e)) error; 2: logarithmic (E=ln(e^T*e)) or 0 fo...
Definition: universalcontroller.cpp:226
void fillBuffersAndControl(const sensor *x_, int number_sensors, motor *y_, int number_motors)
puts the sensors in the ringbuffer, generate controller values (by activating the network) and put th...
Definition: universalcontroller.cpp:185
virtual bool store(FILE *f) const
stores the object to the given file stream (ASCII preferred).
Definition: universalcontroller.cpp:237
static double linear(double z)
Definition: feedforwardnn.h:54
std::list< ILayer > ilayerlist
Definition: inspectable.h:87
paramval lambda
Definition: universalcontroller.h:148
UniversalController(const UniversalControllerConf &conf=getDefaultConf())
Definition: universalcontroller.cpp:33
virtual ~UniversalController()
Definition: universalcontroller.cpp:51
unsigned int t
Definition: universalcontroller.h:131
static UniversalControllerConf getDefaultConf()
Definition: universalcontroller.h:56
int c
Definition: hexapod.cpp:56
matrix::Matrix calculateControllerValues(const matrix::Matrix &x)
calculate controller outputs (and activates inputs)
Definition: universalcontroller.cpp:206
double squashsize
update squashing
Definition: universalcontroller.h:37