discretecontrolleradapter.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
00003  *    martius@informatik.uni-leipzig.de                                    *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *    frankguettler@gmx.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  *  DESCRIPTION                                                            *
00025  *                                                                         *
00026  *   $Log: discretecontrolleradapter.h,v $
00027  *   Revision 1.3  2008/05/07 16:45:52  martius
00028  *   code cosmetics and documentation
00029  *
00030  *   Revision 1.2  2008/04/17 14:54:44  martius
00031  *   randomGen added, which is a random generator with long period and an
00032  *    internal state. Each Agent has an instance and passed it to the controller
00033  *    and the wiring. This is good for
00034  *   a) repeatability on agent basis,
00035  *   b) parallel execution as done in ode_robots
00036  *
00037  *   Revision 1.1  2007/03/22 08:10:09  robot3
00038  *   adapter (decorator) class for an arbitrary controller to discretesize sensor
00039  *   and/or motor values.
00040  *
00041  *
00042  *                                                                 *
00043  ***************************************************************************/
00044 #ifndef DISCRETECONTROLLERADAPTER_H
00045 #define DISCRETECONTROLLERADAPTER_H
00046 
00047 #include "abstractcontrolleradapter.h"
00048 
00049 /**
00050 Adapter class for robot controller.
00051 The controller gets a number of input sensor values each timestep and has to
00052 generate a number of output motor values.
00053 
00054 These sensor and motor values are discretesized with this adapter.
00055 
00056 Use this adapter between an agent and a controller to get discrete
00057 sensor and motor values.
00058 
00059 The sensor values are hand over to the controller from the agent,
00060 in the other direction the motor values of the controller are hand over
00061 to the agent.
00062 
00063 If no intervalCount is set, the count=1.
00064 If no intervalRange is set, the range is automatically adjusted.
00065 
00066 For more details about controllers,
00067 see AbstractController and all implementing classes.
00068 
00069         @see AbstractController
00070         @see AbstractControllerAdapter
00071         @author Frank Güttler <frankguettler@gmx.de>
00072 */
00073 class DiscreteControllerAdapter : public AbstractControllerAdapter
00074 {
00075 public:
00076     DiscreteControllerAdapter(AbstractController* controller);
00077 
00078     virtual ~DiscreteControllerAdapter();
00079 
00080     /**
00081     Sets the number of intervals, in which sensor AND motor values are mapped.
00082 
00083         @param intervalCount the number of intervals
00084    */
00085     virtual void setIntervalCount(int intervalCount);
00086 
00087     /**
00088     Sets the number of intervals, in which sensor values are mapped.
00089 
00090         @param sensorIntervalCount the number of intervals
00091    */
00092     virtual void setSensorIntervalCount(int sensorIntervalCount);
00093 
00094     /**
00095     Sets the number of intervals, in which motor values are mapped.
00096 
00097         @param motorIntervalCount the number of intervals
00098    */
00099     virtual void setMotorIntervalCount(int motorIntervalCount);
00100 
00101 
00102         /**
00103         Sets the interval range for the motors AND sensors, the minimum and maximum.
00104 
00105         The third parameter decides if the originally range should be completely
00106         mapped to the given interval range. If not, the values outside the given
00107         interval range are set to minRange respectively maxRange.
00108 
00109         Note: The adjustment of the range is disabled, if this method is called.
00110 
00111         @param minRange the minimum of the interval
00112         @param maxRange the maximum of the interval
00113         @param mapToInterval decides if all values are mapped to the given interval
00114         */
00115         virtual void setIntervalRange(double minRange, double maxRange, bool mapToInterval=true);
00116 
00117         /**
00118         Sets the interval range for the motors, the minimum and maximum.
00119 
00120         The third parameter decides if the originally range should be completely
00121         mapped to the given interval range. If not, the values outside the given
00122         interval range are set to minMotorRange respectively maxMotorRange.
00123 
00124         Note: The adjustment of the range is disabled, if this method is called.
00125 
00126         @param minMotorRange the minimum of the interval
00127         @param maxMotorRange the maximum of the interval
00128         @param mapToMotorInterval decides if all values are mapped to the given interval
00129         */
00130         virtual void setMotorIntervalRange(double minMotorRange, double maxMotorRange, bool mapToMotorInterval=true);
00131 
00132         /**
00133         Sets the interval range for the sensors, the minimum and maximum.
00134 
00135         The third parameter decides if the originally range should be completely
00136         mapped to the given interval range. If not, the values outside the given
00137         interval range are set to minSensorRange respectively maxSensorRange.
00138 
00139         Note: The adjustment of the range is disabled, if this method is called.
00140 
00141         @param minSensorRange the minimum of the interval
00142         @param maxSensorRange the maximum of the interval
00143         @param mapToSensorInterval decides if all values are mapped to the given interval
00144         */
00145         virtual void setSensorIntervalRange(double minSensorRange, double maxSensorRange, bool mapToSensorInterval=true);
00146 
00147 
00148 /***************************************************************************/
00149 /* BEGIN: forwarding methods of AbstractController                         */
00150 /***************************************************************************/
00151 
00152   /** performs one step (includes learning).
00153       Calculates motor commands from sensor inputs.
00154       @param sensors sensors inputs scaled to [-1,1]
00155       @param sensornumber length of the sensor array
00156       @param motors motors outputs. MUST have enough space for motor values!
00157       @param motornumber length of the provided motor array
00158   */
00159   virtual void step(const sensor* sensors, int sensornumber,
00160                     motor* motors, int motornumber);
00161   /** performs one step without learning.
00162       @see step
00163   */
00164   virtual void stepNoLearning(const sensor*, int number_sensors,
00165                               motor* , int number_motors);
00166 
00167         /**
00168          * init function
00169         */
00170         virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
00171 
00172 /***************************************************************************/
00173 /* END: forwarding methods of AbstractController                           */
00174 /***************************************************************************/
00175 
00176 /***************************************************************************/
00177 /* BEGIN: forwarding methods of Inspectable                                */
00178 /***************************************************************************/
00179 
00180         virtual std::list<Inspectable::iparamkey> getInternalParamNames() const;
00181 
00182         virtual std::list<Inspectable::iparamval> getInternalParams() const;
00183 
00184 /***************************************************************************/
00185 /* END: forwarding methods of Inspectable                                  */
00186 /***************************************************************************/
00187 
00188 
00189 protected:
00190         int sensorIntervalCount;
00191         int motorIntervalCount;
00192         bool automaticMotorRange;
00193         bool automaticSensorRange;
00194         bool mapToSensorInterval;
00195         bool mapToMotorInterval;
00196         double minMotorRange;
00197         double maxMotorRange;
00198         double minSensorRange;
00199         double maxSensorRange;
00200 
00201 private:
00202         double minMotorValue;
00203         double maxMotorValue;
00204         double minSensorValue;
00205         double maxSensorValue;
00206         sensor* discreteSensors;
00207         bool firstStep;
00208 
00209 private:
00210 
00211         /**
00212          * makes the discretisation of sensor values
00213          */
00214         virtual void doDiscretisizeSensorValues(const sensor* sensors, int sensornumber);
00215 
00216         /**
00217          * makes the discretisation of motor values
00218          */
00219         virtual void doDiscretisizeMotorValues(motor* motors, int motornumber);
00220 
00221         /**
00222         is used for automaticSensorRange, sets min and max Sensor range.
00223         */
00224         virtual void findMinAndMaxSensorRange(const sensor* sensors, int sensornumber);
00225 
00226         /**
00227         is used for automaticRange, sets min and max Motor range.
00228         */
00229         virtual void findMinAndMaxMotorRange(motor* motors, int motornumber);
00230 
00231         /**
00232         is used for mapToInterval, sets min and max Sensor values.
00233         */
00234         virtual void findMinAndMaxSensorValues(const sensor* sensors, int sensornumber);
00235 
00236         /**
00237         is used for mapToInterval, sets min and max Motor values.
00238         */
00239         virtual void findMinAndMaxMotorValues(motor* motors, int motornumber);
00240 
00241         /**
00242         is used for discretisizing values
00243         */
00244         virtual double discretisizeValue(double valueToDiscretisize, bool automaticRange, double minRange, double maxRange, double minValue, double maxValue, int intervalCount, bool mapToInterval);
00245 
00246         virtual double roundValue(double valueToRound);
00247 };
00248 
00249 #endif

Generated on Fri Oct 30 16:29:01 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7