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
wiredcontroller.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 /*
25 ** Started on Mon Oct 22 10:50:47 2007 Georg Martius
26 ** Last update Mon Oct 22 10:50:47 2007 Georg Martius
27 */
28 #ifndef WIREDCONTROLLER_H_
29 #define WIREDCONTROLLER_H_
30 
31 #include "plotoptionengine.h"
32 #include "backcaller.h"
33 #include "types.h"
34 #include "inspectable.h"
35 #include "configurable.h"
36 #include "randomgenerator.h"
37 
38 #include <stdio.h>
39 #include <list>
40 #include <utility>
41 #include <string>
42 
43 
44 class AbstractController;
45 class AbstractWiring;
46 class Callbackable;
47 class WiredController;
48 
49 /** The WiredController contains a controller and a wiring, which
50  connects the controller with the robot.
51  Additionally there are some ways to keep track of internal information.
52  You have the possibility to keep track of sensor values,
53  motor values and internal parameters of the controller with PlotOptions.
54  The name PlotOptions is a bit missleaded, it should be "OutputOptions",
55  however you can write the data into a file or send it to
56  visualisation tools like guilogger or neuronviz.
57  */
58 class WiredController : public Inspectable, public Configurable {
59 public:
60  /** constructor. PlotOption as output setting.
61  noisefactor is used to set the relative noise strength of this agent
62  */
63  WiredController(const PlotOption& plotOption = PlotOption(NoPlot), double noisefactor = 1, const iparamkey& name = "WiredController", const paramkey& revision = "$ID");
64  /** constructor. A list of PlotOption can given.
65  noisefactor is used to set the relative noise strength of this agent
66  */
67  WiredController(const std::list<PlotOption>& plotOptions, double noisefactor = 1, const iparamkey& name = "WiredController", const paramkey& revision = "$ID");
68 
69  /** destructor
70  */
71  virtual ~WiredController();
72 
73  /** initializes the object with the given controller and wiring
74  and initializes the output options
75  It is also possible to provide a random seed,
76  if not given (0) rand() is used to create one
77  */
79  int robotsensornumber, int robotmotornumber,
80  const std::list<SensorMotorInfo>& robotSensorInfos,
81  const std::list<SensorMotorInfo>& robotMotorInfos,
82  RandGen* randGen=0);
83 
84  /** Performs an step of the controller, which includes
85  pushing sensor values through the wiring,
86  controller step,
87  pushing controller outputs (= motorcommands) back through the wiring
88  @param sensors sensors inputs scaled to [-1,1]
89  @param sensornumber length of the sensor array
90  @param motors motors outputs. MUST have enough space for motor values!
91  @param motornumber length of the provided motor array
92 
93  @param noise Noise strength.
94  @param time (optional) current simulation time (used for logging)
95  */
96  virtual void step(const sensor* sensors, int sensornumber,
97  motor* motors, int motornumber,
98  double noise, double time=-1);
99 
100  /** Enables the motor babbling mode for given number of steps (typically 1000).
101  Optionally a controller can be
102  given that is used for the babbling (default is MotorBabbler) (deleted automatically).
103  During motor babbling the function motorbabbling of the normal controller is called instead of step.
104  */
105  virtual void startMotorBabblingMode (int steps, AbstractController* babblecontroller = 0);
106 
108 
109  /** stops the motor babbling mode. */
110  virtual void stopMotorBabblingMode () { motorBabblingSteps = 0; }
111  /// returns true if in motorbabbling mode
112  virtual bool getMotorBabblingMode() { return motorBabblingSteps > 0; }
113 
114 
115  /** adds the PlotOptions to the list of plotoptions
116  If a plotoption with the same Mode exists, then the old one is deleted first
117  */
118  virtual PlotOption addPlotOption(PlotOption& plotoption);
119 
120  /** adds a new PlotOption and initializes it
121  @see addPlotOption
122  */
123  virtual bool addAndInitPlotOption(PlotOption& plotOption);
124 
125  /** removes the PlotOptions with the given type
126  @return true if sucessful, false otherwise
127  */
128  virtual bool removePlotOption(PlotMode mode);
129 
130  /**
131  write comment to output streams (PlotOptions). For instance changes in parameters.
132  see PlotOptionEngine
133  */
134  virtual void writePlotComment(const char* cmt, bool addSpace=true);
135 
136  /** Returns a pointer to the controller.
137  */
139  virtual const AbstractController* getController() const { return controller;}
140 
141  /** Returns a pointer to the wiring.
142  */
143  virtual AbstractWiring* getWiring() { return wiring;}
144 
145 protected:
146  /**
147  * Plots controller sensor- and motorvalues and internal controller parameters.
148  * @param time simulation time
149  */
150  virtual void plot(double time);
151 
152 
155 
156  /// number of sensors of robot
158  /// number of motors of robot
160  /// number of sensors of comntroller
162  /// number of motors of comntroller
164 
165  /// factor that is muliplied with noise stength
166  double noisefactor;
167 
170 
171  void internInit();
172 
173  protected:
176 
178 
180 
181  std::list<Callbackable* > callbackables;
182 
183  long int t;
184 };
185 
186 #endif /* !WIREDCONTROLLER_H_ */
int cmotornumber
number of motors of comntroller
Definition: wiredcontroller.h:163
virtual bool init(AbstractController *controller, AbstractWiring *wiring, int robotsensornumber, int robotmotornumber, const std::list< SensorMotorInfo > &robotSensorInfos, const std::list< SensorMotorInfo > &robotMotorInfos, RandGen *randGen=0)
initializes the object with the given controller and wiring and initializes the output options It is ...
Definition: wiredcontroller.cpp:80
PlotMode
Output mode for agent.
Definition: plotoption.h:40
virtual AbstractWiring * getWiring()
Returns a pointer to the wiring.
Definition: wiredcontroller.h:143
int motorBabblingSteps
Definition: wiredcontroller.h:175
Interface class for a class which wants to be callback on a certain action.
Definition: callbackable.h:39
bool initialised
Definition: wiredcontroller.h:179
std::string paramkey
Definition: configurable.h:85
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
int csensornumber
number of sensors of comntroller
Definition: wiredcontroller.h:161
motor * cmotors
Definition: wiredcontroller.h:168
virtual ~WiredController()
destructor
Definition: wiredcontroller.cpp:68
AbstractWiring * wiring
Definition: wiredcontroller.h:154
void internInit()
Definition: wiredcontroller.cpp:54
WiredController(const PlotOption &plotOption=PlotOption(NoPlot), double noisefactor=1, const iparamkey &name="WiredController", const paramkey &revision="$ID")
constructor.
Definition: wiredcontroller.cpp:43
double sensor
Definition: types.h:29
virtual void stopMotorBabblingMode()
stops the motor babbling mode.
Definition: wiredcontroller.h:110
iparamkey name
Definition: inspectable.h:251
Definition: plotoptionengine.h:38
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
dummy (does nothing) is there for compatibility, might be removed later
Definition: plotoption.h:42
The WiredController contains a controller and a wiring, which connects the controller with the robot...
Definition: wiredcontroller.h:58
virtual bool getMotorBabblingMode()
returns true if in motorbabbling mode
Definition: wiredcontroller.h:112
Abstract wiring-object between controller and robot.
Definition: abstractwiring.h:39
std::string iparamkey
Definition: inspectable.h:53
virtual const AbstractController * getController() const
Definition: wiredcontroller.h:139
PlotOptionEngine plotEngine
Definition: wiredcontroller.h:177
virtual void plot(double time)
Plots controller sensor- and motorvalues and internal controller parameters.
Definition: wiredcontroller.cpp:155
virtual PlotOption addPlotOption(PlotOption &plotoption)
adds the PlotOptions to the list of plotoptions If a plotoption with the same Mode exists...
Definition: wiredcontroller.cpp:137
virtual void startMotorBabblingMode(int steps, AbstractController *babblecontroller=0)
Enables the motor babbling mode for given number of steps (typically 1000).
Definition: wiredcontroller.cpp:123
This class contains options for the use of an external plot utility like guilogger or neuronviz or ju...
Definition: plotoption.h:66
virtual bool addAndInitPlotOption(PlotOption &plotOption)
adds a new PlotOption and initializes it
Definition: wiredcontroller.cpp:141
Interface for inspectable objects.
Definition: inspectable.h:48
Abstact class for configurable objects.
Definition: configurable.h:81
int rsensornumber
number of sensors of robot
Definition: wiredcontroller.h:157
virtual void writePlotComment(const char *cmt, bool addSpace=true)
write comment to output streams (PlotOptions).
Definition: wiredcontroller.cpp:149
double motor
Definition: types.h:30
virtual AbstractController * getMotorBabbler()
Definition: wiredcontroller.h:107
AbstractController * controller
Definition: wiredcontroller.h:153
int rmotornumber
number of motors of robot
Definition: wiredcontroller.h:159
virtual bool removePlotOption(PlotMode mode)
removes the PlotOptions with the given type
Definition: wiredcontroller.cpp:145
double noisefactor
factor that is muliplied with noise stength
Definition: wiredcontroller.h:166
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber, double noise, double time=-1)
Performs an step of the controller, which includes pushing sensor values through the wiring...
Definition: wiredcontroller.cpp:165
sensor * csensors
Definition: wiredcontroller.h:169
virtual AbstractController * getController()
Returns a pointer to the controller.
Definition: wiredcontroller.h:138
AbstractController * motorBabbler
Definition: wiredcontroller.h:174
std::list< Callbackable * > callbackables
Definition: wiredcontroller.h:181
long int t
Definition: wiredcontroller.h:183