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

# sinecontroller.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 __SINECONTROLLER_H
    00025 #define __SINECONTROLLER_H
    00026
    00027
    00028 #include <stdio.h>
    00029 #include "abstractcontroller.h"
    00030
    00031 /**
    00032  * class for robot control with sine, sawtooth and impuls
    00033  *
    00034  * period is the length of the period in steps and
    00035  * phaseshift is the phase difference between channels given in Pi/2
    00036  */
    00037 class SineController : public AbstractController {
    00038 public:
    00039   enum function {Sine, SawTooth, Impulse};
    00040
    00041   /**
    00042      @param controlmask bitmask to select channels to control (default all)
    00043      @param function controller function to use
    00044    */
    00045   SineController(unsigned long int controlmask = (~0), function func = Sine );
    00046
    00047   /** initialisation of the controller with the given sensor/ motornumber
    00048       Must be called before use.
    00049   */
    00050   virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
    00051
    00052   /** @return Number of sensors the controller was initialised
    00053       with or 0 if not initialised */
    00054   virtual int getSensorNumber() const {return number_sensors;}
    00055
    00056
    00057   /** @return Number of motors the controller was initialised
    00058       with or 0 if not initialised */
    00059   virtual int getMotorNumber() const {return number_motors;}
    00060
    00061   /** performs one step ( the same as StepNoLearning).
    00062       Calculates motor commands from sensor inputs.
    00063       @param sensors sensors inputs scaled to [-1,1]
    00064       @param sensornumber length of the sensor array
    00065       @param motors motors outputs. MUST have enough space for motor values!
    00066       @param motornumber length of the provided motor array
    00067   */
    00068   virtual void step(const sensor* sensors, int sensornumber,
    00069                     motor* motors, int motornumber);
    00070   /** performs one step.
    00071       @see step
    00072   */
    00073   virtual void stepNoLearning(const sensor* , int number_sensors,
    00074                               motor* , int number_motors);
    00075
    00076
    00077   /********* STORABLE INTERFACE ******/
    00078   /// @see Storable
    00079   virtual bool store(FILE* f) const {
    00080     Configurable::print(f,"");
    00081     return true;
    00082   }
    00083
    00084   /// @see Storable
    00085   virtual bool restore(FILE* f) {
    00086     Configurable::parse(f);
    00087     return true;
    00088   }
    00089
    00090   /// sine
    00091   static double sine(double x, double _unused);
    00092   /// saw tooth shape oscillator
    00093   static double sawtooth(double x, double _unused);
    00094   /// impuls shaped oscillator (+-1 for impulsWidth part of the time)
    00095   static double impuls(double x, double impulsWidth);
    00096
    00097 protected:
    00098
    00099   std::string name;
    00100   int number_sensors;
    00101   int number_motors;
    00102   unsigned long int controlmask; // bitmask to select channels. (the others are set to 0)
    00103
    00104   paramval period;
    00105   paramval phaseShift;
    00106   paramval impulsWidth;
    00107   double phase; // phase of oscillator
    00108   paramval amplitude;
    00109
    00110   double (*osci) (double x, double param); // oscillator function
    00111 };
    00112
    00113 #endif