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
braitenberg.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 __BRAITENBERG_H
25 #define __BRAITENBERG_H
26 
27 
28 #include <stdio.h>
29 #include <selforg/abstractcontroller.h>
30 
31 /**
32  * simple braitenberg controler type 2 a and b (Aggressive,Cowardly)
33  *
34  * assumes a linecamera (see LineImgProc), left and right sensor are specified in the constructor
35  */
37 public:
39 
40  /**
41  @param type Braitenberg type
42  @param leftsensor index of left light sensor
43  @param rightsensor index of right light sensor
44  @param leftmotor index of motor of left wheel
45  @param rightmotor index of motor of right wheel
46  */
48  int leftmotor=0, int rightmotor=1)
49  : AbstractController("Braitenberg", "0.1"), type(type),
50  leftsensor(leftsensor), rightsensor(rightsensor),
52 
53  addParameterDef("strength", &strength,0.6);
54  addParameterDef("offset", &offset,0.0);
55  }
56 
57  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0){
58  number_sensors=sensornumber;
59  number_motors=motornumber;
60  assert(sensornumber>=2 && sensornumber>=leftsensor && sensornumber>=rightsensor);
61  assert(motornumber>=2 && motornumber>=leftmotor && motornumber>=rightmotor);
62  }
63 
64  virtual int getSensorNumber() const {return number_sensors;}
65 
66  virtual int getMotorNumber() const {return number_motors;}
67 
68  virtual void step(const sensor* sensors, int sensornumber,
69  motor* motors, int motornumber) {
70  stepNoLearning(sensors, sensornumber, motors , motornumber);
71  }
72 
73  virtual void stepNoLearning(const sensor* sensors, int sensornumber,
74  motor* motors, int motornumber){
75  switch(type){
76  case Aggressive:
77  motors[leftmotor] = sensors[rightsensor] * strength + offset;
78  motors[rightmotor] = sensors[leftsensor] * strength + offset;
79  break;
80  case Cowardly:
81  motors[leftmotor] = sensors[leftsensor] * strength + offset;
82  motors[rightmotor] = sensors[rightsensor] * strength + offset;
83  break;
84  }
85  }
86 
87 
88  /********* STORABLE INTERFACE ******/
89  /// @see Storable
90  virtual bool store(FILE* f) const {
91  Configurable::print(f,"");
92  return true;
93  }
94 
95  /// @see Storable
96  virtual bool restore(FILE* f) {
98  return true;
99  }
100 
101 protected:
102 
112 };
113 
114 #endif
int leftsensor
Definition: braitenberg.h:104
int number_sensors
Definition: braitenberg.h:108
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
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: braitenberg.h:57
Definition: braitenberg.h:38
Braitenberg(Type type, int leftsensor, int rightsensor, int leftmotor=0, int rightmotor=1)
Definition: braitenberg.h:47
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
simple braitenberg controler type 2 a and b (Aggressive,Cowardly)
Definition: braitenberg.h:36
paramval offset
Definition: braitenberg.h:111
virtual bool store(FILE *f) const
Definition: braitenberg.h:90
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
int number_motors
Definition: braitenberg.h:109
paramval strength
Definition: braitenberg.h:110
virtual bool restore(FILE *f)
Definition: braitenberg.h:96
double sensor
Definition: abstractcontroller.h:48
double paramval
Definition: configurable.h:88
Type type
Definition: braitenberg.h:103
int rightsensor
Definition: braitenberg.h:105
virtual void stepNoLearning(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step without learning.
Definition: braitenberg.h:73
Type
Definition: braitenberg.h:38
virtual void addParameterDef(const paramkey &key, paramval *val, paramval def, paramval minBound, paramval maxBound, const paramdescr &descr=paramdescr())
This function is only provided for convenience.
Definition: configurable.h:220
virtual int getMotorNumber() const
Definition: braitenberg.h:66
Definition: braitenberg.h:38
bool parse(FILE *f, const char *prefix=0, bool traverseChildren=true)
parses the configuration from the given file
Definition: configurable.cpp:384
double motor
Definition: abstractcontroller.h:49
int rightmotor
Definition: braitenberg.h:107
int leftmotor
Definition: braitenberg.h:106
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step (includes learning).
Definition: braitenberg.h:68
virtual int getSensorNumber() const
Definition: braitenberg.h:64