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
discretecontrolleradapter.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 DISCRETECONTROLLERADAPTER_H
25 #define DISCRETECONTROLLERADAPTER_H
26 
28 
29 /**
30 Adapter class for robot controller.
31 The controller gets a number of input sensor values each timestep and has to
32 generate a number of output motor values.
33 
34 These sensor and motor values are discretesized with this adapter.
35 
36 Use this adapter between an agent and a controller to get discrete
37 sensor and motor values.
38 
39 The sensor values are hand over to the controller from the agent,
40 in the other direction the motor values of the controller are hand over
41 to the agent.
42 
43 If no intervalCount is set, the count=1.
44 If no intervalRange is set, the range is automatically adjusted.
45 
46 For more details about controllers,
47 see AbstractController and all implementing classes.
48 
49  @see AbstractController
50  @see AbstractControllerAdapter
51  @author Frank Güttler <frankguettler@gmx.de>
52 */
54 {
55 public:
56  DiscreteControllerAdapter(AbstractController* controller, const std::string& name, const std::string& revision);
57 
59 
60  /**
61  Sets the number of intervals, in which sensor AND motor values are mapped.
62 
63  @param intervalCount the number of intervals
64  */
65  virtual void setIntervalCount(int intervalCount);
66 
67  /**
68  Sets the number of intervals, in which sensor values are mapped.
69 
70  @param sensorIntervalCount the number of intervals
71  */
73 
74  /**
75  Sets the number of intervals, in which motor values are mapped.
76 
77  @param motorIntervalCount the number of intervals
78  */
79  virtual void setMotorIntervalCount(int motorIntervalCount);
80 
81 
82  /**
83  Sets the interval range for the motors AND sensors, the minimum and maximum.
84 
85  The third parameter decides if the originally range should be completely
86  mapped to the given interval range. If not, the values outside the given
87  interval range are set to minRange respectively maxRange.
88 
89  Note: The adjustment of the range is disabled, if this method is called.
90 
91  @param minRange the minimum of the interval
92  @param maxRange the maximum of the interval
93  @param mapToInterval decides if all values are mapped to the given interval
94  */
95  virtual void setIntervalRange(double minRange, double maxRange, bool mapToInterval=true);
96 
97  /**
98  Sets the interval range for the motors, the minimum and maximum.
99 
100  The third parameter decides if the originally range should be completely
101  mapped to the given interval range. If not, the values outside the given
102  interval range are set to minMotorRange respectively maxMotorRange.
103 
104  Note: The adjustment of the range is disabled, if this method is called.
105 
106  @param minMotorRange the minimum of the interval
107  @param maxMotorRange the maximum of the interval
108  @param mapToMotorInterval decides if all values are mapped to the given interval
109  */
110  virtual void setMotorIntervalRange(double minMotorRange, double maxMotorRange, bool mapToMotorInterval=true);
111 
112  /**
113  Sets the interval range for the sensors, the minimum and maximum.
114 
115  The third parameter decides if the originally range should be completely
116  mapped to the given interval range. If not, the values outside the given
117  interval range are set to minSensorRange respectively maxSensorRange.
118 
119  Note: The adjustment of the range is disabled, if this method is called.
120 
121  @param minSensorRange the minimum of the interval
122  @param maxSensorRange the maximum of the interval
123  @param mapToSensorInterval decides if all values are mapped to the given interval
124  */
125  virtual void setSensorIntervalRange(double minSensorRange, double maxSensorRange, bool mapToSensorInterval=true);
126 
127 
128 /***************************************************************************/
129 /* BEGIN: forwarding methods of AbstractController */
130 /***************************************************************************/
131 
132  /** performs one step (includes learning).
133  Calculates motor commands from sensor inputs.
134  @param sensors sensors inputs scaled to [-1,1]
135  @param sensornumber length of the sensor array
136  @param motors motors outputs. MUST have enough space for motor values!
137  @param motornumber length of the provided motor array
138  */
139  virtual void step(const sensor* sensors, int sensornumber,
140  motor* motors, int motornumber);
141  /** performs one step without learning.
142  @see step
143  */
144  virtual void stepNoLearning(const sensor*, int number_sensors,
145  motor* , int number_motors);
146 
147  /**
148  * init function
149  */
150  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
151 
152 /***************************************************************************/
153 /* END: forwarding methods of AbstractController */
154 /***************************************************************************/
155 
156 /***************************************************************************/
157 /* BEGIN: forwarding methods of Inspectable */
158 /***************************************************************************/
159 
160 // nothing to overwrite
161 
162 /***************************************************************************/
163 /* END: forwarding methods of Inspectable */
164 /***************************************************************************/
165 
166 
167 protected:
178 
179 private:
180  double minMotorValue;
181  double maxMotorValue;
182  double minSensorValue;
183  double maxSensorValue;
184  sensor* discreteSensors;
185  bool firstStep;
186 
187 private:
188 
189  /**
190  * makes the discretisation of sensor values
191  */
192  virtual void doDiscretisizeSensorValues(const sensor* sensors, int sensornumber);
193 
194  /**
195  * makes the discretisation of motor values
196  */
197  virtual void doDiscretisizeMotorValues(motor* motors, int motornumber);
198 
199  /**
200  is used for automaticSensorRange, sets min and max Sensor range.
201  */
202  virtual void findMinAndMaxSensorRange(const sensor* sensors, int sensornumber);
203 
204  /**
205  is used for automaticRange, sets min and max Motor range.
206  */
207  virtual void findMinAndMaxMotorRange(motor* motors, int motornumber);
208 
209  /**
210  is used for mapToInterval, sets min and max Sensor values.
211  */
212  virtual void findMinAndMaxSensorValues(const sensor* sensors, int sensornumber);
213 
214  /**
215  is used for mapToInterval, sets min and max Motor values.
216  */
217  virtual void findMinAndMaxMotorValues(motor* motors, int motornumber);
218 
219  /**
220  is used for discretisizing values
221  */
222  virtual double discretisizeValue(double valueToDiscretisize, bool automaticRange, double minRange, double maxRange, double minValue, double maxValue, int intervalCount, bool mapToInterval);
223 
224  virtual double roundValue(double valueToRound);
225 };
226 
227 #endif
double minSensorRange
Definition: discretecontrolleradapter.h:176
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
bool automaticMotorRange
Definition: discretecontrolleradapter.h:170
DiscreteControllerAdapter(AbstractController *controller, const std::string &name, const std::string &revision)
Definition: discretecontrolleradapter.cpp:49
Abstract adapter class (interface) for robot controller.
Definition: abstractcontrolleradapter.h:52
double minMotorRange
Definition: discretecontrolleradapter.h:174
int motorIntervalCount
Definition: discretecontrolleradapter.h:169
double sensor
Definition: types.h:29
iparamkey name
Definition: inspectable.h:251
virtual void setSensorIntervalRange(double minSensorRange, double maxSensorRange, bool mapToSensorInterval=true)
Sets the interval range for the sensors, the minimum and maximum.
Definition: discretecontrolleradapter.cpp:103
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
bool mapToSensorInterval
Definition: discretecontrolleradapter.h:172
virtual void setMotorIntervalCount(int motorIntervalCount)
Sets the number of intervals, in which motor values are mapped.
Definition: discretecontrolleradapter.cpp:87
AbstractController * controller
Definition: abstractcontrolleradapter.h:158
virtual void setIntervalCount(int intervalCount)
Sets the number of intervals, in which sensor AND motor values are mapped.
Definition: discretecontrolleradapter.cpp:76
bool automaticSensorRange
Definition: discretecontrolleradapter.h:171
int sensorIntervalCount
Definition: discretecontrolleradapter.h:168
Adapter class for robot controller.
Definition: discretecontrolleradapter.h:53
virtual ~DiscreteControllerAdapter()
Definition: discretecontrolleradapter.cpp:73
double maxSensorRange
Definition: discretecontrolleradapter.h:177
virtual void setSensorIntervalCount(int sensorIntervalCount)
Sets the number of intervals, in which sensor values are mapped.
Definition: discretecontrolleradapter.cpp:82
virtual void stepNoLearning(const sensor *, int number_sensors, motor *, int number_motors)
performs one step without learning.
Definition: discretecontrolleradapter.cpp:121
bool mapToMotorInterval
Definition: discretecontrolleradapter.h:173
virtual void init(int sensornumber, int motornumber, RandGen *randGen=0)
init function
Definition: discretecontrolleradapter.cpp:127
double maxMotorRange
Definition: discretecontrolleradapter.h:175
double motor
Definition: abstractcontroller.h:49
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step (includes learning).
Definition: discretecontrolleradapter.cpp:115
virtual void setIntervalRange(double minRange, double maxRange, bool mapToInterval=true)
Sets the interval range for the motors AND sensors, the minimum and maximum.
Definition: discretecontrolleradapter.cpp:91
virtual void setMotorIntervalRange(double minMotorRange, double maxMotorRange, bool mapToMotorInterval=true)
Sets the interval range for the motors, the minimum and maximum.
Definition: discretecontrolleradapter.cpp:96