Robot Simulator of the Robotics Group for Self-Organization of Control: motorbabbler.h Source File

# motorbabbler.h

Go to the documentation of this file.

    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 __MOTORBABBLER_H
    00025 #define __MOTORBABBLER_H
    00026
    00027 #include <stdio.h>
    00028 #include "abstractcontroller.h"
    00029 #include "matrix.h"
    00030
    00031 /**
    00032  * class for robot control that does motor babbling, e.g. sine waves
    00033  * with different frequencies and phaseshift
    00034  */
    00035 class MotorBabbler : public AbstractController {
    00036 public:
    00037   enum function {Sine, SawTooth};
    00038
    00039   /**
    00040      @param controlmask bitmask to select channels to control (default all)
    00041      @param function controller function to use
    00042    */
    00043   MotorBabbler(function func = Sine );
    00044
    00045   virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
    00046   virtual int getSensorNumber() const {return number_sensors;}
    00047   virtual int getMotorNumber() const {return number_motors;}
    00048   virtual void step(const sensor* sensors, int sensornumber,
    00049                     motor* motors, int motornumber){
    00050     stepNoLearning(sensors, sensornumber, motors, motornumber);
    00051   }
    00052   virtual void stepNoLearning(const sensor* , int number_sensors,
    00053                               motor* , int number_motors);
    00054
    00055   // samples a new set of frequencies
    00056   void sampleFrequencies();
    00057
    00058   /********* STORABLE INTERFACE ******/
    00059   /// @see Storable
    00060   virtual bool store(FILE* f) const {
    00061     Configurable::print(f,"");
    00062     return true;
    00063   }
    00064
    00065   /// @see Storable
    00066   virtual bool restore(FILE* f) {
    00067     Configurable::parse(f);
    00068     return true;
    00069   }
    00070
    00071   /// sine
    00072   static double sine(double x);
    00073   /// saw tooth shape oscillator
    00074   static double sawtooth(double x);
    00075
    00076 protected:
    00077   int number_sensors;
    00078   int number_motors;
    00079
    00080   paramval speed;
    00081   paramval amplitude;
    00082   paramint resampling;
    00083   matrix::Matrix phases;
    00084   matrix::Matrix frequencies;
    00085
    00086   RandGen* randGen;
    00087
    00088   double (*osci) (double x); // oscillator function
    00089   int t;
    00090 };
    00091
    00092 #endif