invertmotorbigmodel.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: invertmotorbigmodel.h,v $ 00020 * Revision 1.3 2006/12/21 11:44:17 martius 00021 * commenting style for doxygen //< -> ///< 00022 * FOREACH and FOREACHC are macros for collection iteration 00023 * 00024 * Revision 1.2 2006/11/29 16:22:43 martius 00025 * name is a variable of configurable and is used as such 00026 * 00027 * Revision 1.1 2006/07/20 17:15:25 martius 00028 * controller with arbitrary invertable model 00029 * 00030 * 00031 ***************************************************************************/ 00032 #ifndef __INVERTMOTORBIGMODEL_H 00033 #define __INVERTMOTORBIGMODEL_H 00034 00035 #include "invertmotorcontroller.h" 00036 00037 #include <assert.h> 00038 #include <math.h> 00039 00040 #include "matrix.h" 00041 #include "noisegenerator.h" 00042 #include "invertablemodel.h" 00043 00044 typedef struct InvertMotorBigModelConf { 00045 int buffersize; ///< buffersize size of the time-buffer for x,y,eta 00046 double cInit; ///< cInit size of the C matrix to initialised with. 00047 double cNonDiag; ///< cNonDiag is the size of the nondiagonal elements in respect to the diagonal (cInit) ones 00048 bool modelInit; ///< size of the unit-map strenght of the model 00049 bool someInternalParams; ///< someInternalParams if true only some internal parameters are exported, otherwise all 00050 bool useTeaching; ///< if true, the controller honors the teaching signal 00051 00052 InvertableModel* model; ///< model used as world model 00053 } InvertMotorNStepConf; 00054 00055 /** 00056 * class for robot controller is based on InvertMotorNStep 00057 * 00058 * - direct inversion 00059 * 00060 * - motor space 00061 * 00062 * - multilayer,nonlinear model 00063 */ 00064 class InvertMotorBigModel : public InvertMotorController { 00065 00066 public: 00067 InvertMotorBigModel(const InvertMotorBigModelConf& conf = getDefaultConf()); 00068 virtual void init(int sensornumber, int motornumber); 00069 00070 virtual ~InvertMotorBigModel(); 00071 00072 /// returns the number of sensors the controller was initialised with or 0 if not initialised 00073 virtual int getSensorNumber() const { return number_sensors; } 00074 /// returns the mumber of motors the controller was initialised with or 0 if not initialised 00075 virtual int getMotorNumber() const { return number_motors; } 00076 00077 /// performs one step (includes learning). 00078 /// Calulates motor commands from sensor inputs. 00079 virtual void step(const sensor* , int number_sensors, motor* , int number_motors); 00080 00081 /// performs one step without learning. Calulates motor commands from sensor inputs. 00082 virtual void stepNoLearning(const sensor* , int number_sensors, 00083 motor* , int number_motors); 00084 00085 00086 /************** STOREABLE **********************************/ 00087 /** stores the controller values to a given file. */ 00088 virtual bool store(FILE* f) const; 00089 /** loads the controller values from a given file. */ 00090 virtual bool restore(FILE* f); 00091 00092 /************** INSPECTABLE ********************************/ 00093 virtual iparamkeylist getInternalParamNames() const; 00094 virtual iparamvallist getInternalParams() const; 00095 virtual ilayerlist getStructuralLayers() const; 00096 virtual iconnectionlist getStructuralConnections() const; 00097 00098 /************** CONFIGURABLE ********************************/ 00099 virtual paramval getParam(const paramkey& key) const; 00100 virtual bool setParam(const paramkey& key, paramval val); 00101 virtual paramlist getParamList() const; 00102 00103 00104 00105 /**** TEACHING ****/ 00106 virtual void setTeachingMode(bool onOff); 00107 virtual bool getTeachingMode(); 00108 virtual void setMotorTeachingSignal(const motor* teaching, int len); 00109 void calcCandHUpdatesTeaching(matrix::Matrix& C_update, matrix::Matrix& H_update, int y_delay); 00110 00111 00112 static InvertMotorBigModelConf getDefaultConf(){ 00113 InvertMotorBigModelConf c; 00114 c.buffersize = 50; 00115 c.cInit = 1.0; 00116 c.cNonDiag = 0; 00117 c.modelInit = 1.0; 00118 c.someInternalParams = true; 00119 c.useTeaching = false; 00120 c.model = 0; 00121 return c; 00122 } 00123 00124 void getLastMotors(motor* motors, int len); 00125 00126 protected: 00127 unsigned short number_sensors; 00128 unsigned short number_motors; 00129 00130 matrix::Matrix A; ///< current response function of the model 00131 00132 matrix::Matrix C; ///< Controller Matrix 00133 matrix::Matrix H; ///< Controller Bias 00134 00135 matrix::Matrix R; ///< C*A 00136 matrix::Matrix SmallID; ///< small identity matrix in the dimension of R 00137 matrix::Matrix xsi; ///< current output error 00138 double xsi_norm; ///< norm of matrix 00139 double xsi_norm_avg; ///< average norm of xsi (used to define whether Modell learns) 00140 double pain; ///< if the modelling error (xsi) is too high we have a pain signal 00141 matrix::Matrix* x_buffer; 00142 matrix::Matrix* y_buffer; 00143 matrix::Matrix* eta_buffer; 00144 matrix::Matrix zero_eta; // zero initialised eta 00145 matrix::Matrix x_smooth; 00146 // matrix::Matrix z; ///< membrane potential 00147 00148 matrix::Matrix y_teaching; ///< teaching motor signal 00149 00150 InvertMotorBigModelConf conf; 00151 00152 /// puts the sensors in the ringbuffer, generate controller values and put them in the 00153 // ringbuffer as well 00154 virtual void fillBuffersAndControl(const sensor* x_, int number_sensors, 00155 motor* y_, int number_motors); 00156 00157 /// calculates the first shift into the motor space useing delayed motor values. 00158 // @param delay 0 for no delay and n>0 for n timesteps delay in the time loop 00159 virtual void calcEtaAndBufferIt(int delay); 00160 00161 /// learn H,C with motors y and corresponding sensors x 00162 virtual void learnController(); 00163 00164 /// calculates the Update for C and H 00165 // @param y_delay timesteps to delay the y-values. (usually 0) 00166 // Please note that the delayed values are NOT used for the error calculation 00167 // (this is done in calcXsi()) 00168 virtual void calcCandHUpdates(matrix::Matrix& C_update, matrix::Matrix& H_update, int y_delay); 00169 00170 /// updates the matrix C and H 00171 virtual void updateCandH(const matrix::Matrix& C_update, const matrix::Matrix& H_update, double squashSize); 00172 00173 /// learn A, (and S) using motors y and corresponding sensors x 00174 // @param delay 0 for no delay and n>0 for n timesteps delay in the time loop 00175 virtual void learnModel(int delay); 00176 00177 /// returns controller output for given sensor values 00178 virtual matrix::Matrix calculateControllerValues(const matrix::Matrix& x_smooth); 00179 00180 /// calculates the error_factor for either logarithmic (E=ln(e^T*e)) or square (E=sqrt(e^t*e)) error 00181 virtual double calcErrorFactor(const matrix::Matrix& e, bool loga, bool root); 00182 00183 00184 }; 00185 00186 #endif

Generated on Tue Jan 16 02:14:36 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8