Robotsystem of the Robot Group Leipzig: deprivation.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Examples

- Search for |

- File List
- File Members

# deprivation.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: deprivation.h,v $
    00020  *   Revision 1.3  2006/07/14 12:23:58  martius
    00021  *   selforg becomes HEAD
    00022  *
    00023  *   Revision 1.1.2.5  2006/07/10 13:05:15  martius
    00024  *   NON-COMMERICAL LICENSE added to controllers
    00025  *
    00026  *   Revision 1.1.2.4  2006/07/10 11:59:23  martius
    00027  *   Matrixlib now in selforg
    00028  *   no namespace std in header files
    00029  *
    00030  *   Revision 1.1.2.3  2006/03/29 15:11:19  martius
    00031  *   damping is now in invertmotornstep
    00032  *
    00033  *   Revision 1.1.2.2  2006/02/20 10:56:21  martius
    00034  *   lowered damping
    00035  *
    00036  *   Revision 1.1.2.1  2006/02/14 10:27:11  martius
    00037  *   investigation about deprivation of worldmodel
    00038  *
    00039  *   Revision 1.1.2.1  2006/02/08 15:14:49  martius
    00040  *   new version of proactive which uses direct H feeding
    00041  *
    00042  *
    00043  ***************************************************************************/
    00044 #ifndef __DEPRIVATION_H
    00045 #define __DEPRIVATION_H
    00046
    00047 #include "invertmotornstep.h"
    00048 #include "onelayerffnn.h"
    00049
    00050 #include <assert.h>
    00051 #include <math.h>
    00052
    00053 #include <selforg/matrix.h>
    00054
    00055 /**
    00056  * robot controller for self-organized behaviour
    00057  * just like invertmotornstep,
    00058  *  just that is enables us to execute the same motor commands for a long time
    00059  */
    00060 class Deprivation : public InvertMotorNStep {
    00061 public:
    00062   /// is called with current motor values and returns new motor values
    00063   typedef matrix::Matrix (*MotorCallback)(const matrix::Matrix& y);
    00064
    00065   /// is called with current controller matrix C and bias H which can be alterned
    00066   typedef void (*ControllerCallback)(matrix::Matrix& C, matrix::Matrix& H);
    00067
    00068   /**
    00069    */
    00070   Deprivation(MotorCallback motorCallback, ControllerCallback controllerCallback =0,
    00071               const InvertMotorNStepConf& conf = getDefaultConf())
    00072     : InvertMotorNStep(conf), motorCallback(motorCallback), controllerCallback(controllerCallback) {
    00073     assert(motorCallback);
    00074     // prepare name;
    00075     Configurable::insertCVSInfo(name, "$RCSfile: deprivation.h,v $", "$Revision: 1.3 $");
    00076     useExternal=false;
    00077   }
    00078
    00079   virtual ~Deprivation(){
    00080   }
    00081
    00082   virtual void setExternalControlMode(bool useExternal){
    00083     this->useExternal=useExternal;
    00084     if(controllerCallback && initialised){
    00085       controllerCallback(C, H);
    00086     }
    00087   }
    00088   virtual bool getExternalControlMode(){
    00089     return useExternal;
    00090   }
    00091
    00092
    00093 protected:
    00094   /// overloaded
    00095   virtual void learnController(){
    00096     if(!useExternal){
    00097       InvertMotorNStep::learnController();
    00098     }
    00099   }
    00100
    00101   /// calculate controller outputs (only of nop external value is set)
    00102   /// @param x_smooth smoothed sensors Matrix(number_channels,1)
    00103   virtual matrix::Matrix calculateControllerValues(const Matrix& x_smooth){
    00104     Matrix y = InvertMotorNStep::calculateControllerValues(x_smooth);
    00105     if(useExternal){
    00106       return motorCallback(y);
    00107     }
    00108     else
    00109       return y;
    00110   };
    00111
    00112 protected:
    00113   bool useExternal;
    00114
    00115   MotorCallback motorCallback;
    00116   ControllerCallback controllerCallback;
    00117
    00118 };
    00119
    00120 #endif