Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sinecontroller.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __SINECONTROLLER_H
25 #define __SINECONTROLLER_H
26 
27 
28 #include <stdio.h>
29 #include "abstractcontroller.h"
30 
31 /**
32  * class for robot control with sine, sawtooth and impuls
33  *
34  * period is the length of the period in steps and
35  * phaseshift is the phase difference between channels given in Pi/2
36  */
38 public:
39  enum function {Sine, SawTooth, Impulse};
40 
41  /**
42  @param controlmask bitmask to select channels to control (default all)
43  @param function controller function to use
44  */
45  SineController(unsigned long int controlmask = (~0), function func = Sine);
46 
47  /** initialisation of the controller with the given sensor/ motornumber
48  Must be called before use.
49  */
50  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
51 
52  /** @return Number of sensors the controller was initialised
53  with or 0 if not initialised */
54  virtual int getSensorNumber() const {return number_sensors;}
55 
56 
57  /** @return Number of motors the controller was initialised
58  with or 0 if not initialised */
59  virtual int getMotorNumber() const {return number_motors;}
60 
61  /** performs one step ( the same as StepNoLearning).
62  Calculates motor commands from sensor inputs.
63  @param sensors sensors inputs scaled to [-1,1]
64  @param sensornumber length of the sensor array
65  @param motors motors outputs. MUST have enough space for motor values!
66  @param motornumber length of the provided motor array
67  */
68  virtual void step(const sensor* sensors, int sensornumber,
69  motor* motors, int motornumber);
70  /** performs one step.
71  @see step
72  */
73  virtual void stepNoLearning(const sensor* , int number_sensors,
74  motor* , int number_motors);
75 
76 
77  /********* STORABLE INTERFACE ******/
78  /// @see Storable
79  virtual bool store(FILE* f) const {
80  Configurable::print(f,"");
81  return true;
82  }
83 
84  /// @see Storable
85  virtual bool restore(FILE* f) {
87  return true;
88  }
89 
90  /// sine
91  static double sine(double x, double _unused);
92  /// saw tooth shape oscillator
93  static double sawtooth(double x, double _unused);
94  /// impuls shaped oscillator (+-1 for impulsWidth part of the time)
95  static double impuls(double x, double impulsWidth);
96 
97 protected:
98 
99  std::string name;
102  unsigned long int controlmask; // bitmask to select channels. (the others are set to 0)
104 
108  double phase; // phase of oscillator
110 
111  double (*osci) (double x, double param); // oscillator function
112 };
113 
115 public:
116  MultiSineController(unsigned long int controlmask = (~0), function func = Sine);
117  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
118  virtual void stepNoLearning(const sensor* , int number_sensors,
119  motor* , int number_motors);
120 protected:
121  double* periods;
122  double* phaseShifts;
123  double* amplitudes;
124  double* offsets;
125  long t;
126 };
127 
128 
129 
130 #endif
MultiSineController(unsigned long int controlmask=(~0), function func=Sine)
Definition: sinecontroller.cpp:118
double * periods
Definition: sinecontroller.h:121
virtual int getSensorNumber() const
Definition: sinecontroller.h:54
unsigned long int controlmask
Definition: sinecontroller.h:102
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step ( the same as StepNoLearning).
Definition: sinecontroller.cpp:65
virtual void stepNoLearning(const sensor *, int number_sensors, motor *, int number_motors)
performs one step.
Definition: sinecontroller.cpp:144
double sensor
Definition: types.h:29
static double sawtooth(double x, double _unused)
saw tooth shape oscillator
Definition: sinecontroller.cpp:91
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
double(* osci)(double x, double param)
Definition: sinecontroller.h:111
long t
Definition: sinecontroller.h:125
void print(FILE *f, const char *prefix, int columns=90, bool traverseChildren=true) const
prints the keys, values and descriptions to the file. Each line is prefixed
Definition: configurable.cpp:308
double * amplitudes
Definition: sinecontroller.h:123
double sensor
Definition: abstractcontroller.h:48
Definition: sinecontroller.h:39
double phase
Definition: sinecontroller.h:108
double * offsets
Definition: sinecontroller.h:124
double paramval
Definition: configurable.h:88
virtual void init(int sensornumber, int motornumber, RandGen *randGen=0)
initialisation of the controller with the given sensor/ motornumber Must be called before use...
Definition: sinecontroller.cpp:128
static double sine(double x, double _unused)
sine
Definition: sinecontroller.cpp:87
paramval amplitude
Definition: sinecontroller.h:109
int number_sensors
Definition: sinecontroller.h:100
std::string name
Definition: sinecontroller.h:99
bool individual
Definition: sinecontroller.h:103
paramval impulsWidth
Definition: sinecontroller.h:107
paramval period
Definition: sinecontroller.h:105
virtual void init(int sensornumber, int motornumber, RandGen *randGen=0)
initialisation of the controller with the given sensor/ motornumber Must be called before use...
Definition: sinecontroller.cpp:60
double motor
Definition: types.h:30
static double impuls(double x, double impulsWidth)
impuls shaped oscillator (+-1 for impulsWidth part of the time)
Definition: sinecontroller.cpp:106
virtual void stepNoLearning(const sensor *, int number_sensors, motor *, int number_motors)
performs one step.
Definition: sinecontroller.cpp:70
Definition: sinecontroller.h:39
Definition: sinecontroller.h:39
Definition: sinecontroller.h:114
virtual bool restore(FILE *f)
Definition: sinecontroller.h:85
bool parse(FILE *f, const char *prefix=0, bool traverseChildren=true)
parses the configuration from the given file
Definition: configurable.cpp:384
paramval phaseShift
Definition: sinecontroller.h:106
double motor
Definition: abstractcontroller.h:49
class for robot control with sine, sawtooth and impuls
Definition: sinecontroller.h:37
SineController(unsigned long int controlmask=(~0), function func=Sine)
Definition: sinecontroller.cpp:33
virtual int getMotorNumber() const
Definition: sinecontroller.h:59
virtual bool store(FILE *f) const
Definition: sinecontroller.h:79
double * phaseShifts
Definition: sinecontroller.h:122
int number_motors
Definition: sinecontroller.h:101