sinecontroller.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: sinecontroller.h,v $
00023  *   Revision 1.16  2009/08/10 15:02:17  der
00024  *   Impuls->Impulse
00025  *
00026  *   Revision 1.15  2009/03/31 15:53:11  martius
00027  *   added amplitude
00028  *
00029  *   Revision 1.14  2009/02/02 15:37:44  martius
00030  *   added impulswidth
00031  *
00032  *   Revision 1.13  2009/02/02 15:23:50  martius
00033  *   added saw tooth and impuls oscillators
00034  *   sinerate is now period which is counted in control cycles
00035  *   changing the period does not change phase as it was before.
00036  *
00037  *   Revision 1.12  2008/04/17 14:54:45  martius
00038  *   randomGen added, which is a random generator with long period and an
00039  *    internal state. Each Agent has an instance and passed it to the controller
00040  *    and the wiring. This is good for
00041  *   a) repeatability on agent basis,
00042  *   b) parallel execution as done in ode_robots
00043  *
00044  *   Revision 1.11  2007/03/26 13:13:47  martius
00045  *   store and restore with params
00046  *
00047  *   Revision 1.10  2006/11/29 16:22:43  martius
00048  *   name is a variable of configurable and is used as such
00049  *
00050  *   Revision 1.9  2006/08/02 09:32:03  martius
00051  *   store and restore according to storable interface
00052  *
00053  *   Revision 1.8  2006/07/14 12:23:59  martius
00054  *   selforg becomes HEAD
00055  *
00056  *   Revision 1.6.6.5  2006/06/25 21:56:08  martius
00057  *   configureable has name and revision
00058  *
00059  *   Revision 1.6.6.4  2006/06/25 16:51:36  martius
00060  *   configureable has name and revision
00061  *   a robot is configureable by default
00062  *
00063  *   Revision 1.6.6.3  2006/03/30 12:35:13  martius
00064  *   documentation updated
00065  *
00066  *   Revision 1.6.6.2  2006/01/18 16:48:35  martius
00067  *   stored and restore
00068  *
00069  *   Revision 1.6.6.1  2005/11/14 15:38:17  martius
00070  *   moved to selforg
00071  *
00072  *   Revision 1.6  2005/11/14 12:46:19  martius
00073  *   added number of controlled motors
00074  *
00075  *   Revision 1.5  2005/11/09 13:56:34  martius
00076  *   const in instspectable functions
00077  *
00078  *   Revision 1.4  2005/10/06 17:06:57  martius
00079  *   switched to stl lists
00080  *
00081  *   Revision 1.3  2005/08/06 20:47:54  martius
00082  *   Commented
00083  *
00084  *   Revision 1.2  2005/07/07 10:25:47  martius
00085  *   added Phaseshift
00086  *
00087  *   Revision 1.1  2005/07/06 13:55:33  fhesse
00088  *   initial version, realising sine and cosine outputs
00089  *                                            *
00090  *                                                                         *
00091  ***************************************************************************/
00092 #ifndef __SINECONTROLLER_H
00093 #define __SINECONTROLLER_H
00094 
00095 
00096 #include <stdio.h>
00097 #include "abstractcontroller.h"
00098 
00099 /**
00100  * class for robot control with sine, sawtooth and impuls  
00101  * 
00102  * period is the length of the period in steps and 
00103  * phaseshift is the phase difference between channels given in Pi/2
00104  */
00105 class SineController : public AbstractController {
00106 public:
00107   enum function {Sine, SawTooth, Impulse};
00108 
00109   /**     
00110      @param controlmask bitmask to select channels to control (default all)
00111      @param function controller function to use
00112    */
00113   SineController(unsigned long int controlmask = (~0), function func = Sine );
00114 
00115   /** initialisation of the controller with the given sensor/ motornumber 
00116       Must be called before use.
00117   */
00118   virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
00119   
00120   /** @return Number of sensors the controller was initialised 
00121       with or 0 if not initialised */
00122   virtual int getSensorNumber() const {return number_sensors;}
00123 
00124 
00125   /** @return Number of motors the controller was initialised 
00126       with or 0 if not initialised */
00127   virtual int getMotorNumber() const {return number_motors;}
00128 
00129   /** performs one step ( the same as StepNoLearning).
00130       Calculates motor commands from sensor inputs.
00131       @param sensors sensors inputs scaled to [-1,1]
00132       @param sensornumber length of the sensor array
00133       @param motors motors outputs. MUST have enough space for motor values!
00134       @param motornumber length of the provided motor array
00135   */
00136   virtual void step(const sensor* sensors, int sensornumber, 
00137                     motor* motors, int motornumber);
00138   /** performs one step. 
00139       @see step
00140   */
00141   virtual void stepNoLearning(const sensor* , int number_sensors, 
00142                               motor* , int number_motors);
00143   
00144 
00145   /********* STORABLE INTERFACE ******/
00146   /// @see Storable
00147   virtual bool store(FILE* f) const { 
00148     Configurable::print(f,"");
00149     return true;
00150   }
00151 
00152   /// @see Storable
00153   virtual bool restore(FILE* f) { 
00154     Configurable::parse(f);    
00155     return true;
00156   }
00157 
00158   /// sine 
00159   static double sine(double x, double _unused);
00160   /// saw tooth shape oscillator
00161   static double sawtooth(double x, double _unused);
00162   /// impuls shaped oscillator (+-1 for impulsWidth part of the time)
00163   static double impuls(double x, double impulsWidth);
00164 
00165 protected:
00166 
00167   std::string name;
00168   int number_sensors;
00169   int number_motors;
00170   unsigned long int controlmask; // bitmask to select channels. (the others are set to 0)
00171 
00172   paramval period;
00173   paramval phaseShift;
00174   paramval impulsWidth;
00175   double phase; // phase of oscillator
00176   paramval amplitude;
00177 
00178   double (*osci) (double x, double param); // oscillator function
00179 };
00180 
00181 #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