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
derivativewiring.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 __DERIVATIVEWIRING_H
25 #define __DERIVATIVEWIRING_H
26 
27 #include "abstractwiring.h"
28 
29 /** Configuration object for DerivativeWiring.
30  If all boolean parametes are false, id is set to true (equivalent to One2OneWiring)
31 */
32 typedef struct __DerivativeWiringConf {
33  bool useId; //< include zeroth derivative
34  bool useFirstD; ///< include first derivative
35  bool useSecondD; ///< second include second derivative
36  double eps; ///< update rate for floating average (0 -> no sensor variation, 1 -> no smoothing)
37  double derivativeScale; ///< factor for the derivatives
38  unsigned int blindMotors; ///< number of motors that are blind (not given to robot)
40 
41 
42 /** Implements a wiring (between controller and robot)
43  which includes the first and second derivative
44  of the original robot sensor values
45 */
47 public:
48  /** constructor
49  @param conf for giving the wished configuration of DerivativeWiring
50  via \ref __DerivativeWiringConf "DerivativeWiringConf"
51  @param noise NoiseGenerator that is used for adding noise to sensor values
52  */
54  NoiseGenerator* noise, const std::string& name = "DerivativeWiring");
55 
56  /** destructor
57  */
58  virtual ~DerivativeWiring();
59 
60  /** Providing default configuration for DerivativeWiring with first derivative.
61  No smoothing and no scaling. ( as static method )
62  */
65  c.useId = true; // use id
66  c.useFirstD = false; // use first derivative
67  c.useSecondD = false; // do not use secound derivative
68  c.eps = 1; // no smoothing
69  c.derivativeScale=1; // no scaleing
70  c.blindMotors=0; // no blind motors used
71  return c;
72  };
73 
74  /** Providing default configuration for DerivativeWiring for only first derivative.
75  smoothing over 4 steps and scale of 5. Use smaller noise!
76  ( as static method )
77  */
80  c.useId = false; // do not use id
81  c.useFirstD = true; // use first derivative
82  c.useSecondD = false; // do not use secound derivative
83  c.eps = 0.5; // smoothing over 2 steps
84  c.derivativeScale=5; // scaling with 5
85  c.blindMotors=0; // no blind motors used
86  return c;
87  };
88 
89  virtual void reset();
90 
91 protected:
92 
93  virtual bool initIntern();
94 
95  virtual bool wireSensorsIntern(const sensor* rsensors, int rsensornumber,
96  sensor* csensors, int csensornumber,
97  double noise);
98 
99  virtual bool wireMotorsIntern(motor* rmotors, int rmotornumber,
100  const motor* cmotors, int cmotornumber);
101 
102 protected:
103  /** Calculate the first derivative of the sensorvalues given by the robot
104  * f'(x) = (f(x+1) - f(x-1)) / 2
105  * since we do not have f(x+1) we go one timestep in the past
106  */
107  void calcFirstDerivative();
108 
109  /** Calculate the secound derivative of the sensorvalues given by the robot
110  * f'(x) = f(x) - 2f(x-1) + f(x-2)
111  */
112  void calcSecondDerivative();
113 
114  /// used configuration
116  static const int buffersize=40;
117  int time;
118  /// number timesteps the sensor values are delayed for calculation of the derivative
119  // int delay;
120 
121 
122  /// current and old smoothed sensor values of robot
124 
125  /// current sensors (with noise)
126  // sensor* id;
127 
128  /// current first derivative
130 
131  /// current second derivative
133 
134  /// array that stored the values of the blind motors
136 
137 };
138 
139 #endif
virtual bool wireSensorsIntern(const sensor *rsensors, int rsensornumber, sensor *csensors, int csensornumber, double noise)
Realizes a wiring from robot sensors to controller sensors.
Definition: derivativewiring.cpp:85
int rmotornumber
number of motors at robot side
Definition: abstractwiring.h:182
int csensornumber
number of sensors at controller side
Definition: abstractwiring.h:187
void calcSecondDerivative()
Calculate the secound derivative of the sensorvalues given by the robot f'(x) = f(x) - 2f(x-1) + f(x-...
Definition: derivativewiring.cpp:191
unsigned int blindMotors
number of motors that are blind (not given to robot)
Definition: derivativewiring.h:38
double eps
update rate for floating average (0 -> no sensor variation, 1 -> no smoothing)
Definition: derivativewiring.h:36
virtual void reset()
reset internal state
Definition: derivativewiring.cpp:157
double sensor
Definition: types.h:29
iparamkey name
Definition: inspectable.h:251
struct __DerivativeWiringConf DerivativeWiringConf
Configuration object for DerivativeWiring.
bool useFirstD
include first derivative
Definition: derivativewiring.h:34
sensor * second
current second derivative
Definition: derivativewiring.h:132
Abstract wiring-object between controller and robot.
Definition: abstractwiring.h:39
void calcFirstDerivative()
Calculate the first derivative of the sensorvalues given by the robot f'(x) = (f(x+1) - f(x-1)) / 2 s...
Definition: derivativewiring.cpp:182
motor * blindMotors
array that stored the values of the blind motors
Definition: derivativewiring.h:135
virtual bool wireMotorsIntern(motor *rmotors, int rmotornumber, const motor *cmotors, int cmotornumber)
Realizes wiring from controller motor outputs to robot motors.
Definition: derivativewiring.cpp:169
int time
Definition: derivativewiring.h:117
Implements a wiring (between controller and robot) which includes the first and second derivative of ...
Definition: derivativewiring.h:46
sensor * sensorbuffer[buffersize]
number timesteps the sensor values are delayed for calculation of the derivative
Definition: derivativewiring.h:123
static DerivativeWiringConf getDefaultConf()
Providing default configuration for DerivativeWiring with first derivative.
Definition: derivativewiring.h:63
virtual ~DerivativeWiring()
destructor
Definition: derivativewiring.cpp:44
double motor
Definition: types.h:30
DerivativeWiring(const DerivativeWiringConf &conf, NoiseGenerator *noise, const std::string &name="DerivativeWiring")
constructor
Definition: derivativewiring.cpp:30
virtual bool initIntern()
to be overloaded by subclasses The rsensornumber and rmotornumber are already stored in the member va...
Definition: derivativewiring.cpp:55
int cmotornumber
number of motors at controller side
Definition: abstractwiring.h:192
double derivativeScale
factor for the derivatives
Definition: derivativewiring.h:37
int rsensornumber
number of sensors at robot side
Definition: abstractwiring.h:177
static const int buffersize
Definition: derivativewiring.h:116
bool useSecondD
second include second derivative
Definition: derivativewiring.h:35
bool useId
Definition: derivativewiring.h:33
DerivativeWiringConf conf
used configuration
Definition: derivativewiring.h:115
Configuration object for DerivativeWiring.
Definition: derivativewiring.h:32
static DerivativeWiringConf getDefaultConf1()
Providing default configuration for DerivativeWiring for only first derivative.
Definition: derivativewiring.h:78
int c
Definition: hexapod.cpp:56
sensor * first
current sensors (with noise)
Definition: derivativewiring.h:129
Interface and basic class for noise generator.
Definition: noisegenerator.h:37