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
abstractcontroller.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 __ABSTRACTCONTROLLER_H
25 #define __ABSTRACTCONTROLLER_H
26 
27 #include <stdio.h>
28 #include <list>
29 #include <map>
30 #include "configurable.h"
31 #include "inspectable.h"
32 #include "storeable.h"
33 #include "randomgenerator.h"
34 #include "sensormotorinfo.h"
35 
36 /**
37  * Abstract class for robot controller (with some basic functionality).
38  * The controller gets a number of input sensor values each timestep
39  * and has to generate a number of output motor values.
40  *
41  * Interface assumes the following usage:
42  * - init() is called first to initialise the dimension of sensor- and motor space
43  * - each time step
44  * either step() or stepNoLearning() is called to ask the controller for motor values.
45  */
46 class AbstractController : public Configurable, public Inspectable, public Storeable {
47 public:
48  typedef double sensor;
49  typedef double motor;
50 
51  /// contructor (hint: use $ID$ for revision)
52  AbstractController(const std::string& name, const std::string& revision)
53  : Configurable(name, revision), Inspectable(name) {}
54 
55  /** initialisation of the controller with the given sensor/ motornumber
56  Must be called before use. The random generator is optional.
57  */
58  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0)= 0;
59 
60  /** @return Number of sensors the controller
61  was initialised with or 0 if not initialised */
62  virtual int getSensorNumber() const= 0;
63 
64  /** @return Number of motors the controller
65  was initialised with or 0 if not initialised */
66  virtual int getMotorNumber() const= 0;
67 
68  /** performs one step (includes learning).
69  Calculates motor commands from sensor inputs.
70  @param sensors sensors inputs scaled to [-1,1]
71  @param sensornumber length of the sensor array
72  @param motors motors outputs. MUST have enough space for motor values!
73  @param motornumber length of the provided motor array
74  */
75  virtual void step(const sensor* sensors, int sensornumber,
76  motor* motors, int motornumber)= 0;
77  /** performs one step without learning.
78  @see step
79  */
80  virtual void stepNoLearning(const sensor* , int number_sensors,
81  motor* , int number_motors)= 0;
82 
83  /** called in motor babbling phase.
84  the motor values are given (by babbling controller) and
85  this controller can learn the basic relations from observed sensors/motors
86  */
87  virtual void motorBabblingStep(const sensor* , int number_sensors,
88  const motor* , int number_motors) {};
89 
90  /** the controller is notified about the information on sensor.
91  This is called after init and before step
92  By default the sensorIndexMap and sensorInfoMap is updated and
93  can be accessed by SIdx() and SInfo()
94  */
95  virtual void sensorInfos(std::list<SensorMotorInfo> sensorInfos);
96 
97  /** the controller is notified about the information on motors.
98  This is called after init and before step
99  By default the motorIndexMap and motorInfoMap is updated and
100  can be accessed by MIdx() and MInfo()
101 
102  */
103  virtual void motorInfos(std::list<SensorMotorInfo> motorInfos);
104 
105  /** returns the index of the sensor with the given name
106  (if not found then 0 and all sensor names are printed) */
107  virtual int SIdx(const std::string& name);
108  /** returns the index of the motor with the given name
109  (if not found then 0 and all motor names are printed) */
110  virtual int MIdx(const std::string& name);
111  /** returns the Information for the sensor with given index */
112  virtual SensorMotorInfo SInfo(int index);
113  /** returns the Information for the motor with given index */
114  virtual SensorMotorInfo MInfo(int index);
115 
116 protected:
117  std::map<std::string, int> sensorIndexMap;
118  std::map<std::string, int> motorIndexMap;
119  std::map<int, SensorMotorInfo> sensorInfoMap;
120  std::map<int, SensorMotorInfo> motorInfoMap;
121 };
122 
123 #endif
virtual void sensorInfos(std::list< SensorMotorInfo > sensorInfos)
the controller is notified about the information on sensor.
Definition: abstractcontroller.cpp:29
Interface for objects, that can be stored and restored to/from a file stream (binary).
Definition: storeable.h:33
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
double sensor
Definition: types.h:29
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
std::map< std::string, int > sensorIndexMap
Definition: abstractcontroller.h:117
AbstractController(const std::string &name, const std::string &revision)
contructor (hint: use $ID$ for revision)
Definition: abstractcontroller.h:52
double sensor
Definition: abstractcontroller.h:48
virtual int MIdx(const std::string &name)
returns the index of the motor with the given name (if not found then 0 and all motor names are print...
Definition: abstractcontroller.cpp:58
virtual void motorInfos(std::list< SensorMotorInfo > motorInfos)
the controller is notified about the information on motors.
Definition: abstractcontroller.cpp:36
virtual int SIdx(const std::string &name)
returns the index of the sensor with the given name (if not found then 0 and all sensor names are pri...
Definition: abstractcontroller.cpp:43
Interface for objects, that can be stored and restored to/from a file stream (binary).
Definition: sensormotorinfo.h:33
virtual SensorMotorInfo SInfo(int index)
returns the Information for the sensor with given index
Definition: abstractcontroller.cpp:73
virtual void init(int sensornumber, int motornumber, RandGen *randGen=0)=0
initialisation of the controller with the given sensor/ motornumber Must be called before use...
Interface for inspectable objects.
Definition: inspectable.h:48
Abstact class for configurable objects.
Definition: configurable.h:81
double motor
Definition: types.h:30
std::map< int, SensorMotorInfo > motorInfoMap
Definition: abstractcontroller.h:120
virtual void stepNoLearning(const sensor *, int number_sensors, motor *, int number_motors)=0
performs one step without learning.
std::map< std::string, int > motorIndexMap
Definition: abstractcontroller.h:118
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber)=0
performs one step (includes learning).
virtual void motorBabblingStep(const sensor *, int number_sensors, const motor *, int number_motors)
called in motor babbling phase.
Definition: abstractcontroller.h:87
double motor
Definition: abstractcontroller.h:49
virtual SensorMotorInfo MInfo(int index)
returns the Information for the motor with given index
Definition: abstractcontroller.cpp:82
std::map< int, SensorMotorInfo > sensorInfoMap
Definition: abstractcontroller.h:119
virtual int getMotorNumber() const =0
virtual int getSensorNumber() const =0