00001 /*************************************************************************** 00002 * Copyright (C) 2005-2011 LpzRobots development team * 00003 * Georg Martius <georg dot martius at web dot de> * 00004 * Frank Guettler <guettler at informatik dot uni-leipzig dot de * 00005 * Frank Hesse <frank at nld dot ds dot mpg dot de> * 00006 * Ralf Der <ralfder at mis dot mpg dot de> * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 * * 00023 ***************************************************************************/ 00024 #ifndef DISCRETECONTROLLERADAPTER_H 00025 #define DISCRETECONTROLLERADAPTER_H 00026 00027 #include "abstractcontrolleradapter.h" 00028 00029 /** 00030 Adapter class for robot controller. 00031 The controller gets a number of input sensor values each timestep and has to 00032 generate a number of output motor values. 00033 00034 These sensor and motor values are discretesized with this adapter. 00035 00036 Use this adapter between an agent and a controller to get discrete 00037 sensor and motor values. 00038 00039 The sensor values are hand over to the controller from the agent, 00040 in the other direction the motor values of the controller are hand over 00041 to the agent. 00042 00043 If no intervalCount is set, the count=1. 00044 If no intervalRange is set, the range is automatically adjusted. 00045 00046 For more details about controllers, 00047 see AbstractController and all implementing classes. 00048 00049 @see AbstractController 00050 @see AbstractControllerAdapter 00051 @author Frank Güttler <frankguettler@gmx.de> 00052 */ 00053 class DiscreteControllerAdapter : public AbstractControllerAdapter 00054 { 00055 public: 00056 DiscreteControllerAdapter(AbstractController* controller, const std::string& name, const std::string& revision); 00057 00058 virtual ~DiscreteControllerAdapter(); 00059 00060 /** 00061 Sets the number of intervals, in which sensor AND motor values are mapped. 00062 00063 @param intervalCount the number of intervals 00064 */ 00065 virtual void setIntervalCount(int intervalCount); 00066 00067 /** 00068 Sets the number of intervals, in which sensor values are mapped. 00069 00070 @param sensorIntervalCount the number of intervals 00071 */ 00072 virtual void setSensorIntervalCount(int sensorIntervalCount); 00073 00074 /** 00075 Sets the number of intervals, in which motor values are mapped. 00076 00077 @param motorIntervalCount the number of intervals 00078 */ 00079 virtual void setMotorIntervalCount(int motorIntervalCount); 00080 00081 00082 /** 00083 Sets the interval range for the motors AND sensors, the minimum and maximum. 00084 00085 The third parameter decides if the originally range should be completely 00086 mapped to the given interval range. If not, the values outside the given 00087 interval range are set to minRange respectively maxRange. 00088 00089 Note: The adjustment of the range is disabled, if this method is called. 00090 00091 @param minRange the minimum of the interval 00092 @param maxRange the maximum of the interval 00093 @param mapToInterval decides if all values are mapped to the given interval 00094 */ 00095 virtual void setIntervalRange(double minRange, double maxRange, bool mapToInterval=true); 00096 00097 /** 00098 Sets the interval range for the motors, the minimum and maximum. 00099 00100 The third parameter decides if the originally range should be completely 00101 mapped to the given interval range. If not, the values outside the given 00102 interval range are set to minMotorRange respectively maxMotorRange. 00103 00104 Note: The adjustment of the range is disabled, if this method is called. 00105 00106 @param minMotorRange the minimum of the interval 00107 @param maxMotorRange the maximum of the interval 00108 @param mapToMotorInterval decides if all values are mapped to the given interval 00109 */ 00110 virtual void setMotorIntervalRange(double minMotorRange, double maxMotorRange, bool mapToMotorInterval=true); 00111 00112 /** 00113 Sets the interval range for the sensors, the minimum and maximum. 00114 00115 The third parameter decides if the originally range should be completely 00116 mapped to the given interval range. If not, the values outside the given 00117 interval range are set to minSensorRange respectively maxSensorRange. 00118 00119 Note: The adjustment of the range is disabled, if this method is called. 00120 00121 @param minSensorRange the minimum of the interval 00122 @param maxSensorRange the maximum of the interval 00123 @param mapToSensorInterval decides if all values are mapped to the given interval 00124 */ 00125 virtual void setSensorIntervalRange(double minSensorRange, double maxSensorRange, bool mapToSensorInterval=true); 00126 00127 00128 /***************************************************************************/ 00129 /* BEGIN: forwarding methods of AbstractController */ 00130 /***************************************************************************/ 00131 00132 /** performs one step (includes learning). 00133 Calculates motor commands from sensor inputs. 00134 @param sensors sensors inputs scaled to [-1,1] 00135 @param sensornumber length of the sensor array 00136 @param motors motors outputs. MUST have enough space for motor values! 00137 @param motornumber length of the provided motor array 00138 */ 00139 virtual void step(const sensor* sensors, int sensornumber, 00140 motor* motors, int motornumber); 00141 /** performs one step without learning. 00142 @see step 00143 */ 00144 virtual void stepNoLearning(const sensor*, int number_sensors, 00145 motor* , int number_motors); 00146 00147 /** 00148 * init function 00149 */ 00150 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0); 00151 00152 /***************************************************************************/ 00153 /* END: forwarding methods of AbstractController */ 00154 /***************************************************************************/ 00155 00156 /***************************************************************************/ 00157 /* BEGIN: forwarding methods of Inspectable */ 00158 /***************************************************************************/ 00159 00160 // nothing to overwrite 00161 00162 /***************************************************************************/ 00163 /* END: forwarding methods of Inspectable */ 00164 /***************************************************************************/ 00165 00166 00167 protected: 00168 int sensorIntervalCount; 00169 int motorIntervalCount; 00170 bool automaticMotorRange; 00171 bool automaticSensorRange; 00172 bool mapToSensorInterval; 00173 bool mapToMotorInterval; 00174 double minMotorRange; 00175 double maxMotorRange; 00176 double minSensorRange; 00177 double maxSensorRange; 00178 00179 private: 00180 double minMotorValue; 00181 double maxMotorValue; 00182 double minSensorValue; 00183 double maxSensorValue; 00184 sensor* discreteSensors; 00185 bool firstStep; 00186 00187 private: 00188 00189 /** 00190 * makes the discretisation of sensor values 00191 */ 00192 virtual void doDiscretisizeSensorValues(const sensor* sensors, int sensornumber); 00193 00194 /** 00195 * makes the discretisation of motor values 00196 */ 00197 virtual void doDiscretisizeMotorValues(motor* motors, int motornumber); 00198 00199 /** 00200 is used for automaticSensorRange, sets min and max Sensor range. 00201 */ 00202 virtual void findMinAndMaxSensorRange(const sensor* sensors, int sensornumber); 00203 00204 /** 00205 is used for automaticRange, sets min and max Motor range. 00206 */ 00207 virtual void findMinAndMaxMotorRange(motor* motors, int motornumber); 00208 00209 /** 00210 is used for mapToInterval, sets min and max Sensor values. 00211 */ 00212 virtual void findMinAndMaxSensorValues(const sensor* sensors, int sensornumber); 00213 00214 /** 00215 is used for mapToInterval, sets min and max Motor values. 00216 */ 00217 virtual void findMinAndMaxMotorValues(motor* motors, int motornumber); 00218 00219 /** 00220 is used for discretisizing values 00221 */ 00222 virtual double discretisizeValue(double valueToDiscretisize, bool automaticRange, double minRange, double maxRange, double minValue, double maxValue, int intervalCount, bool mapToInterval); 00223 00224 virtual double roundValue(double valueToRound); 00225 }; 00226 00227 #endif