Robot Simulator of the Robotics Group for Self-Organization of Control: motornoisewiring.h Source File

# motornoisewiring.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************/
    00024 #ifndef __MOTORNOISEWIRING_H
    00025 #define __MOTORNOISEWIRING_H
    00026
    00027 #include <selforg/one2onewiring.h>
    00028 #include <selforg/configurable.h>
    00029
    00030 /**
    00031  *   Implements a one to one wiring that adds noise to the motor signals
    00032  *   (the sensors will get no noise)
    00033  */
    00034 class MotorNoiseWiring : public One2OneWiring, public Configurable {
    00035 public:
    00036   /** constructor
    00037       @param noise NoiseGenerator that is used for adding noise to motor values
    00038   */
    00039   MotorNoiseWiring(NoiseGenerator* noise, double noiseStrength)
    00040     : One2OneWiring(0, Controller),    // no noise at sensors, show Controller x,y and noise
    00041       Configurable("MotorNoiseWiring", "$Id$"),
    00042       motNoiseGen(noise), motNoiseStrength(noiseStrength) {
    00043   }
    00044   virtual ~MotorNoiseWiring(){}
    00045
    00046   double getNoiseStrength(){ return motNoiseStrength; }
    00047   void setNoiseStrength(double _motNoiseStrength) {
    00048     if(_motNoiseStrength>=0) motNoiseStrength=_motNoiseStrength;
    00049   }
    00050
    00051
    00052   virtual bool initIntern(){
    00053     One2OneWiring::initIntern();
    00054     mMotNoise.set(rmotornumber,1);
    00055     addParameter("strength", &this->motNoiseStrength,0, 2, "strength of motor value noise (additive)");
    00056
    00057     addInspectableMatrix("n", &mMotNoise, false, "motor noise");
    00058     if(motNoiseGen)
    00059       motNoiseGen->init(rmotornumber, randGen);
    00060     return true;
    00061   }
    00062
    00063   virtual bool wireMotorsIntern(motor* rmotors, int rmotornumber,
    00064                                 const motor* cmotors, int cmotornumber){
    00065     One2OneWiring::wireMotorsIntern(rmotors, rmotornumber, cmotors, cmotornumber);
    00066     if(motNoiseGen){
    00067       double* nv = (double*) mMotNoise.unsafeGetData();
    00068       memset(nv, 0 , sizeof(double) * rmotornumber);
    00069       motNoiseGen->add(nv, motNoiseStrength);
    00070       for(int i=0; i<rmotornumber; i++){
    00071         rmotors[i]+=nv[i];
    00072       }
    00073     }
    00074     return true;
    00075   }
    00076
    00077
    00078 protected:
    00079   NoiseGenerator* motNoiseGen;
    00080   double motNoiseStrength;
    00081   matrix::Matrix mMotNoise;
    00082 };
    00083
    00084 #endif