motornoisewiring.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __MOTORNOISEWIRING_H
00025 #define __MOTORNOISEWIRING_H
00026
00027 #include <selforg/one2onewiring.h>
00028 #include <selforg/configurable.h>
00029
00030
00031
00032
00033
00034 class MotorNoiseWiring : public One2OneWiring, public Configurable {
00035 public:
00036
00037
00038
00039 MotorNoiseWiring(NoiseGenerator* noise, double noiseStrength)
00040 : One2OneWiring(0, Controller),
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