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
splitcontrol.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 __SPLITCONTROL_H
25 #define __SPLITCONTROL_H
26 
27 #include <selforg/abstractcontroller.h>
28 #include <selforg/onecontrollerperchannel.h>
29 
30 #include <vector>
31 #include <functional>
32 
33 
34 /**
35  * class for using multiple controller with one robot. The connection is flexible.
36  * The controller are generated on the fly with a generator object.
37  *
38  */
40 public:
41 
42  struct Assoziation {
43  Assoziation();
44  void addSensorIdx(int s) { sensors.push_back(s);}
45  void addMotorIdx(int m) { motors.push_back(m);}
46 
47  std::list<int> sensors;
48  std::list<int> motors;
49  };
50  typedef std::vector<Assoziation> Assoziations;
51 
52  /** @param controllerGenerator generator object for controller
53  @param assoziations list decribing which sensors and motors are connected to each controller
54  @param controllerName name
55  @param numCtrlCreateBeforeInit number of controller that are generated before the init function is called. Useful if they should be put into the inspectable list of the agent
56  @param numContextSensors number of context sensors (counted from the end)
57  passed to all controllers
58  */
60  const Assoziations& assoziations,
61  std::string controllerName,
63  int numContextSensors = 0
64  );
65 
66  virtual ~SplitControl();
67 
68 
69  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
70 
71  virtual void step(const sensor* sensors, int sensornumber,
72  motor* motors, int motornumber);
73 
74  virtual void stepNoLearning(const sensor* sensors , int sensornumber,
75  motor* motors, int motornumber);
76 
77  virtual int getSensorNumber() const {return sensornumber; }
78  virtual int getMotorNumber() const {return motornumber; }
79 
80  /*********** STORABLE **************/
81 
82  virtual bool store(FILE* f) const {return false;}
83 
84  virtual bool restore(FILE* f) {return false;}
85 
86 
87  virtual std::vector<AbstractController*> getControllers() const { return ctrl;}
88 
89 protected:
90  std::vector<AbstractController*> ctrl;
91 
92 
99  double* sensorbuffer;
100  double* motorbuffer;
101 };
102 
103 #endif
ControllerGenerator * controllerGenerator
Definition: splitcontrol.h:93
void addMotorIdx(int m)
Definition: splitcontrol.h:45
virtual std::vector< AbstractController * > getControllers() const
Definition: splitcontrol.h:87
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
std::vector< Assoziation > Assoziations
Definition: splitcontrol.h:50
int motornumber
Definition: splitcontrol.h:97
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: splitcontrol.cpp:55
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
std::vector< AbstractController * > ctrl
Definition: splitcontrol.h:90
virtual int getSensorNumber() const
Definition: splitcontrol.h:77
double * sensorbuffer
Definition: splitcontrol.h:99
virtual bool store(FILE *f) const
stores the object to the given file stream (ASCII preferred).
Definition: splitcontrol.h:82
std::list< int > motors
Definition: splitcontrol.h:48
double sensor
Definition: abstractcontroller.h:48
int numCtrlCreateBeforeInit
Definition: splitcontrol.h:95
void addSensorIdx(int s)
Definition: splitcontrol.h:44
std::list< int > sensors
Definition: splitcontrol.h:47
Definition: splitcontrol.h:42
int numContextSensors
Definition: splitcontrol.h:96
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step (includes learning).
Definition: splitcontrol.cpp:92
class for using multiple controller with one robot.
Definition: splitcontrol.h:39
virtual bool restore(FILE *f)
loads the object from the given file stream (ASCII preferred).
Definition: splitcontrol.h:84
SplitControl(ControllerGenerator *controllerGenerator, const Assoziations &assoziations, std::string controllerName, int numCtrlCreateBeforeInit=1, int numContextSensors=0)
Definition: splitcontrol.cpp:30
Assoziations assoz
Definition: splitcontrol.h:94
double * motorbuffer
Definition: splitcontrol.h:100
double motor
Definition: abstractcontroller.h:49
virtual void stepNoLearning(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step without learning.
Definition: splitcontrol.cpp:116
virtual ~SplitControl()
Definition: splitcontrol.cpp:47
int sensornumber
Definition: splitcontrol.h:98
virtual int getMotorNumber() const
Definition: splitcontrol.h:78
generator for controller
Definition: onecontrollerperchannel.h:55