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
abstractwiring.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 __ABSTRACTWIRING_H
25 #define __ABSTRACTWIRING_H
26 
27 //#include "abstractrobot.h"
28 #include "matrix.h"
29 #include "noisegenerator.h"
30 #include "inspectable.h"
31 #include "randomgenerator.h"
32 #include "sensormotorinfo.h"
33 
34 
35 /** Abstract wiring-object between controller and robot.
36  * Implements wiring of robot sensors to inputs of the controller and
37  * controller outputs to robot motors.
38  */
39 class AbstractWiring : public Inspectable {
40 public:
41  typedef double sensor;
42  typedef double motor;
43 
44  enum PlotTypes {Nothing=0, Robot=1, Controller=4, Noise=8};
45 
46 
47  /** constructor
48  * @param noise NoiseGenerator that is used for adding noise to sensor values
49  */
50  AbstractWiring(NoiseGenerator* noise, int plotMode=Controller, const std::string& name = "AbstractWiring")
52  rsensornumber = 0;
53  rmotornumber = 0;
54  csensornumber = 0;
55  cmotornumber = 0;
56  noiseGenerator = noise;
57  noisevals=0;
58  initialised = false;
59  }
60 
61  /** destructor
62  */
63  virtual ~AbstractWiring(){
64  if(noiseGenerator) delete noiseGenerator;
65  }
66 
67  /** Initializes the number of sensors and motors from robot
68  * (to be precise the internal parameters rsensornumber and rmotornumber!),
69  * calculates the number of sensors and motors on controller side.
70  * The internal version initIntern() is called from here and
71  * be overloaded to calculate and provide the appropriate numbers
72  * controllersensornumber (csensornumber), controllermotornumber (cmotornumber)
73  * The number of noise channels (noisenumber) can also be changed.
74  * @param randGen pointer to random generator, if not given then a new one is created
75  * @return returns false on error, otherwise true
76  */
77  virtual bool init(int robotsensornumber, int robotmotornumber, RandGen* randGen=0);
78 
79  /** Realizes wiring from robot sensors to controller sensors.
80  * The internal version wireSensorsIntern() is called from here and
81  * must be overloaded in order to implement the appropriate mapping.
82  * Noise values of the right size are then accessible via the noisevals array.
83  * @param rsensors pointer to array of sensorvalues from robot
84  * @param rsensornumber number of sensors from robot
85  * @param csensors pointer to array of sensorvalues for controller
86  * @param csensornumber number of sensors to controller
87  * @param noiseStrength size of the noise added to the sensors
88  * @return returns false on error, otherwise true
89  */
90  virtual bool wireSensors(const sensor* rsensors, int rsensornumber,
91  sensor* csensors, int csensornumber,
92  double noiseStrength);
93 
94  /** Realizes wiring from controller motor outputs to robot motors.
95  * The internal version wireMotorsIntern() is called from here and
96  * must be overloaded in order to implement the appropriate mapping.
97  * @param rmotors pointer to array of motorvalues for robot
98  * @param rmotornumber number of robot motors
99  * @param cmotors pointer to array of motorvalues from controller
100  * @param cmotornumber number of motorvalues from controller
101  * @return returns false if error, else true
102  */
103  virtual bool wireMotors(motor* rmotors, int rmotornumber,
104  const motor* cmotors, int cmotornumber);
105 
106  /** Returns the number of sensors on robot side.
107  */
108  virtual int getRobotSensornumber(){return rsensornumber;}
109 
110  /** Returns the number of motors on robot side.
111  */
112  virtual int getRobotMotornumber() {return rmotornumber;}
113 
114  /** Returns the number of sensors on controller side.
115  */
117 
118  /** Returns the number of motors on controller side.
119  */
120  virtual int getControllerMotornumber() {return cmotornumber;}
121 
122  /** routes the infos of the motors from robot to controller */
123  virtual std::list<SensorMotorInfo> wireSensorInfos(const std::list<SensorMotorInfo>& robotSensorInfos);
124 
125  /** routes the infos of the motors from robot to controller */
126  virtual std::list<SensorMotorInfo> wireMotorInfos(const std::list<SensorMotorInfo>& robotMotorInfos);
127 
128  /// reset internal state
129  virtual void reset() {}
130 
131  /// used by WiredController to pass infos to inspectable
132  void addSensorMotorInfosToInspectable(const std::list<SensorMotorInfo>& robotSensorInfos,
133  const std::list<SensorMotorInfo>& robotMotorInfos,
134  const std::list<SensorMotorInfo>& controllerSensorInfos,
135  const std::list<SensorMotorInfo>& controllerMotorInfos);
136 
137 
138 protected:
139  // static std::list<std::string> infosToNames(std::list<SensorMotorInfo> infos) {
140  // std::list<std::string> names;
141  // std::transform(infos.begin(), infos.end(), names.begin(), [](const SensorMotorInfo& i){return i.name;});
142  // return names;
143  // }
144 
145  /** to be overloaded by subclasses
146  The rsensornumber and rmotornumber are already stored
147  in the member variables. The random values are to be accessed
148  via the noiseGenerator.
149  @see init()
150  */
151  virtual bool initIntern() = 0;
152 
153  /** to be overloaded by subclasses
154  @see wireSensors()
155  */
156  virtual bool wireSensorsIntern(const sensor* rsensors, int rsensornumber,
157  sensor* csensors, int csensornumber,
158  double noiseStrength) = 0;
159 
160  /** to be overloaded by subclasses
161  @see wireMotors()
162  */
163  virtual bool wireMotorsIntern(motor* rmotors, int rmotornumber,
164  const motor* cmotors, int cmotornumber) = 0;
165 
166 
167  /// using plotTypes this variables defines what is plotted
168  int plotMode;
169 
170  /// for storing the noise values
172  sensor* noisevals; // pointer to the noisevalues stored in the matrix
173  // size of the noise vector
175 
176  /// number of sensors at robot side
178  /// copy of the last robot sensors
180 
181  /// number of motors at robot side
183  /// copy of the last robot motors
185 
186  /// number of sensors at controller side
188  /// copy of the last controller sensors
190 
191  /// number of motors at controller side
193  /// copy of the last controller motors
195 
196  /// noise generator
198 
199  /// random generator used in NoiseGenerator (in case it is needed by subclasses)
201 
203 };
204 
205 #endif
Matrix type.
Definition: matrix.h:65
virtual int getRobotSensornumber()
Returns the number of sensors on robot side.
Definition: abstractwiring.h:108
virtual void reset()
reset internal state
Definition: abstractwiring.h:129
int rmotornumber
number of motors at robot side
Definition: abstractwiring.h:182
int csensornumber
number of sensors at controller side
Definition: abstractwiring.h:187
virtual bool wireMotorsIntern(motor *rmotors, int rmotornumber, const motor *cmotors, int cmotornumber)=0
to be overloaded by subclasses
virtual int getControllerMotornumber()
Returns the number of motors on controller side.
Definition: abstractwiring.h:120
int plotMode
using plotTypes this variables defines what is plotted
Definition: abstractwiring.h:168
virtual bool wireSensors(const sensor *rsensors, int rsensornumber, sensor *csensors, int csensornumber, double noiseStrength)
Realizes wiring from robot sensors to controller sensors.
Definition: abstractwiring.cpp:88
matrix::Matrix mCsensors
copy of the last controller sensors
Definition: abstractwiring.h:189
double sensor
Definition: types.h:29
AbstractWiring(NoiseGenerator *noise, int plotMode=Controller, const std::string &name="AbstractWiring")
constructor
Definition: abstractwiring.h:50
iparamkey name
Definition: inspectable.h:251
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
virtual int getControllerSensornumber()
Returns the number of sensors on controller side.
Definition: abstractwiring.h:116
matrix::Matrix mRmotors
copy of the last robot motors
Definition: abstractwiring.h:184
Abstract wiring-object between controller and robot.
Definition: abstractwiring.h:39
virtual bool initIntern()=0
to be overloaded by subclasses The rsensornumber and rmotornumber are already stored in the member va...
void addSensorMotorInfosToInspectable(const std::list< SensorMotorInfo > &robotSensorInfos, const std::list< SensorMotorInfo > &robotMotorInfos, const std::list< SensorMotorInfo > &controllerSensorInfos, const std::list< SensorMotorInfo > &controllerMotorInfos)
used by WiredController to pass infos to inspectable
Definition: abstractwiring.cpp:73
matrix::Matrix mCmotors
copy of the last controller motors
Definition: abstractwiring.h:194
int noisenumber
Definition: abstractwiring.h:174
virtual bool init(int robotsensornumber, int robotmotornumber, RandGen *randGen=0)
Initializes the number of sensors and motors from robot (to be precise the internal parameters rsenso...
Definition: abstractwiring.cpp:30
matrix::Matrix mRsensors
copy of the last robot sensors
Definition: abstractwiring.h:179
virtual int getRobotMotornumber()
Returns the number of motors on robot side.
Definition: abstractwiring.h:112
virtual std::list< SensorMotorInfo > wireSensorInfos(const std::list< SensorMotorInfo > &robotSensorInfos)
routes the infos of the motors from robot to controller
Definition: abstractwiring.cpp:111
Interface for inspectable objects.
Definition: inspectable.h:48
Definition: abstractwiring.h:44
sensor * noisevals
Definition: abstractwiring.h:172
Definition: abstractwiring.h:44
double motor
Definition: types.h:30
double motor
Definition: abstractwiring.h:42
virtual bool wireMotors(motor *rmotors, int rmotornumber, const motor *cmotors, int cmotornumber)
Realizes wiring from controller motor outputs to robot motors.
Definition: abstractwiring.cpp:102
Definition: abstractwiring.h:44
int cmotornumber
number of motors at controller side
Definition: abstractwiring.h:192
Definition: abstractwiring.h:44
PlotTypes
Definition: abstractwiring.h:44
int rsensornumber
number of sensors at robot side
Definition: abstractwiring.h:177
virtual ~AbstractWiring()
destructor
Definition: abstractwiring.h:63
double sensor
Definition: abstractwiring.h:41
RandGen * randGen
random generator used in NoiseGenerator (in case it is needed by subclasses)
Definition: abstractwiring.h:200
virtual bool wireSensorsIntern(const sensor *rsensors, int rsensornumber, sensor *csensors, int csensornumber, double noiseStrength)=0
to be overloaded by subclasses
bool initialised
Definition: abstractwiring.h:202
matrix::Matrix mNoise
for storing the noise values
Definition: abstractwiring.h:171
virtual std::list< SensorMotorInfo > wireMotorInfos(const std::list< SensorMotorInfo > &robotMotorInfos)
routes the infos of the motors from robot to controller
Definition: abstractwiring.cpp:115
NoiseGenerator * noiseGenerator
noise generator
Definition: abstractwiring.h:197
Interface and basic class for noise generator.
Definition: noisegenerator.h:37