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
onecontrollerperchannel.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 __ONECONTROLLERPERCHANNEL_H
25 #define __ONECONTROLLERPERCHANNEL_H
26 
27 #include <selforg/abstractcontroller.h>
28 #include <vector>
29 #include <functional>
30 
31 
32 /** generator for controller
33 
34  derive a struct and overload the operator. For example:
35 
36  struct ControlGen : public ControllerGenerator {
37  virtual ~ControlGen(){}
38  virtual AbstractController* operator()( int index) {
39  AbstractController* c;
40  c= new Sox(0.8);
41  c->setParam("epsC",0.02);
42  c->setParam("epsA",0.01);
43  return c;
44  }
45  };
46 
47  // to see the values in the inspectable do after
48  agent = new OdeAgent(global);
49  // this line
50  agent->addInspectable(((OneControllerPerChannel*)controller)->getControllers()[0]);
51  ....
52  Make sure you initialize the OneControllerPerChannel with sufficiently many initial controller.
53 
54 */
55 struct ControllerGenerator : public std::unary_function< int, AbstractController*> {
57  virtual AbstractController* operator()( int index) = 0;
58 };
59 
60 
61 /**
62  * class for using multiple controller, one for each joint. Each controller
63  * has dimension 1x1. The controller are generated on the fly with a generator object
64  *
65  */
67 public:
68 
69  /** @param controllerGenerator generator object for controller
70  @param controllerName name
71  @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
72  @param numContextSensors number of context sensors (counted from the end)
73  passed to all controllers
74  */
76  std::string controllerName,
78  int numContextSensors = 0
79  );
80 
81  virtual ~OneControllerPerChannel();
82 
83 
84  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
85 
86  virtual void step(const sensor* sensors, int sensornumber,
87  motor* motors, int motornumber);
88 
89  virtual void stepNoLearning(const sensor* sensors , int sensornumber,
90  motor* motors, int motornumber);
91 
92  virtual int getSensorNumber() const {return sensornumber; }
93  virtual int getMotorNumber() const {return motornumber; }
94 
95  /*********** STORABLE **************/
96 
97  virtual bool store(FILE* f) const;
98 
99  virtual bool restore(FILE* f);
100 
101 
102  virtual std::vector<AbstractController*> getControllers() const { return ctrl;}
103 
104 protected:
105  std::vector<AbstractController*> ctrl;
111  double* sensorbuffer;
112 };
113 
114 #endif
int numContextSensors
Definition: onecontrollerperchannel.h:108
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
virtual bool store(FILE *f) const
stores the object to the given file stream (ASCII preferred).
Definition: onecontrollerperchannel.cpp:110
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: onecontrollerperchannel.cpp:52
class for using multiple controller, one for each joint.
Definition: onecontrollerperchannel.h:66
virtual ~OneControllerPerChannel()
Definition: onecontrollerperchannel.cpp:45
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step (includes learning).
Definition: onecontrollerperchannel.cpp:75
std::vector< AbstractController * > ctrl
Definition: onecontrollerperchannel.h:105
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
double * sensorbuffer
Definition: onecontrollerperchannel.h:111
virtual ~ControllerGenerator()
Definition: onecontrollerperchannel.h:56
double sensor
Definition: abstractcontroller.h:48
virtual bool restore(FILE *f)
loads the object from the given file stream (ASCII preferred).
Definition: onecontrollerperchannel.cpp:118
virtual int getSensorNumber() const
Definition: onecontrollerperchannel.h:92
virtual std::vector< AbstractController * > getControllers() const
Definition: onecontrollerperchannel.h:102
virtual AbstractController * operator()(int index)=0
ControllerGenerator * controllerGenerator
Definition: onecontrollerperchannel.h:106
int motornumber
Definition: onecontrollerperchannel.h:109
int sensornumber
Definition: onecontrollerperchannel.h:110
OneControllerPerChannel(ControllerGenerator *controllerGenerator, std::string controllerName, int numCtrlCreateBeforeInit=1, int numContextSensors=0)
Definition: onecontrollerperchannel.cpp:30
int numCtrlCreateBeforeInit
Definition: onecontrollerperchannel.h:107
virtual int getMotorNumber() const
Definition: onecontrollerperchannel.h:93
double motor
Definition: abstractcontroller.h:49
virtual void stepNoLearning(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step without learning.
Definition: onecontrollerperchannel.cpp:92
generator for controller
Definition: onecontrollerperchannel.h:55