abstractwiring.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  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  *                                                                         *
00022  *   $Log: abstractwiring.h,v $
00023  *   Revision 1.10  2009/10/23 12:38:30  martius
00024  *   noise is stored in a matrix internally such that it can be inspected easily
00025  *
00026  *   Revision 1.9  2009/08/05 22:32:21  martius
00027  *   big change:
00028  *       abstractwiring is responsable for providing sensors and motors
00029  *        and noise to the inspectable interface.
00030  *       external interface: unchanged except plotMode in constructor
00031  *       internal interface: all subclasses have to overload
00032  *         initIntern, wireSensorsIntern, wireMotorsIntern
00033  *       All existing implementation are changed
00034  *
00035  *   Revision 1.8  2008/09/16 15:37:29  martius
00036  *   added randomgen
00037  *
00038  *   Revision 1.7  2008/04/28 11:14:54  guettler
00039  *   removed include "abstractrobot.h" (not needed)
00040  *
00041  *   Revision 1.6  2008/04/17 14:54:45  martius
00042  *   randomGen added, which is a random generator with long period and an
00043  *    internal state. Each Agent has an instance and passed it to the controller
00044  *    and the wiring. This is good for
00045  *   a) repeatability on agent basis,
00046  *   b) parallel execution as done in ode_robots
00047  *
00048  *   Revision 1.5  2007/11/07 13:40:24  martius
00049  *   sensors and motors also added as type here (not very nice anyway)
00050  *
00051  *   Revision 1.4  2006/12/21 11:44:17  martius
00052  *   commenting style for doxygen //< -> ///<
00053  *   FOREACH and FOREACHC are macros for collection iteration
00054  *
00055  *   Revision 1.3  2006/07/20 17:14:36  martius
00056  *   removed std namespace from matrix.h
00057  *   storable interface
00058  *   abstract model and invertablemodel as superclasses for networks
00059  *
00060  *   Revision 1.2  2006/07/14 12:24:02  martius
00061  *   selforg becomes HEAD
00062  *
00063  *   Revision 1.1.2.1  2005/11/16 11:24:27  martius
00064  *   moved to selforg
00065  *
00066  *   Revision 1.8  2005/11/09 13:55:44  martius
00067  *   *** empty log message ***
00068  *
00069  *   Revision 1.7  2005/10/24 09:52:36  fhesse
00070  *   comments in doxygen
00071  *
00072  *   Revision 1.6  2005/10/06 17:11:36  martius
00073  *   switched to stl lists
00074  *
00075  *   Revision 1.5  2005/08/03 20:34:58  martius
00076  *   use if Inspectable interface
00077  *
00078  *   Revision 1.4  2005/07/21 15:14:47  martius
00079  *   wireSensors and wireMotors get constant fields
00080  *
00081  *   Revision 1.3  2005/07/18 14:44:27  martius
00082  *   noise moved into wiring
00083  *
00084  *   Revision 1.2  2005/07/18 10:14:45  martius
00085  *   noise is added here
00086  *
00087  *   Revision 1.1  2005/07/14 15:57:53  fhesse
00088  *   now agent contains controller, robot and wiring, plotting ability included, therefore plotagent can be removed; ono2onewiring replaces one2oneagent
00089  *                                            *
00090  *                                                                         *
00091  ***************************************************************************/
00092 #ifndef __ABSTRACTWIRING_H
00093 #define __ABSTRACTWIRING_H
00094 
00095 //#include "abstractrobot.h"
00096 #include "matrix.h"
00097 #include "noisegenerator.h"
00098 #include "inspectable.h"
00099 #include "randomgenerator.h"
00100 
00101 
00102 /** Abstract wiring-object between controller and robot.
00103  *  Implements wiring of robot sensors to inputs of the controller and
00104  *  controller outputs to robot motors.
00105  */
00106 class AbstractWiring : public Inspectable {
00107 public:
00108   typedef double sensor;
00109   typedef double motor;
00110   
00111   enum PlotTypes {Robot, Controller, Noise};
00112 
00113 
00114   /** constructor
00115    *  @param noise NoiseGenerator that is used for adding noise to sensor values
00116    */
00117   AbstractWiring(NoiseGenerator* noise, int plotMode=Controller)
00118     : plotMode(plotMode) {
00119     rsensornumber = 0;
00120     rmotornumber  = 0;
00121     csensornumber = 0;
00122     cmotornumber  = 0;
00123     noiseGenerator = noise;
00124     noisevals=0;
00125     initialised = false;
00126   }
00127 
00128   /** destructor
00129    */
00130   virtual ~AbstractWiring(){
00131     if(noiseGenerator) delete noiseGenerator;
00132   }
00133 
00134   /** Initializes the  number of sensors and motors from robot
00135    *  (to be precise the internal parameters rsensornumber and rmotornumber!),
00136    *  calculates the number of sensors and motors on controller side.
00137    *  The internal version initIntern() is called from here and 
00138    *   be overloaded to calculate and provide the appropriate numbers
00139    *  controllersensornumber (csensornumber), controllermotornumber (cmotornumber),
00140    *  robotsensornumber (rsensornumber) and robotmotornumber (rmotornumber),
00141    *  @param randGen pointer to random generator, if not given then a new one is created
00142    *  @return returns false on error, otherwise true
00143    */
00144   virtual bool init(int robotsensornumber, int robotmotornumber, RandGen* randGen=0);
00145 
00146   /** Realizes wiring from robot sensors to controller sensors.
00147    *   The internal version wireSensorsIntern() is called from here and 
00148    *    must be overloaded in order to implement the appropriate mapping.
00149    *   @param rsensors pointer to array of sensorvalues from robot
00150    *   @param rsensornumber number of sensors from robot
00151    *   @param csensors pointer to array of sensorvalues for controller
00152    *   @param csensornumber number of sensors to controller
00153    *   @param noise size of the noise added to the sensors
00154    *  @return returns false on error, otherwise true
00155    */
00156   virtual bool wireSensors(const sensor* rsensors, int rsensornumber,
00157                            sensor* csensors, int csensornumber,
00158                            double noiseStrength);
00159 
00160   /** Realizes wiring from controller motor outputs to robot motors.
00161    *   The internal version wireMotorsIntern() is called from here and 
00162    *    must be overloaded in order to implement the appropriate mapping.
00163    *   @param rmotors pointer to array of motorvalues for robot
00164    *   @param rmotornumber number of robot motors
00165    *   @param cmotors pointer to array of motorvalues from controller
00166    *   @param cmotornumber number of motorvalues from controller
00167    *   @return returns false if error, else true
00168    */
00169   virtual bool wireMotors(motor* rmotors, int rmotornumber,
00170                           const motor* cmotors, int cmotornumber);
00171 
00172   /** Returns the number of sensors on robot side.
00173    */
00174   virtual int getRobotSensornumber(){return rsensornumber;}
00175 
00176   /** Returns the number of motors on robot side.
00177    */
00178   virtual int getRobotMotornumber() {return rmotornumber;}
00179 
00180   /** Returns the number of sensors on controller side.
00181    */
00182   virtual int getControllerSensornumber(){return csensornumber;}
00183 
00184   /** Returns the number of motors on controller side.
00185    */
00186   virtual int getControllerMotornumber() {return cmotornumber;}
00187 
00188 
00189 protected:
00190   /** to be overloaded by subclasses
00191       @see init() 
00192    */
00193   virtual bool initIntern(int robotsensornumber, int robotmotornumber, RandGen* randGen=0) = 0;
00194 
00195   /** to be overloaded by subclasses
00196       @see wireSensors() 
00197    */
00198   virtual bool wireSensorsIntern(const sensor* rsensors, int rsensornumber,
00199                                  sensor* csensors, int csensornumber,
00200                                  double noiseStrength) = 0;
00201 
00202   /** to be overloaded by subclasses
00203       @see wireMotors() 
00204    */
00205   virtual bool wireMotorsIntern(motor* rmotors, int rmotornumber,
00206                                 const motor* cmotors, int cmotornumber)  = 0;
00207 
00208 
00209 
00210   /// using plotTypes this variables defines what is plotted
00211   int plotMode; 
00212   /// for storing the noise values
00213   matrix::Matrix mNoise;
00214   sensor* noisevals; // pointer to the noisevalues stored in the matrix
00215 
00216   /// number of sensors at robot side
00217   int rsensornumber;
00218   /// copy of the last robot sensors
00219   matrix::Matrix mRsensors; 
00220 
00221   /// number of motors at robot side
00222   int rmotornumber;
00223   /// copy of the last robot motors
00224   matrix::Matrix mRmotors;
00225 
00226   /// number of sensors at controller side
00227   int csensornumber;
00228   /// copy of the last controller sensors
00229   matrix::Matrix mCsensors;
00230 
00231   /// number of motors at controller side
00232   int cmotornumber;
00233   /// copy of the last controller motors
00234   matrix::Matrix mCmotors;
00235 
00236   /// noise generator
00237   NoiseGenerator* noiseGenerator;
00238 
00239   bool initialised;
00240 };
00241 
00242 #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