Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
motornoisewiring.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __MOTORNOISEWIRING_H
25 #define __MOTORNOISEWIRING_H
26 
27 #include <selforg/one2onewiring.h>
28 #include <selforg/configurable.h>
29 
30 /**
31  * Implements a one to one wiring that adds noise to the motor signals
32  * (the sensors will get no noise)
33  */
35 public:
36  /** constructor
37  @param noise NoiseGenerator that is used for adding noise to motor values
38  */
39  MotorNoiseWiring(NoiseGenerator* noise, double noiseStrength)
40  : One2OneWiring(0, Controller), // no noise at sensors, show Controller x,y and noise
41  Configurable("MotorNoiseWiring", "$Id$"),
42  motNoiseGen(noise), motNoiseStrength(noiseStrength) {
43  }
44  virtual ~MotorNoiseWiring(){}
45 
46  double getNoiseStrength(){ return motNoiseStrength; }
47  void setNoiseStrength(double _motNoiseStrength) {
48  if(_motNoiseStrength>=0) motNoiseStrength=_motNoiseStrength;
49  }
50 
51 
52  virtual bool initIntern(){
55  addParameter("strength", &this->motNoiseStrength,0, 2, "strength of motor value noise (additive)");
56 
57  addInspectableMatrix("n", &mMotNoise, false, "motor noise");
58  if(motNoiseGen)
60  return true;
61  }
62 
63  virtual bool wireMotorsIntern(motor* rmotors, int rmotornumber,
64  const motor* cmotors, int cmotornumber){
65  One2OneWiring::wireMotorsIntern(rmotors, rmotornumber, cmotors, cmotornumber);
66  if(motNoiseGen){
67  double* nv = (double*) mMotNoise.unsafeGetData();
68  memset(nv, 0 , sizeof(double) * rmotornumber);
70  for(int i=0; i<rmotornumber; i++){
71  rmotors[i]+=nv[i];
72  }
73  }
74  return true;
75  }
76 
77 
78 protected:
82 };
83 
84 #endif
Matrix type.
Definition: matrix.h:65
Implements one to one wiring of robot sensors to inputs of the controller and controller outputs to r...
Definition: one2onewiring.h:32
virtual void add(double *value, double noiseStrength)
adds multidimensional noise to the value field.
Definition: noisegenerator.h:85
int rmotornumber
number of motors at robot side
Definition: abstractwiring.h:182
virtual bool initIntern()
initializes the number of sensors and motors on robot side, calculate number of sensors and motors on...
Definition: one2onewiring.cpp:42
double getNoiseStrength()
Definition: motornoisewiring.h:46
MotorNoiseWiring(NoiseGenerator *noise, double noiseStrength)
constructor
Definition: motornoisewiring.h:39
void setNoiseStrength(double _motNoiseStrength)
Definition: motornoisewiring.h:47
virtual bool wireMotorsIntern(motor *rmotors, int rmotornumber, const motor *cmotors, int cmotornumber)
Realizes one to one wiring from controller motor outputs to robot motors.
Definition: one2onewiring.cpp:82
Implements a one to one wiring that adds noise to the motor signals (the sensors will get no noise) ...
Definition: motornoisewiring.h:34
virtual void addInspectableMatrix(const iparamkey &key, const matrix::Matrix *m, bool only4x4AndDiag=true, const std::string &descr=std::string())
This is the new style for adding inspectable values.
Definition: inspectable.cpp:92
virtual bool wireMotorsIntern(motor *rmotors, int rmotornumber, const motor *cmotors, int cmotornumber)
Realizes one to one wiring from controller motor outputs to robot motors.
Definition: motornoisewiring.h:63
matrix::Matrix mMotNoise
Definition: motornoisewiring.h:81
virtual void init(unsigned int dimension, RandGen *randGen=0)
initialization with the the given dimension for multidimensional noise
Definition: noisegenerator.h:61
virtual void addParameter(const paramkey &key, paramval *val, paramval minBound, paramval maxBound, const paramdescr &descr=paramdescr())
This is the new style for adding configurable parameters.
Definition: configurable.h:172
Abstact class for configurable objects.
Definition: configurable.h:81
void set(I _m, I _n, const D *_data=0)
sets the size of the matrix and maybe the data if given (row-wise).
Definition: matrix.cpp:147
NoiseGenerator * motNoiseGen
Definition: motornoisewiring.h:79
double motor
Definition: abstractwiring.h:42
Definition: abstractwiring.h:44
int cmotornumber
number of motors at controller side
Definition: abstractwiring.h:192
RandGen * randGen
random generator used in NoiseGenerator (in case it is needed by subclasses)
Definition: abstractwiring.h:200
double motNoiseStrength
Definition: motornoisewiring.h:80
virtual bool initIntern()
initializes the number of sensors and motors on robot side, calculate number of sensors and motors on...
Definition: motornoisewiring.h:52
virtual ~MotorNoiseWiring()
Definition: motornoisewiring.h:44
const D * unsafeGetData() const
returns a pointer to the data. UNSAFE!!!
Definition: matrix.h:153
Interface and basic class for noise generator.
Definition: noisegenerator.h:37