derivativewiring.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  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  *                                                                         *
00022  *   $Log: derivativewiring.h,v $
00023  *   Revision 1.9  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.8  2007/12/12 10:26:14  der
00031  *   MI: calculation of H(X) and H(Y|X) added
00032  *
00033  *   Revision 1.7  2006/12/21 11:44:17  martius
00034  *   commenting style for doxygen //< -> ///<
00035  *   FOREACH and FOREACHC are macros for collection iteration
00036  *
00037  *   Revision 1.6  2006/12/12 09:43:40  martius
00038  *   getDefaultConf1()
00039  *
00040  *   Revision 1.5  2006/12/11 18:23:11  martius
00041  *   changed order again: first all sensors, then all derivatives ...
00042  *   noise is only added to first sensor set
00043  *   now 2 functions for default configs
00044  *   blind motors not as sets, but as direct number given
00045  *
00046  *   Revision 1.4  2006/12/04 17:44:28  martius
00047  *   unclear
00048  *
00049  *   Revision 1.3  2006/12/04 16:05:10  der
00050  *   under construction
00051  *
00052  *   Revision 1.2  2006/07/14 12:24:02  martius
00053  *   selforg becomes HEAD
00054  *
00055  *   Revision 1.1.2.1  2005/11/16 11:24:28  martius
00056  *   moved to selforg
00057  *
00058  *   Revision 1.6  2005/10/28 12:05:27  martius
00059  *   adapted time horizont for derivative
00060  *    to quater of the time horizont of averaging
00061  *
00062  *   Revision 1.5  2005/10/24 13:32:07  fhesse
00063  *   comments adjusted and in doxygen style
00064  *
00065  *   Revision 1.4  2005/10/24 11:06:33  fhesse
00066  *   comments adjusted and in doxygen style
00067  *
00068  *   Revision 1.3  2005/07/21 15:09:00  martius
00069  *   blind motors
00070  *
00071  *   Revision 1.2  2005/07/21 11:30:59  fhesse
00072  *   started with blind motors
00073  *
00074  *   Revision 1.1  2005/07/18 14:44:55  martius
00075  *   wiring that supports derivatives
00076  *
00077  *                                                                         *
00078  ***************************************************************************/
00079 #ifndef __DERIVATIVEWIRING_H
00080 #define __DERIVATIVEWIRING_H
00081 
00082 #include "abstractwiring.h"
00083 
00084 /**  Configuration Object for DerivativeWiring.
00085      If all boolean parametes are false, id is set to true (equivalent to One2OneWiring)
00086 */
00087 typedef struct __DerivativeWiringConf {
00088   bool useId;        //< include zeroth derivative
00089   bool useFirstD;   ///< include first derivative
00090   bool useSecondD;  ///< second include second derivative
00091   double eps;       ///< update rate for floating average (0 -> no sensor variation, 1 -> no smoothing)
00092   double derivativeScale;   ///< factor for the derivatives
00093   unsigned int blindMotors;   ///< number of motors that are blind (not given to robot)
00094 } DerivativeWiringConf;
00095 
00096 
00097 /** Implements a wiring (between controller and robot) 
00098     which includes the first and second derivative 
00099     of the original robot sensor values
00100 */
00101 class DerivativeWiring : public AbstractWiring{
00102 public:
00103   /** constructor
00104       @param conf  for giving the wished configuration of DerivativeWiring 
00105       via \ref __DerivativeWiringConf "DerivativeWiringConf" 
00106       @param noise NoiseGenerator that is used for adding noise to sensor values  
00107   */
00108   DerivativeWiring(const DerivativeWiringConf& conf, 
00109                    NoiseGenerator* noise);
00110 
00111   /** destructor
00112    */
00113   virtual ~DerivativeWiring();
00114 
00115   /** initializes the internal numbers of sensors and motors on robot side, calculate
00116       number of sensors and motors on controller side
00117   */
00118   virtual bool init(int robotsensornumber, int robotmotornumber, RandGen* randGen=0);
00119 
00120   /** Realizes derivative wiring from robot sensors to controller sensors. 
00121       @param rsensors pointer to array of sensorvalues from robot 
00122       @param rsensornumber number of sensors from robot
00123       @param csensors pointer to array of sensorvalues for controller  
00124       @param csensornumber number of sensors to controller
00125       @param noise size of the noise added to the sensors
00126   */
00127   virtual bool wireSensors(const sensor* rsensors, int rsensornumber, 
00128                            sensor* csensors, int csensornumber,
00129                            double noise);
00130 
00131   /** Realizes wiring from controller motor outputs to robot motors. 
00132       @param rmotors pointer to array of motorvalues for robot 
00133       @param rmotornumber number of robot motors 
00134       @param cmotors pointer to array of motorvalues from controller  
00135       @param cmotornumber number of motorvalues from controller
00136   */
00137   virtual bool wireMotors(motor* rmotors, int rmotornumber,
00138                           const motor* cmotors, int cmotornumber);
00139 
00140   /** Providing default configuration for DerivativeWiring with first derivative.
00141       No smoothing and no scaling. ( as static method )
00142    */
00143   static DerivativeWiringConf getDefaultConf(){
00144     DerivativeWiringConf c;
00145     c.useId = true;        // use id
00146     c.useFirstD = false;    // use first derivative
00147     c.useSecondD = false;  // do not use secound derivative
00148     c.eps = 1;             // no smoothing
00149     c.derivativeScale=1;   // no scaleing
00150     c.blindMotors=0;       // no blind motors used
00151     return c;
00152   };
00153 
00154   /** Providing default configuration for DerivativeWiring for only first derivative. 
00155       smoothing over 4 steps and scale of 5. Use smaller noise!
00156       ( as static method )
00157    */
00158   static DerivativeWiringConf getDefaultConf1(){
00159     DerivativeWiringConf c;
00160     c.useId = false;       // do not use id
00161     c.useFirstD = true;    // use first derivative
00162     c.useSecondD = false;  // do not use secound derivative
00163     c.eps = 0.5;          // smoothing over 2 steps
00164     c.derivativeScale=5;   // scaling with 5
00165     c.blindMotors=0;       // no blind motors used
00166     return c;
00167   };
00168 
00169 protected:
00170   /** Calculate the first derivative of the sensorvalues given by the robot
00171    *  f'(x) = (f(x+1) - f(x-1)) / 2
00172    *  since we do not have f(x+1) we go one timestep in the past
00173    */
00174   void calcFirstDerivative();
00175 
00176   /** Calculate the secound derivative of the sensorvalues given by the robot
00177    *  f'(x) = f(x) - 2f(x-1) + f(x-2)
00178    */
00179   void calcSecondDerivative();
00180 
00181   /// used configuration
00182   DerivativeWiringConf conf;
00183   static const int buffersize=40;
00184   int time;
00185   /// number timesteps the sensor values are delayed for calculation of the derivative
00186   //  int delay;
00187   
00188 
00189   /// current and old smoothed sensor values of robot
00190   sensor* sensorbuffer[buffersize]; 
00191 
00192   /// current sensors (with noise)
00193   // sensor* id;
00194 
00195   /// current first derivative
00196   sensor* first;               
00197 
00198   /// current second derivative
00199   sensor* second;            
00200 
00201   /// array that stored the values of the blind motors     
00202   motor *blindMotors;        
00203 
00204 };
00205 
00206 #endif

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