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

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